serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
721 stars 517 forks source link

Script is failing from Jenkins due to difference in screen size - Chrome Browser #3169

Open BSuneel opened 1 year ago

BSuneel commented 1 year ago

I am working on running Selenium(Serenity) scripts in Jenkins. Here, my browser window size which is 1920x1080 px resolution and chrome version is 114.0.5735.199. The script is working as expected in locally but not from Jenkins.

I have tried the below codes

Logic One: Dimension size = getDriver().manage().window().getSize(); int width = size.getWidth(); int height = size.getHeight(); // print the current window size System.out.println("Before window size is: " + width + "x" + height);

ChromeOptions options = new ChromeOptions();
options.addArguments("enable-automation");
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
options.addArguments("--no-sandbox");
options.addArguments("--disable-extensions");
options.addArguments("--dns-prefetch-disable");
options.addArguments("--disable-gpu");

ChromeDriver chromeDriver = new ChromeDriver(options);
Dimension afterDimension = chromeDriver.manage().window().getSize();
width = afterDimension.getWidth();
height = afterDimension.getHeight();
// print the current window size
System.out.println("After window size is: " + width + "x" + height);

Logic Two : Dimension size = getDriver().manage().window().getSize(); int width = size.getWidth(); int height = size.getHeight(); // print the current window size System.out.println("Before window size is: " + width + "x" + height); getDriver().manage().window().setSize(new Dimension(1920, 1080)); System.out.println("After window size is: " + width + "x" + height);

Logic Three: From serenity config file.

               #--Browser will maximized for all the browsers
               serenity.browser.maximized=true
               chrome.switches =--start-maximized
               serenity.browser.width=1920
               serenity.browser.height=1080

The same configurations are working fine from locally(Windows Machine- Eclipse) but from Jenkins not.

I'm using the below versions: Serenity : 2.0.41 Chrome Browser : 114.0.5735.199

wakaleo commented 1 year ago

Your code looks fine, it is most likely an issue with the Jenkins virtual display setup. Check the screenshots on the jenkins build to see what it is doing.

BSuneel commented 1 year ago

Hi John Ferguson Smart,

The below code working fine with Firefox browser from Jenkins, not with chrome browser.

--Browser will maximized for all the browsers

           serenity.browser.maximized=true
           chrome.switches =--start-maximized
           serenity.browser.width=1920
           serenity.browser.height=1080

Find the below screenshots and logs: Firefox browser: image

12:28:40 INFO: Detected dialect: W3C 12:28:41 Before window size is: 1920x1080 12:28:41 2023-06-27 01:58:41,780 9112 [main] INFO c.t.automation.common.OpenSite - Privacy error not displayed, Hence going with securely. 12:28:42 After window size is: 1920x1080 12:28:43 2023-06-27 01:58:43,216 10548 [main] INFO c.t.a.e.n.EsatLoginPageActions - User has entered emaild 12:28:43 2023-06-27 01:58:43,268 10600 [main] INFO c.t.a.e.n.EsatLoginPageActions - User has provided the Password

Chrome Browser image

12:41:37 Before window size is: 1044x788 12:41:37 2023-06-27 02:11:37,600 5986 [main] INFO c.t.automation.common.OpenSite - Privacy error not displayed, Hence going with securely. 12:41:37 After window size is: 1044x788 12:41:37 2023-06-27 02:11:37,800 6186 [main] INFO c.t.automation.utils.TfDriverWait - JQuery call is in Progress 12:41:38 2023-06-27 02:11:38,470 6856 [main] INFO c.t.a.e.n.EsatLoginPageActions - User has entered emaild

The chrome browser getting 1044x788 resolution. Due to this small resolution menus are overlapping and scripts are failing in chrome browser.

Note: The same script working as expected with Firefox browser.

Any suggestions for chrome browser issue. Thanks in Advance.