我想知道测试不同设备分辨率的最佳方法是什么。 我有3种不同的分辨率,所有测试都必须通过。 我看到的问题在每个分辨率中都是重复的代码。如何做到这一点很容易重复使用。
你能举例说明应该如何做。
答案 0 :(得分:1)
一种方法是使用环境变量,即在onPrepare块/文件中:
if (process.env.E2E_CUSTOM_WIDTH && process.env.E2E_CUSTOM_HEIGHT) {
// e.g. from the command line (before running the tests)
// $ export E2E_CUSTOM_WIDTH=1400
// $ export E2E_CUSTOM_HEIGHT=900
browser.manage().window().setPosition(0, 0); // top left
// I've put this in global for simplicity, you may want to change that
global.fixedWidth = parseInt(process.env.E2E_CUSTOM_WIDTH);
global.fixedHeight = parseInt(process.env.E2E_CUSTOM_HEIGHT);
browser.manage().window().setSize(global.fixedWidth, global.fixedHeight);
}
因此,您的测试没有代码重复,只需通过操作shell中的环境变量,使用正确的配置矩阵运行量角器。
其他选项是使用单独的量角器配置文件和浏览器窗口大小变化。