问题
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.
回答1:
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.
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/24842837/browser-never-opens-when-running-robot-framework-tests-from-jenkins