1

We are trying to run Selenium Tests from Jenkins on our Windows Slaves as a Gradle project.

I am able to start Selenium from bat command gradle clean Smoke_Test and the test execution starts but it opens the browser in Background (the test case fails and it says that it cannot find a button to click on). If I manually run gradle clean Smoke_Test on the windows VM, it starts Selenium, opens the browser in Foreground and it executes the test successfully.

Is it possible to get the browser open in foreground when Jenkins starts the Selenium Test?

I have tried to give Jenkins-Slave Windows Service permissions to Allow service to interact with desktop but it still does not work.

Edit: I have to run Jenkins as a Service as the Windows Server is a slave. I cannot run java -jar Jenkins.war due to Enterprise restrictions. enter image description here

bilcy
  • 168
  • 1
  • 12
  • 1
    It is not possible to open the browser in the foreground with Jenkins, since it runs as a Windows service. Furthermore, the real problem is it can't find the element. To be honest, I bet you have a race condition causing the failure when attempting to find the element. I think you are trying to solve the wrong problem, and even if you got the browser opening in the foreground, I bet the test would still fail for the same reason. – Greg Burghardt Jul 11 '19 at 15:57
  • If I trigger the test manually, then Selenium is able to Click on that button and it is able to execute the test case Successfully. I am not sure why it is causing this problem when running in Background. – bilcy Jul 11 '19 at 16:02
  • The issue is it is being run in two different contexts, and possibly on two different machines, with two different processors and performance. The test running on the Jenkins server could be executing slower, causing a failure due to a race condition between selenium and the web page being tested. – Greg Burghardt Jul 11 '19 at 16:05
  • Running on a single machine. Restricted to a single session and made sure that on one is using it and still it is not working. If there is a race condition, then I assume that on multiple trials, I should get error in some conditions only, but I am getting the same error everytime. – bilcy Jul 12 '19 at 18:26
  • Is jenkins running on the same machine that you are running the tests using a batch file? – Greg Burghardt Jul 12 '19 at 18:55
  • Can you post the Java code that creates the web driver, and the line of code or method that is failing when running in Jenkins? – Greg Burghardt Jul 12 '19 at 18:55

2 Answers2

2

Interactive access on some desktop from a service is tricky, i wasted some time few years ago and fell back to the not so elegant, but working solution: Configure auto-login for some user and have some bat file in autostart to initiate a connection to jenkins via the jnlp option. Edit: Best to wait a few seconds, then download the agent.jar from the server, then start the connection on it.

Note however, that with Java 11, that jnlp option will get removed. Might need some special plugin then.

Dominik Gebhart
  • 2,980
  • 1
  • 16
  • 28
  • Sorry but would it be possible for you to look at [this](https://stackoverflow.com/questions/56987133/not-able-to-open-jenkinsui-from-slave-machine-when-jenkins-is-installed-via-war) question too? – Gurmanjot Singh Jul 12 '19 at 07:08
0

As @Greg mentioned, I was trying to solve a wrong problem. My test case was failing when executing through Jenkins because of my Chrome Driver. I changed the Chrome Driver to the Headless version and the test cases passed (with Chrome in Background, of course!).

bilcy
  • 168
  • 1
  • 12