量角器多尺寸浏览器 [英] Protractor Multiple Size Browsers

查看:85
本文介绍了量角器多尺寸浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对于我正在处理的Web应用程序,我正在使用Protractor JS对其进行测试 - 我正在以移动优先的方式编写它,因此调整大小应该不是问题。有没有办法让它在没有大量重复代码的情况下测试多种尺寸?使用

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

多个x和y值似乎效率很低,但我不确定我能想到更好的东西?

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

推荐答案

我会基于预先定义的大小数组动态创建测试

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

这可以帮助您关注 DRY原则

This would help you to follow the DRY principle.

这篇关于量角器多尺寸浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆