Search code examples
microsoft-edgenightwatch.jscucumberjs

Nightwatchjs claims support for Edge browser, but does not actually seem to support it, at least when implemented based on documentation


I've tried to get Nightwatchjs to recognize the Edge browser and run tests on it. It errrs:

Unsupported browser: microsoftedge. There is no available driver.

I've searched for hours about this, and there seems to be a few mentions of the Edge browser before it ditched EdgeHtml and became Chromium based. I tried all of the suggestions from these places. I also used example projects on Github, such as those seen in mucsi96/nightwatch-api.

Every attempt at this results in the above error. I've tried naming it edge, microsoftedge, and even tried a suggestion that involved pretending it was actually IE. Nightwatch even mentions support for the edge browser here. But the documentation is extremely limited, and all suggested approaches do not work.

I've tried several different approaches to the config, like these:

edge: {
  desiredCapabilities: {
    browserName: 'MicrosoftEdge',
    javascriptEnabled: true
  }
}

edge: {
  desiredCapabilities : {
    browserName : 'MicrosoftEdge',
    edgeOptions:{
      w3c: false,
    }
  },
  start_process: false,
  webdriver: {
    default_path_prefix: '',
    server_path: './node_modules/edgedriver/bin/edgedriver',
    start_process: true,
    use_legacy_jsonwire: true
  }
},

I also have the most up-to-date version of Nightwatch (1.4.3). It seems like the browserName attribute is the problem, and the file that is checking that name doesn't implement anything for Edge, even though Nightwatchjs claims support for it. Any ideas?

Note: I am using cucumber-js with Nightwatchjs.


Solution

  • I've manually written a workaround for this. I modified the Nightwatchjs code to add support for the browsers it suggests it supports, but lacks the code for.

    EdgeDriver logic edgedriver.js

    OperaDriver logic operadriver.js

    Those are brand new files that go in ./node_modules/nightwatchjs/lib/runner/wd-instances.

    Next, replace the existing browersname.js file with this (or just add the new browser names in manually.

    Finally, go to webdriver-server.js and add the following code snippet to the "createInstance()" method in the switch statement:

     case BrowserName.EDGE:
        WebDriverImpl = EdgeDriver;
        break;
      case BrowserName.OPERA:
        WebDriverImpl = OperaDriver;
        break;
    

    and also add this to the top

    const EdgeDriver = require('./wd-instances/edgedriver.js');
    const OperaDriver = require('./wd-instances/operadriver.js');
    

    This will allow you to register your Opera or Edge browser now and run tests against them from your nightwatch.conf.js file (or json file). Here are my declarations:

    edge: {
      desiredCapabilities: {
        //alwaysMatch: { 'ms:edgeOptions': { args: ['--headless'] } },
        browserName: 'MicrosoftEdge',
        javascriptEnabled: true,
        acceptSslCerts: true,
        edgeOptions:{
          w3c: false,
          args : ["disable-web-security", "ignore-certificate-errors", "no-sandbox", "disable-gpu"]
        }
      },
      start_process: false,
      webdriver: {
        default_path_prefix: '',
        server_path: './bin/drivers/edgedriver',
        start_process: true,
        port: 4445,
        use_legacy_jsonwire: true
      }
    },
    opera: {
      desiredCapabilities : {
        browserName : 'opera',
        operaOptions : {
          w3c: false,
          args : ["disable-web-security", "ignore-certificate-errors", "no-sandbox", "disable-gpu"]
        },
      },
      webdriver: {
        start_process: true,
        port: 4450,
        server_path: './bin/drivers/operadriver',
        cli_args: [
          // --verbose
        ]
      }
    }
    

    The "args" above may not be valid for these two browsers, but because they are chromium, I copied the chrome flags. I have yet to verify that they are indeed valid, so keep that in mind.