10

Currently I am working on running Selenium scripts in Jenkins. Here, my issue is my browser window size which is 1382x754 px resolution.

But in Jenkins browser resolution was 1044x784. Due to this my script was unable to find the elements using x-path in Jenkins.

I have tried by setting the window size while initializing the driver, then window size is increased to 1048x788 px and then it is not increasing any more.

Any suggestions for any work around for this issue?

Environment : Windows 7 , Jenkins version(1.596), browser: Chrome

4

Me and my team encountered the same issue. In our case, the web app we were testing had a responsive view which caused our selectors to become invalid when browser window was reduced to such a small size (such as when being ran on Jenkins). Below are the steps we used to rectify the issue. Mind you, our Jenkins instance is being run on a VM with Windows installed.

  1. Create a new Jenkins node whose Launch Method is "Launch Agent via Java Web Start"

enter image description here

  1. In the jenkins node list, click on that nodes title and get its java web start launch command.

enter image description here

  1. Login to the VM, open up a terminal and run that command.

  2. Configure your jenkins jobs to only run on that node. In the jobs configure page:

enter image description here

Final Notes

  • We opted to have the javaws command to run everytime our VM was booted (via Windows Task Scheduler)
  • Notice how we didn't specify the node to run as a windows service. In our testing we found that having the node run as a windows service caused the resolution issue to persist.
  • This method forces the job to run directly on the VM, using the VM's resolution. In other words the resolution you see when you log into the VM will be the resolution your jobs run on. A side effect of this solution is that jobs will no longer run in the background. If you log into the VM with automation running, you'll be able to see it do its thing.

Windows Services Blurb

We had initially tried to run the new node as a windows service but wasn't able to find a way to fix the resolution issue. In the off chance that someone has arrived at this thread with this issue and is being forced to run their node as a service, the following may help them (it didn't for us).

  • Set the windows registry key NoInteractiveServices to 0
  • In windows services, disable Interactive Services Detection
  • In the service settings on windows, enable 'Allow Desktop Interaction'
| improve this answer | |
0

I had faced a similar issue. Scrolling was enabled on the modal window, so I scrolled down and then tried to access the element. It worked for me.

| improve this answer | |
  • Thanks @Sanchita, My issue is not resolved as you suggested bcoz when I am going fetch the text of an element by using xpath locator.When the screen resolution is different to my local and jenkins browser. xpath value is getting changed so my script fails in jenkins browser.If I change the xpath according to jenkins browser then i9t will fail in my local browser. – QAMember Feb 2 '16 at 10:02
  • I am not suggesting. My scenario is like that @user246 – QAMember Feb 19 '16 at 7:51
  • Apologies, comment was intended for Op, I entered it in the wrong place. – user246 Feb 19 '16 at 13:17
  • Maximising the browser at the beginning might help abit also. – masood ghz Apr 4 '16 at 10:15
0

I think you should commit code using Jenkins browser resolution (1044x784) to resolve issue on Jenkins.

On your local machine, you can change it to match with local resolution (but don't commit it).

| improve this answer | |
0

I simply defaulted selenium driver to open a browser resolution that will fit on both machines and even switched the xpath to css selector. Made it much easier for me to find the element.

| improve this answer | |
0

During the test run set the window size.

driver.manage().window().setSize(new Dimension(1044,784));

You can also try to make it larger, on the Jenkins run it might also make the windows larger then the display viewport.

| improve this answer | |
0

You can try something like this:

public void clickElementJS(String path, String formName){
    String xpathValue = cfg.config(path, formName);
    element = GenericExecutors.driver.findElement(By.xpath(xpathValue));
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].scrollIntoView(true);",element);  
    element.click();
}
| improve this answer | |
0

Unlock the system and execute the test scripts when ever you executing the scripts via Jenkins services, then the browser size might be not resized. try this , it worked for us

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.