简体   繁体   English

运行不同窗口尺寸的量角器测试?

[英]Run protractor tests with different window sizes?

I want to start 4 different chrome windows to run the same tests on 4 resolutions. 我想启动4个不同的镀铬窗口,在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 但我真的没有找到一种方法来组合这些2.或者有一种更简单的方法来创建这种行为

As for me, the best way is to add multiCapabilities in config: 至于我,最好的方法是在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
}]

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. 我想到的一个非常简单的解决方案是在您的测试文件中使用switch创建一个for循环,以使您的测试以不同的分辨率运行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(){...};
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM