Run protractor tests with different window sizes?

萝らか妹 提交于 2019-12-17 23:18:31

问题


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


回答1:


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(){...};
});



回答2:


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
}]


来源:https://stackoverflow.com/questions/22305297/run-protractor-tests-with-different-window-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!