gpt4 book ai didi

javascript - 如何在 Protractor/WebdriverJS 中设置默认浏览器窗口大小

转载 作者:IT王子 更新时间:2023-10-29 02:41:43 26 4
gpt4 key购买 nike

出于某种原因,当我在工作中运行我的测试时,浏览器被最大化,但当我在家里运行它们时,它只打开一个大约 50% 宽度的浏览器窗口。这会导致向下滚动等出现一些差异,因此我希望它在运行测试的每台机器上打开一个相同大小的浏览器窗口。执行此操作的最佳方法是什么?

(我找到了其他语言的一些答案,但我无法将它们改编成 JavaScript)

添加

browser.executeScript('window.moveTo(0,0);' +
'window.resizeTo(screen.width, screen.height);');

什么都不做(显然 Google Chrome 不支持 window.moveTowindow.resizeTo)。

最佳答案

您可以通过运行以下命令来设置默认浏览器大小:

var width = 800;
var height = 600;
browser.driver.manage().window().setSize(width, height);

要最大化浏览器窗口,请运行:

browser.driver.manage().window().maximize();

要设置位置,运行:

var x = 150;
var y = 100;
browser.driver.manage().window().setPosition(x, y);

如果出现错误:

WebDriverError: unknown error: operation is unsupported with remote debugging

Operation not supported when using remote debugging Some WebDrivercommands (e.g. resizing the browser window) require a Chrome extensionto be loaded into the browser. ChromeDriver normally loads this"automation extension" every time it launches a new Chrome session.

However ChromeDriver can be instructed to connect to an existingChrome session instead of launching a new one. This is done using'debuggerAddress' in the Capabilities (aka ChromeOptions) object.Since the automation extension is only loaded at startup, there aresome commands that ChromeDriver does not support when working withexisting sessions through remote debugging.

If you see the error "operation not supported when using remotedebugging", try rewriting the test so that it launches a new Chromesession. This can be done by removing 'debuggerAddress' from theCapabilities object.

来源: Operation not supported when using remote debugging

关于javascript - 如何在 Protractor/WebdriverJS 中设置默认浏览器窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20023567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com