Automation Scripts failing in Jenkins

I have written automation script wherein i have used explicit wait to wait until the visibility of that element and then perform a click operation on that. The webelement is present in anchor tag and it has a id. So i have used id to write xpath and identify the element .when i run the script locally it runs fine without any issue. But the same script when run in Jenkins is giving expected condition failed waiting for visibility of element and failing with timeout error. I had increased the explicit wait till 250 seconds and even with that it is failing. So that is when i thought it might be because of some other issue. I have verified the browser version and java version in local and in the server where Jenkins is running the job and both are same. So wanted to get help on this

Are you trying to do driver.manage().window().maximize()? It might have happened due to the window resizing issue. The same happened to me as well.

My test also ran fine in Eclipse but was failing in Jenkins. The problem that I was having was due to window resizing issue. When I maximized the window by driver.manage().window().maximize(); it always threw error. So I changed the window size manually to a given dimension, and the problem was solved.

// Give the resolution to which the window is to be maximized
Dimension dimen = new Dimension(1382, 744); 

// Resize the current window to above dimension
driver.manage().window().setSize(dimen); 

This is what I set the size of the windows to, and it works completely fine. Don’t know why Jenkins can’t find elements in maximized windows, but this solves for me.

3 Likes