[英]Selenium Grid: how to maximize browser window using RemoteWebDriver and ChromeDriver
I would like to know how can I maximize the browser window using Selenium Grid and RemoteWebDriver with the most popular browsers. 我想知道如何使用Selenium Grid和RemoteWebDriver与最流行的浏览器最大化浏览器窗口。
This question has not been solved yet in this community, there is another question that could look like this: How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#? 这个问题在这个社区尚未解决,还有一个问题可能如下: 如何使用C#在Selenium WebDriver(Selenium 2)中最大化浏览器窗口? But in that question is not clear how to maximize the browser window in RemoteWebDriver. 但在那个问题尚不清楚如何在RemoteWebDriver中最大化浏览器窗口。
On Firefox and IE I guess it is in the same way driver.manage().window().maximize();
在Firefox和IE上我猜它的方式与driver.manage().window().maximize();
In Chrome we have to do: 在Chrome中我们必须这样做:
ChromeOptions options = new ChromeOptions(); options.AddArgument("--start-maximized"); driver = new ChromeDriver(options);
The question is how can I apply that to RemoteWebDriver? 问题是如何将其应用于RemoteWebDriver?
If i understand your question correctly you want to know how to pass driver options to remote driver.In that case where ever you are creating driver object you need to create desire capabilities and use one of the constructor of the remote driver with capability parameter. 如果我正确理解你的问题你想知道如何将驱动程序选项传递给远程驱动程序。在这种情况下,你需要创建驱动程序对象,你需要创建欲望功能并使用带有功能参数的远程驱动程序的构造函数之一。 For example 例如
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(URL, capabilities);
//driver = new ChromeDriver(capabilities);
You also can use QAF which abstraction driver configuration and management outside the code. 您还可以在代码之外使用QAF抽象驱动程序配置和管理。 Where you can set driver capabilities by using properties. 您可以使用属性设置驱动程序功能 。 As alternate You also can use Driver listener for such purpose. 作为备用您也可以使用Driver侦听器来实现此目的。 For example: 例如:
Using Properties: 使用属性:
Following two properties will do the needful for chrome driver: 以下两个属性将需要chrome驱动程序:
drive.name=chromeDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}
For remote driver: 对于远程驱动:
remote.server=<remote server or grid url>
drive.name=chromeRemoteDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}
Using Listener: 使用Listener:
void beforeInitialize(Capabilities capabilities){
if(capabilities.getBrowserName().equalIgnorCase("chrome"){
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
((DesiredCapabilities)capabilities).setCapability(ChromeOptions.CAPABILITY, options);
}
}
void onInitialize(QAFExtendedWebDriver driver){
//for browser other than chrome...
driver.manage().window().maximize();
}
In Java you could do it like this: 在Java中你可以这样做:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
RemoteWebDriver driver = new ChromeDriver(options);
It was already hinted at in the comments but to point it out: You can assign a ChromeDriver
instance to a RemoteWebDriver
type. 它已在评论中暗示过,但要指出:您可以将ChromeDriver
实例分配给RemoteWebDriver
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.