maxgalbu / nightwatch-custom-commands-assertions

Nightwatch.js custom commands and assertions
MIT License
136 stars 32 forks source link

Problems with jQueryElement #15

Closed TK95 closed 8 years ago

TK95 commented 8 years ago

Here is my code:

 .jqueryElement("body", function(element) {
                console.log("EL", element)
            })

After launch It breaks my test, and giving an error :

{ additionalInformation: '\nDriver info: driver.version: unknown',
  localizedMessage: '$ is not defined\nBuild info: version: \'2.47.1\', revision: \'411b314\', time: \'2015-07-30 03:03:16\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'\nDriver info: driver.version: unknown',
  supportUrl: null,
  systemInformation: 'System info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'',
  cause: null,
  suppressed: [],
  message: '$ is not defined\nBuild info: version: \'2.47.1\', revision: \'411b314\', time: \'2015-07-30 03:03:16\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'\nDriver info: driver.version: unknown',
  hCode: 86066378,
  class: 'org.openqa.selenium.WebDriverException',
  buildInformation: 
   { buildRevision: '411b314',
     buildTime: '2015-07-30 03:03:16',
     releaseLabel: '2.47.1',
     hCode: 368747769,
     class: 'org.openqa.selenium.internal.BuildInfo' } }

Obviously, jQuery wasn't found. How can I require jQuery? Or maybe I something missing?

maxgalbu commented 8 years ago

jQuery must be included in the page you are testing, see e.g. this file: https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/tests/html/jqueryElement.html

TK95 commented 8 years ago

Thank you, it solved my error. But I still don't have jQuery element. Here is output from console.log :

{ ELEMENT: '2' }

Sometimes I get { ELEMENT: '0' }. Are any ideas?

maxgalbu commented 8 years ago

I guess selenium can't return a reference to the element, because you are outside the DOM where it lives. The nightwatch .element function does the same:

.element("css selector", "#div", function(el) {
    console.log(el);
})

..returns:

{ state: 'success',
  sessionId: '4704636e-6737-4945-9885-9cb0619ff054',
  hCode: 1370763489,
  value: { ELEMENT: '0' },
  class: 'org.openqa.selenium.remote.Response',
  status: 0 }
TK95 commented 8 years ago

Okay. Maybe you know how to fix it? I would be very grateful to you.

maxgalbu commented 8 years ago

What would you like to obtain from the element? There are a lot of selenium functions to get whatever you want, without actually having the element.

TK95 commented 8 years ago

I would like to obtain element attributes, innerHTML and array of child nodes. Is it possible?

maxgalbu commented 8 years ago

These are the functions you are looking for:

http://nightwatchjs.org/api#getText http://nightwatchjs.org/api#getAttribute

If you need to assert a value:

http://nightwatchjs.org/api#assert-containsText http://nightwatchjs.org/api#assert-attributeEquals

Obtaining the child nodes won't be useful, same as obtaining the element itself

TK95 commented 8 years ago

Okay. Issue can be closed