I want to start 4 different chrome windows to run the same tests on 4 resolutions. –
I know protractor has a feature called multiCapabilities, and I know you can set the window size like this:
browser.manage().window().setSize(320, 480);
But I don't really find a way to combine these 2. Or is there an easier way to create this behaviour
Protractor allows setting the custom browser window size. Custom width and height can be mentioned in the Set Size function, the browser window will be resized to the mentioned width and height. Purpose: The function setSize() in the Window class is used to resize the browser window.
When you want to run protractor scripts by opening a browser instance for each test, you should add two capabilities shardTestFiles and maxInstances in the Capabilities block of the conf. js file. This will help to execute your scripts on same browser with multiple instances.
Testing Against Multiple Browsers If you would like to test against multiple browsers, use the multiCapabilities configuration option. Protractor will run tests in parallel against each set of capabilities. Please note that if multiCapabilities is defined, the runner will ignore the capabilities configuration.
As for me, the best way is to add multiCapabilities
in config:
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions' : {
args: ['--lang=en',
'--window-size=800,800']
},
specs: ['spec.js']
},{
'browserName': 'chrome',
'chromeOptions' : {
args: ['--lang=en',
'--window-size=350,650']
},
specs: ['spec.js']
// and so on
}]
A very simple solution that comes in my mind would be to create a for
loop in your test file with a switch
to make your tests running 4 times with a different resolution.
At the beginning of your specs:
describe('myApp', function () {
for (var i = 0; i < 4; i++) {
switch (i) {
case 0:
//set resolution 1
browser.manage().window().setSize(320, 480);
break;
case 1:
//set resolution 2
browser.manage().window().setSize(600, 800);
break;
case 2:
//set resolution 3
browser.manage().window().setSize(768, 1024);
break;
case 3:
//set resolution 4
browser.manage().window().setSize(1080, 1920);
break;
default:
return;
}
}
// beforeEach() {...};
// it('should do something', function(){...};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With