3

I'm experimenting with running my RF/Selenium2Library tests from Jenkins on my OSX laptop. Jenkins is installed as default as user 'jenkins'. I have the RF plugin for Jenkins installed and environment variables set, and everything works fine EXCEPT the browser never opens (neither firefox nor chrome) and the tests fail with selenium timeouts saying that such and such element never appeared.

My hunch is that I need to set a display variable somewhere to get the browser to open properly.

Here's my 'execute shell' command from Jenkins for this project:

source /Users/Shared/Jenkins/.bash_profile; pybot -b /Users/Shared/Jenkins/robot_output/dbug.log -i SMOKE01 -d /Users/Shared/Jenkins/robot_output/ /Users/KWHome/Dev/PycharmProjects/BHI/Tests; exit 0

Again, Selenium seems to think a browser is open somewhere and waits for the initial elements to appear, but they never do because no browser is actually open. I'm a total Jenkins newbie, so huge thanks for any advice on understanding what's going on here.

ADDED:

Here's some output from the jenkins user dbug log created after a build from Jenkins:

20140719 21:28:23.914 - INFO - Opening browser 'firefox' to base url 'https://staging.azzi-mvconnects.com/'
20140719 21:28:27.273 - DEBUG - Opened browser with session id a2414ad7-f523-7441-8a54-dd5c68f4049b
20140719 21:28:27.274 - INFO - +----- END KW: Selenium2Library.Open Browser (3360)
20140719 21:28:27.274 - INFO - +----- START KW: Selenium2Library.Maximize Browser Window [ ]
20140719 21:28:27.415 - INFO - +----- END KW: Selenium2Library.Maximize Browser Window (141)
20140719 21:28:27.416 - INFO - +----- START KW: Selenium2Library.Wait Until Element Is Visible [ ${home_login_button} ]
20140719 21:28:32.500 - INFO - +------ START KW: Selenium2Library.Capture Page Screenshot [ ]
20140719 21:28:32.909 - INFO - </td></tr><tr><td colspan="3"><a href="selenium-screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>
20140719 21:28:32.909 - INFO - +------ END KW: Selenium2Library.Capture Page Screenshot (409)
20140719 21:28:32.910 - FAIL - Element 'ctl00_LoginLink' was not visible in 5 seconds

The browser appears to have 'opened', but it never appears on the desktop. I tried putting 'DISPLAY=:0' before the command to run pybot but no change.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
SkipKent
  • 457
  • 1
  • 6
  • 13
  • In the first part of your question you write "the browser never opens", but later you say "Selenium seems to think a browser is open". What makes you say selenium thinks a browser is open? Does the "Open Browser" keyword complete with no errors? Have you turned on debugging (use the `--debug ` option) and looked at the logs? – Bryan Oakley Jul 19 '14 at 17:41
  • Yes, exactly. I did turn on debugging, and the debug log shows firefox opening: 20140719 21:13:47.312 - INFO - Opening browser 'firefox' to base url 'https://staging.azzi-mvconnects.com/' 20140719 21:13:50.917 - DEBUG - Opened browser with session id 12ac901c-4a60-a341-bca9-cd31f03861bb – SkipKent Jul 20 '14 at 01:15
  • ...but no browser actually opens on the desktop, and no elements are found and the tests fail. When I run the test at the command line, it runs fine. I tried running it after su'ing to user 'jenkins' and it ran fine to (at the command line). When run from the Jenkins webapp, though, I get this weird situation. – SkipKent Jul 20 '14 at 01:17
  • I'm wondering if the fact that I'm logged into osx as myself but running Jenkins as user 'jenkins' is causing the issue. Do I need to give Jenkins permission somehow to access the display? – SkipKent Jul 20 '14 at 01:30
  • So I tried the same scenario on a Windows laptop. I created a simple robot selenium2library test, downloaded Jenkins, kicked off the test from Jenkins and...success! The test takes a LONG time to run, but passes. BUT I STILL DON'T SEE IT RUN! This is what I don't understand. Does Jenkins come with it's own virtual os or something? Why don't I see the browser come up when the test is kicked off by a local instance of Jenkins instead of the command line? – SkipKent Jul 21 '14 at 00:43
  • This issue appears to touch on this: http://stackoverflow.com/questions/17283091/sikuli-selenium-testing-on-jenkins-allow-the-browser-to-be-launched-in-the-for?rq=1 – SkipKent Jul 21 '14 at 00:46
  • This one answers my question, hands down: http://stackoverflow.com/questions/8787682/unable-to-see-selenium-tests-are-running-on-the-browser-when-the-test-is-run-by?rq=1. Jenkins runs the tests as a service in the background. It must do something similar on osx/unix. – SkipKent Jul 21 '14 at 00:51

3 Answers3

5

If your Jenkins job needs to run something that displays a GUI, you cannot run that build in Jenkins which runs as a background service (whether on Windows, Mac or Linux).

(In Linux you can play tricks with Xvnc or similar fake X servers and there are even Jenkins plugins that make it simpler.)

Your alternatives are either:

  • Log in using the GUI session and run Jenkins in a terminal window by typing java -jar /path/to/jenkins.war. When Jenkins is started in the GUI context, any processes started by Jenkins are able to talk to the GUI system and draw windows.
  • Or you can set up a JNLP slave in Jenkins, then log in using the GUI session, open a web browser to access your Jenkins and start the JNLP slave that connects to Jenkins master and now that the slave is running in GUI context, you can configure the job to execute on the slave. Processes that execute in the slave will be able to talk to the GUI system and draw windows.
sti
  • 11,047
  • 1
  • 27
  • 27
0

This question here answers my question, hands down: stackoverflow.com/questions/8787682/…. Jenkins runs the tests as a service in the background. It must do something similar on osx/unix.

SkipKent
  • 457
  • 1
  • 6
  • 13
  • Link: http://stackoverflow.com/questions/8787682/unable-to-see-selenium-tests-are-running-on-the-browser-when-the-test-is-run-by?rq=1 – SkipKent Jul 21 '14 at 00:53
  • it's not service. Jenkins will log on as a user (e.g.: jenkins) and run everything using that user. If you login using the same user as Jenkins, you will see everything – Nguyen Vu Hoang Jul 21 '14 at 05:49
  • Nguyen, thanks for the clarification. Is there a way I can have it run as a different user? I tried changing the string in /Library/LaunchDaemons/org.jenkins-ci.plist but it didn't seem to make a difference. – SkipKent Jul 22 '14 at 17:14
  • you can go to services -> jenkins and change user credential there. For more information, you could take a look at this tutorial http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html – Nguyen Vu Hoang Jul 23 '14 at 02:53
0

We need to run headless browser. We had achieved this for Firefox. We used centOS in jenkins Slave.

I have documented it here: http://dailychitty.blogspot.in/2014/07/configuring-jenkins-agent-to-run-robot.html

Deepti K
  • 590
  • 2
  • 9
  • 26