Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run protractor tests with different window sizes?

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

like image 897
codeaddslife Avatar asked Mar 10 '14 16:03

codeaddslife


People also ask

How do you set a window size on a protractor?

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.

How do you run multiple specs on a protractor?

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.

How do you run a protractor test in multiple browsers?

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.


2 Answers

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
}]
like image 131
Andrew Kostenko Avatar answered Sep 22 '22 12:09

Andrew Kostenko


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(){...};
});
like image 31
glepretre Avatar answered Sep 25 '22 12:09

glepretre