简体   繁体   English

如何在Java中使用Sahi来最大化浏览器

[英]How to maximize browser using Sahi with java

I'm using Sahi Java Driver. 我正在使用Sahi Java驱动程序。 My Java code with Sahi is running well. 我的Sahi Java代码运行良好。 When tests are being executed the browser (in my case Firefox) is not maximized. 执行测试时,浏览器(在我的情况下为Firefox)未最大化。 The snippet of my Sahi Java code as below: 我的Sahi Java代码片段如下:

String browserType = "firefox";
Browser browser = new Browser(browserType);
browser.open();

How can I maximize the browser in Sahi with Java? 如何使用Java在Sahi中最大化浏览器?

If you are using Sahi Pro, you have a browserAction API which takes in maximize as a parameter. 如果您使用的是Sahi Pro,则您有一个browserAction API,该API以maximize作为参数。 This will maximize your browser. 这将最大化您的浏览器。 It also takes other parameters such as focus, minimize, refresh etc. You can check that out. 它还包含其他参数,例如焦点,最小化,刷新等。您可以检查一下。 So your code can be something like this: 因此您的代码可以是这样的:

browser.windowAction('maximize') //please check the syntax, copy paste might go wrong

The following line of Sahi Java code work fine. Sahi Java代码的以下行工作正常。 Add the following line of code after browser.open() ; 在browser.open()之后添加以下代码行;

browser.focusWindow();

I think it should be like, 我认为应该是这样,

-Make a Java Script code for full screen -使Java脚本代码全屏显示

function maximize() {
window.moveTo(0, 0);
window.resizeTo(screen.width, screen.height);
}
maximize();

-Run this script before start the test browser.execute("ScriptToRun") -在启动测试浏览器之前运行此脚本。execute(“ ScriptToRun”)

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM