chrome doesn't maximize when running selenium testNG from jenkins

坚强是说给别人听的谎言 提交于 2021-01-28 06:09:43

问题


I am facing a problem with running

selenium testNG

test from jenkins , the problem is that i am doing a login to my application and checking some element visibility , when i run the test from the batch file directly i got a success because i'm setting my google chrome driver to maximize using:

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

but if the browser is minimized some elements are not visible (front-end requirements) , so when i run the test from jenkins the test failed because i think that the browser doesn't maximized ,

can someone correct for me if i'm wrong , and some help of how to maximize the browser when running from jenkins?


回答1:


When you run your Selenium Suite from jenkins to particular server then driver.manage().window().maximize() doesnt work sometime. Thats why the preferred way is to go by usinn options depending on the browser you are using.

Eg:- For MAC or Linux:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--kiosk");
driver = new ChromeDriver(chromeOptions);

For Windows:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
driver = new ChromeDriver(chromeOptions);

You can try with this, it will work using jenkins




回答2:


As per manage().window().maximize() method not maximize a correct window using driver.manage().window().maximize(); to maximize the Chrome Browser is not the optimum way. Instead use ChromeOptions to maximize the Chrome Browser as follows:

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);

As an alternative you can also use the argument window-size as follows:

ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);



回答3:


Were facing the same kind of problem and solved using this snippet: (Java)

driver.manage().window().fullscreen();

It started failing, then passed arguments to reduce the font size for the contents displayed in screen.

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("window-size=1920,1080");
        chromeOptions.addArguments("--disable-notifications");
        chromeOptions.addArguments("--disable-extenstions");
        chromeOptions.addArguments("disable-infobars");
        chromeOptions.addArguments("force-device-scale-factor=0.75");
        chromeOptions.addArguments("high-dpi-support=0.75");
        driver = new ChromeDriver(chromeOptions);


来源:https://stackoverflow.com/questions/50772879/chrome-doesnt-maximize-when-running-selenium-testng-from-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!