3
votes

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?

3
maximizing should make no difference to locating elements - Corey Goldberg
@CoreyGoldberg i'm locating element by id ,ex:(if the button is not showing on the browser because of minimize lets say it doesn't work) my question to you is selenium works with coordinates (x,y) ? - elie

3 Answers

1
votes

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

0
votes

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);
0
votes

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);