nightwatch: PhantomJS fails on demo test example
When running the demo test example on the nightwatchjs.org homepage using PhantomJS as the browser, I get the following output:
[Google Test] Test Suite
========================
Running: Demo test Google
✔ Element <body> was visible after 53 milliseconds.
✔ Testing if the page title equals "Google".
✖ Testing if element <input[type=text]> is visible. Element could not be located. - expected "true" but got: null
ERROR: Unable to locate element: "input[type=text]" using: css selector
TEST FAILURE: 1 error during execution, 1 assertions failed, 2 passed and 6 skipped.. (6489 ms)
Strangely, if I change .assert.visible("input[type=text]") to .assert.visible("input[name=q]") then that step passes but the test later fails on another step: waitForElementVisible("button[name=btnG]", 1000).
My environment:
Mac OSX 10.9.4 Nightwatch 0.5.18 PhantomJS 1.9.2 selenium-server-standalone-2.42.0.jar
Note: the test runs fine against Firefox.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20 (5 by maintainers)
As @decates indicated above, if you want to use phantomjs, but are okay with it spoofing as a different browser via the user agent, you can configure phantomjs’ user-agent capabilities like this (spoofing as Mac Chrome here):
Then your tests should act the same as your other browser. Using any browser you like, you can check the user-agent string that it sends here: http://www.httpuseragent.org/. Here are some other examples:
Just to note, that the demo test on the http://nightwatchjs.org/ website still fails in PhantomJS
It might be better to use the nightwatchjs.org website as the target for the demo test - so that it wont break if/when google decides to change the way their search page works?
Just to clarify the original issue, this is caused by Google serving up different content depending on the user-agent, and (validly) omitting
type="text"on the input element, as it’s the default value.For Chrome 41 the page is XHTML, and the text box looks like this:
For PhantomJS 2.0.0 it looks like this.
Perhaps the sample test could be changed to use
input[name="q"], or just test nightwatchjs.org instead, as you have control over what is served up?