javascript 使用不同的窗口大小运行量角器测试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22305297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:53:44  来源:igfitidea点击:

Run protractor tests with different window sizes?

javascriptangularjsjasmineprotractor

提问by codeaddslife

I want to start 4 different chrome windows to run the same tests on 4 resolutions. –

我想启动 4 个不同的 chrome 窗口以在 4 个分辨率上运行相同的测试。——

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);

我知道量角器有一个叫做 multiCapabilities 的功能,我知道你可以像这样设置窗口大小: 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

但我真的没有找到将这两个结合起来的方法。或者有没有更简单的方法来创建这种行为

采纳答案by glepretre

A very simple solution that comes in my mind would be to create a forloop in your test file with a switchto make your tests running 4 times with a different resolution.

我想到的一个非常简单的解决方案是for在您的测试文件中创建一个循环,switch使您的测试以不同的分辨率运行 4 次。

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

回答by Andrew Kostenko

As for me, the best way is to add multiCapabilitiesin config:

至于我,最好的方法是添加multiCapabilities配置:

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