Nightwatch & PhantomJS

2,897 views
Skip to first unread message

Rob Wilkerson

unread,
Oct 15, 2014, 6:47:50 PM10/15/14
to nightw...@googlegroups.com
Hey, guys -

To satisfy my curiosity, I started looking into running my Nightwatch tests with PhantomJS. I've now spent a little bit of time and don't have it working yet, but it got me wondering about the net gain of actually getting it working. What's the benefit here?

One upside for me would be if I could run my tests in a completely headless manner that would be significantly faster, but I don't have a clear sense that this is the case.

Another would be the ability to run my tests, sans BrowserStack, on a headless Linux box. My reading indicates that this might be the point, but I'm not having much luck.

My existing tests run great w/ Selenium alone and against BrowserStack, but using the following PhantomJS config I get a failure in every case:

    "phantomjs" : {
      "launch_url" : "http://mysite.mydomain.net",
      "selenium_host"  : "127.0.0.1",
      "selenium_port"  : 4444,
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "selenium" : {
        "start_process" : true,
        "server_path" : "lib/selenium/selenium-server-standalone-2.41.0.jar",
        "log_path" : "",
        "host" : "127.0.0.1",
        "port" : 4444,
        "cli_args" : {
          "webdriver.firefox.profile" : "",
          "webdriver.chrome.driver" : "",
          "webdriver.ie.driver" : ""
        }
      },
      "desiredCapabilities": {
        "browserName" : "phantomjs",
        "javascriptEnabled" : true,
        "acceptSslCerts" : true,
        "phantomjs.binary.path" : "/usr/local/bin/phantomjs"
      }
    },

I've installed phantomjs 1.9.7 via Homebrew and have nightwatch 0.5.28 installed.

Would love a little enlightenment before I burn too many cycles down this rabbit hole.

Thanks.

Lacy Morrow

unread,
Oct 15, 2014, 7:02:56 PM10/15/14
to nightw...@googlegroups.com
Someone who has used it could elaborate on this.

PhantomJS testing is faster (because no real browser) and has less inconsistencies (contains it's own JS/DOM rendering engine) than testing between other browsers. These reasons are why people use it, or not.

I don't use phantom because it isn't a browser that users use. It is not Chrome/Firefox/Opera/Safari/IE and therefore will not give me information about the way my site is running in those browsers.

People use it to (I imagine) to quickly test to make sure their site works in MOST recent versions of all browsers.

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/61c6e2bd-e7f9-4aa5-8379-75060de1e8be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Wilkerson

unread,
Oct 15, 2014, 7:12:16 PM10/15/14
to nightw...@googlegroups.com
Good info, thanks.

I'd be willing to settle for pure functional testing, i.e. "works in MOST recent versions of all browsers", to use your words, as long as it's a lot faster. As the suite gets larger, speed will only matter more and the balance will tip.

The other issue I've seen so far is that CSS may impact test results. For example, one test looks for the text "FOO" because that's how it renders in a browser. This test works w/ Selenium and Browserstack, but not w/ Phantom--presumably because the DOM content is "Foo" modified by CSS to "FOO".

Anyway, thanks again. Nice to have a sense of what Phantom brings to the table in this context.

Lacy Morrow

unread,
Oct 16, 2014, 3:41:44 AM10/16/14
to nightw...@googlegroups.com
That's an interesting drawback of phantom I haven't heard about, I would have imagined that the CSS rendering engine is as up to par as the JS (I assume you mean a CSS text-transform). Either way, it sounds like PhantomJS will suit your needs. I'm having to test as far back as IE8, so it's worth it for me to see the real browser in action.

Chris Neale

unread,
Oct 16, 2014, 3:45:06 AM10/16/14
to nightw...@googlegroups.com
The advantage of PhantomJS is that it's designed to be used in an automated environment. It integrates with various tools without the need for Selenium to drive it and the API is more stable than a 'real' browser. There aren't many reasons to use it with nightwatch though - it isn't faster, it can't do as much (for example, there isn't an implementation of the performance timing API), and, as Lacy said, users don't use it. One small advantage is that there's less memory overhead, but that's a pretty trivial thing unless you're planning to run hundreds of tests in parallel.

Ultimately, it's fun to play with, but I wouldn't spend huge amounts of time on it.

Andrei Rusu

unread,
Oct 16, 2014, 6:38:41 AM10/16/14
to nightw...@googlegroups.com
In Nightwatch it's actually still driven by Selenium via the
GhostDriver so it's not as fast as it can be, only a little faster
than a regular browser. The only real advantage I guess it would be
the ability to use run the tests in a headless environment on a Linux
box but you can get that working with Xvfb with a reasonable amount of
effort.
> --
> You received this message because you are subscribed to the Google Groups
> "NightwatchJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nightwatchjs...@googlegroups.com.
> To post to this group, send email to nightw...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nightwatchjs/83206ed3-b893-481d-9b81-ee40db598bf6%40googlegroups.com.

Eric Frazier

unread,
Nov 3, 2015, 11:19:30 PM11/3/15
to NightwatchJs
Just following a similair path. I am having problems with PhantomJS(injecting scripts and waiting well past page load) and want to try the same thing I am doing with Nightwatch, but it has to be headless to work for me.

Did you ever get an a real answer? I don't see one in this thread..

Thanks,

Eric

Daniel Rinehart

unread,
Nov 4, 2015, 10:42:43 AM11/4/15
to NightwatchJs
Could you describe more what isn't working since this seems to be an old thread. We use Nightwatch with PhantomJS to run a headless test suite as part of our Jenkins setup without problem.

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.

GrayedFox

unread,
Dec 11, 2015, 5:39:37 AM12/11/15
to NightwatchJs
Hey Daniel,

Out of interest (and desperate need!): were you able to set the viewport and window size of PhantomJS using Nightwatch? I desperately need to figure this out. All my tests run fine on Safari, FF and Chrome but they all fail on Phantom due to the website being reactive - so a smaller window size means elements have their name and CSS change (it's a one page app).

I would have to write Phantom specific tests (which defeats the purpose of Nightwatch, really) or figure out a way to resize the Nightwatch window / viewport size. I need to access this PhantomJS property somehow from my tests.

No idea how to talk to the Phantom GhostDriver directly, the Nightwatch methods (i.e. browser.maximizeWindow) don't seem to work either.

Stephanie Madison

unread,
Dec 11, 2015, 5:58:48 PM12/11/15
to nightw...@googlegroups.com
Not sure why the Nightwatch methods wouldn't work in this case. Have you tried `window.resizeTo`?

Colin Roy-Ehri

unread,
Jun 1, 2017, 1:33:27 PM6/1/17
to NightwatchJs, andre...@beatfactor.net
Hi Andrei,
 Could you share what you did in nightwatch.conf.js or your pom to get Xvfb working with Nightwatch? 
Thanks,
Colin
Reply all
Reply to author
Forward
0 new messages