r/javascript • • Apr 08 '19

Microsoft releases new Microsoft Edge based on Chromium

https://twitter.com/MSEdgeDev/status/1115283353731600384?s=19
606 Upvotes

220 comments sorted by

View all comments

Show parent comments

16

u/vinnl Apr 08 '19

Yeah same here, the primary reason being that those are the only two major browsers that run on Linux and can be automated using Selenium, so they can be automatically tested in CI. But there are more and more places that only actively test in Chrome, unfortunately.

1

u/[deleted] Apr 09 '19

I have errors running chrome with selenium installed in nodejs. May I know if you use nodejs to run it?

Or you use python/java based selenium?

1

u/vinnl Apr 09 '19

I use a Java-based Selenium, which I control from Node using WebdriverIO. The latter has a selenium-standalone plugin which ships Selenium, so if you have Java installed, that should be enough. In CI, I run my tests against Selenium's Firefox and Chrome images, which has both the browsers and Selenium set up, so I can just point WDIO to those.

1

u/[deleted] Apr 09 '19

I see.

I just started to write automated user simulation test for websites a few days ago.

I tried WebdriverIO as well, but it contains errors that I couldn't debug for chrome.

(node:9569) UnhandledPromiseRejectionWarning: Error: Required option "capabilities" is missing

Following the guide https://developers.google.com/web/updates/2017/04/headless-chrome#using_webdriverio

It works for firefox though, following this guide https://webdriver.io/docs/gettingstarted.html

I am using puppeteer headless chrome now, it's not that easy to write, for example, not understanding why it failed to click on a product link no matter how I tried to catch it using different syntax, like page.$$ or page.evaluate() with Javascript and DOM api

I wonder if I should learn Java now to use selenium. I have taken a lot of time to debug all these stuff lol

nonetheless, I am considered to be inexperienced in programming field

1

u/vinnl Apr 09 '19

You don't need to learn Java, no worries :)

I should note that I'm still on the previous version of WebdriverIO, so my setup is probably a little bit different. That said, it appears to say that you need to add a capabilities key to your wdio.conf.js. The documentation of that option is here.

Presumably, if you'd want it to work for Chrome and Firefox, you'd have to add something like this:

capabilities: [
    { browserName: 'chrome' },
    { browserName: 'firefox' },
],

(Assuming you have Chromedriver installed as well, which should be the case if you use selenium-assistant.)

1

u/[deleted] Apr 09 '19 edited Apr 09 '19

I have figured it out, for WebdriverIO only, not using any other selenium programs.

For starters, the code from

https://developers.google.com/web/updates/2017/04/headless-chrome#using_webdriverio

is deprecated already really, for example, desiredCapabilities is not enough, capabilities is not set and .init() has been removed as a function don't know since when. I tried to modified the code from

https://webdriver.io/docs/gettingstarted.html for chromium, for what I have debugged, like setting hostname and port, and running headless for firefox.

To start geckodriver for firefox,

./geckodriver --port 4444

To start chromedriver for chromium/chrome,

./chromedriver -p 9515

then my code to execute in nodejs,

const { remote } = require('webdriverio');

(async () => {
    const browser = await remote({
      hostname: '127.0.0.1',

      // ================================
      // port for firefox
      // ================================
      //port: 4444,
 
      // ================================
      // port for chrome/chromium
      // ================================
      port: 9515,

      logLevel: 'error',
      path: '/',
      capabilities: {

        // ================================
        // In Linux (Debian), either chromium or chrome, 
        // they work the same way. It will look in $PATH for google-chrome first, 
        // if fail, then it look for chromium
        // ================================
        browserName: 'chromium',

        // ================================
        // firefox
        // ================================
        //browserName: 'firefox',

        // ================================
        // option for chromium/chrome only
        // ================================
        //chromeOptions: {args: ['--headless']},

        // ================================
        // option for firefox only
        // ================================
        //"moz:firefoxOptions":{
        //  "args":["-headless"]
        //},
      },
    });

    await browser.url('https://webdriver.io');

    const title = await browser.getTitle();
    console.log('Title was: ' + title);

    await browser.deleteSession();
})().catch((e) => console.error(e));

Sources for debugging:

  1. https://webdriver.io/docs/options.html#capabilities

  2. https://webdriver.io/docs/gettingstarted.html

  3. https://developers.google.com/web/updates/2017/04/headless-chrome#using_webdriverio

  4. https://github.com/webdriverio/webdriverio/issues/2581

Documentation:

  1. https://medium.com/@mannyluvstacos/using-headless-chrome-for-your-selenium-tests-with-webdriverio-ce99b09d564

  2. https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode

2

u/vinnl Apr 09 '19

That's great that you figured it out, and shared it for people running into this in the future. As a tip, I'd really recommend you to look into selenium-standalone, so you don't have to start the drivers manually yourself.

1

u/[deleted] Apr 09 '19

Yea sure, I will look into it.

For now, the code below should work, also from https://developers.google.com/web/updates/2017/04/headless-chrome#using_webdriverio

but it won't work for some reasons, for starting server in the same script that I execute, only for chromedriver though,

have to install it via npm,

npm i chromedriver --save

then add the code to the script,

const chromedriver = require('chromedriver');

const PORT = 9515;

chromedriver.start([
  '--url-base=wd/hub',
  `--port=${PORT}`,
  '--verbose'
]);

need to debug, later