Protractor Multiple Size Browsers

六眼飞鱼酱① 提交于 2019-12-23 02:47:12

问题


So for a web app that I'm working on, I'm using Protractor JS to test it - I'm writing it in the mobile-first style, so resizing shouldn't be an issue. Is there a way to get it to tests multiple sizes without huge amounts of repeated code? Writing a test repeated multiple times different sizing using a

browser.driver.manage().window().setSize(x, y);

with multiple values of x and y seems pretty inefficient, but I'm not sure I can think of something better?


回答1:


I would dynamically create tests based on a pre-defined array of sizes:

describe("Testing multiple browser sizes", function () {
    var sizes = [
        {x: 800, y: 600},
        {x: 300, y: 200}
    ];

    sizes.map(function(size) {
        it("should pass the test on browser size: x='" + size.x + "', y='" + size.y + "'", function() {
            browser.driver.manage().window().setSize(size.x, size.y);
            # test logic
        });
    }
});

This would help you to follow the DRY principle.



来源:https://stackoverflow.com/questions/37468427/protractor-multiple-size-browsers

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