Headless protractor not sharding tests

2019-07-13 07:06发布

问题:

I am trying to run my tests headless and shard both my test suites to run them in parallel. On my local machine they run in parallel but in this headless setup they run one after the other. I am using docker images for the web driver and protractor.

I am using webnicer-protractor docker image: https://hub.docker.com/r/webnicer/protractor-headless/ and using elgalu/selenium for the web driver.

My conf.js that I run looks like this:

exports.config = {
  //Headless
  //seleniumAddress: 'http://localhost:4444/wd/hub',
  seleniumAddress: 'http://localhost:24444/wd/hub',
  capabilities: {
    browserName: 'chrome',
    shardTestFiles: true,
    maxInstances: 2
  },
  specs: ['Suites/AccountSettingsSuite.js', 'Suites/CloneDashboardSuite.js']
}

回答1:

Protractor headless testing on real Google Chrome browser is now possible since Chrome >= 57, Chromedriver >= 2.29 along some basic config:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['headless', 'window-size=1920,1080']
    }
}

Another cool thing is that the windows size is not limited to the current display, is truly headless meaning in can be as large as needed for the tests.

Some webdriver features won't work there, for instance:

browser.manage().window().setPosition();
browser.manage().window().setSize();
browser.manage().window().maximize();

You will have to identify and remove the unsupported features, other than that chrome headless is working great for me.

It's important to note that for example sendKeys might trigger this error:

Failed: unknown error: an X display is required for keycode conversions, consider using Xvfb

If there is no real display or there is no Xvfb until this is fixed on Chrome side.

UPDATE The X display required error is fixed with ChromeDriver 2.31