Protractor Multiple Size Browsers

2019-06-05 07:49发布

问题:

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.