nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

[discuss] support for Electron? #856

Closed kevzettler closed 8 years ago

kevzettler commented 8 years ago

purposing Electron support as a faster, more modern headless option over phantomJs

beatfactor commented 8 years ago

what does it require from nightwatch?

On Fri, Feb 12, 2016 at 12:14 AM, Kev Zettler notifications@github.com wrote:

purposing Electron support as a faster, more modern headless option over phantomJs

— Reply to this email directly or view it on GitHub https://github.com/nightwatchjs/nightwatch/issues/856.

vladnicula commented 8 years ago

Was wondering about this right now while integrating nightwatch into my current project. There's a test runner - nightmarejs - that already uses electron for e2e tests, but it's not selenium based. They seem to spawn a child process in node and listen to signals from it.

A few google searches pointed me to electron-prebuilt which happens to be one of the dependencies of the nightmare testrunner. So electron-prebuilt is the npm package that could be used to run electron.

Looking at this page on the electron github repo it seems that running an electron app could be just an extra argument to the nightwatch.json. Setting the chromeOptions .binary argument of the browser to the path returned by electron-prebuilt will start the tests in electron instead of normal chrome.. This is still a normal browser window though.

In order to start the tests in a headless browser, we need to do some extra work, as explained in the ci integration tutorial on the electron docs. I haven't figured out how nightmarejs runs electron in a headless window, and it seems that the recommended way of using the headless version is via xvfb-maybe which is a command line to start electron.

I opened a issue on the electron github page here: https://github.com/atom/electron/issues/4834.

Would really like to have this sorted out.

kevzettler commented 8 years ago

@vladnicula you can run headless electron with https://github.com/maxogden/electron-spawn and xvfb-run llike:

xvfb-run electron-spawn ./yourscript.js

taoeffect commented 8 years ago

:+1: this would be really great.

drptbl commented 8 years ago

Indeed.

drptbl commented 8 years ago

You're able to test with Electron (not headless) using this:

    "electron": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions": {
          "binary": "/Applications/Electron.app/Contents/MacOS/Electron"
        },
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }

Still, after first run I've noticed a lot of "bugs" like resizeWindow is not working (Electron hangs for 10 secs), my custom command waiting for testability in Angular throws an error while it works properly everywhere (together with IE and Safari) and more stuff going on.

beatfactor commented 8 years ago

Seems like there is nothing special required from Nightwatch with the configuration bit explained this is already possible, so I'm closing this. There's also a tutorial available here: https://github.com/electron/electron/blob/master/docs/tutorial/using-selenium-and-webdriver.md.

StephenDavidson commented 8 years ago

Currently testing a prod electron app using nightwatch. Just wanted to add my nightwatch conf incase anyone is interested. Just keep in mind that all your paths always need to be platform independent, so you can test cross platform. My e2e tests are in the dev repo, which is why the app is pointing to two directories up.

var chromedriver = require('chromedriver');
var electron = require('electron-prebuilt');
var path = require('path');
var seleniumServer = require('selenium-server');

module.exports = {
  src_folders: ['tests'],
  output_folder: 'reports',
  page_objects_path: 'page-objects',
  globals_path: 'globals.js',
  test_runner: 'mocha',
  test_workers: false,

  selenium : {
    start_process : true,
    server_path: seleniumServer.path,
    log_path : '',
    host : '127.0.0.1',
    port : 4444
  },

  test_settings: {
    default: {
      launch_url: 'http://localhost',
      selenium_port: 4444,
      selenium_host: 'localhost',
      silent: true,
      screenshots: {
        enabled: false,
        on_failure: true,
        on_error: false,
        path: 'screenshots'
      },
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions:{
          binary: electron,
          args: ['app=' + path.join('..', '..')]
        }
      },
      selenium : {
        cli_args : {
          'webdriver.chrome.driver': chromedriver.path
        }
      }
    }
  }
};
glennr commented 8 years ago

Thanks @StephenDavidson ! I got NW+Electron working with your help. With a bit of trial and error I figured that for a non-electron app (i.e. 'normal' web app), you should omit this line;

args: ['app=' + path.join('..', '..')]

i.e.

      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          binary: electron,
        }
      },

PhantomJS is dead. Long live PhantomJS!

maitriyogin commented 7 years ago

Hi, just been following this thread. So I'v got electron up and running but am missing the "how to run in headless mode" ? Do I need to have xvfb running? /Stephen.

StephenDavidson commented 7 years ago

I would try xvfb. Should work the same as chrome on headless machines.

aamorozov commented 7 years ago

Can someone on this tread clarify please what is the advantage of using electron over selenium? I've been using the latest for a few years and have never heard of testing with electron. Is it applicable to electron apps only? Or is it just an alternative to phantomjs/headless chrome which is about to roll out on unix?

kevzettler commented 7 years ago

@aamorozov with the upcoming release of headless chrome this discussion is obsolete