在没有GUI的Linux机器上通过jenkins执行Selenium测试(仅限CLI) - HEADLESS MODE

时间:2015-08-06 06:35:52

标签: linux selenium jenkins selenium-webdriver headless

这是关于Selenium自动化测试。我有一些Jenkins作业设置用于一些测试执行.Jenkins是在没有GUI的 Ubuntu机器上设置的(仅限CLI)。 因此,当我运行脚本时,似乎显然无法找到Web浏览器 这项工作在Windows中完美运行。在Windows中,我得到了这样的结果。

窗口成功结果

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
06/08/2015 00:04:47,996   INFO [main] (BasicTestObject.java:251) - ======BEGIN Test workflow============
06/08/2015 00:04:48,002   INFO [main] (BasicTestObject.java:252) - BEGIN Test: MlpBvt
06/08/2015 00:04:48,002   INFO [main] (BasicTestObject.java:253) - ======BEGIN Test workflow============

06/08/2015 00:04:58,862  DEBUG [main] (DefaultUIDriver.java:300) - Opened url: http://mlpdemo.qaprod.ecollege.com/
06/08/2015 00:04:58,912   INFO [main] (BasicTestObject.java:296) - -------------BEGIN Test Method-------------------
06/08/2015 00:04:58,913   INFO [main] (BasicTestObject.java:297) - BEGIN Test Method: verifyAdminLogin
06/08/2015 00:04:58,913   INFO [main] (BasicTestObject.java:298) - -------------BEGIN Test Method-------------------
06/08/2015 00:04:58,969  DEBUG [main] (DefaultUIElement.java:980) - Waiting 60000ms for element to be displayed [Locator = {By.xpath: //input[@id='clientname']}]
06/08/2015 00:04:59,058  DEBUG [main] (DefaultUIElement.java:538) - Element is displayed [Locator = {By.xpath: //input[@id='clientname']}]
06/08/2015 00:04:59,059  DEBUG [main] (DefaultUIElement.java:992) - After 89ms, element is displayed [Locator = {By.xpath: //input[@id='clientname']}]

在Linux上我就是这样

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite

06/08/2015 00:18:46,834   INFO [main] (BasicTestObject.java:251) - ======BEGIN Test workflow============
06/08/2015 00:18:46,839   INFO [main] (BasicTestObject.java:252) - BEGIN Test: MlpBvt
06/08/2015 00:18:46,839   INFO [main] (BasicTestObject.java:253) - ======BEGIN Test workflow============
06/08/2015 00:18:46,998  DEBUG [main] (CapturePageOnFailureListener.java:186) - CapturePageOnFailure found 2 parameters 
06/08/2015 00:18:47,002   WARN [main] (DebugUIDriver.java:311) - Called quit() on debugDriver containing null uiDriver
06/08/2015 00:18:47,025   INFO [main] (BasicTestObject.java:304) - -------------END Test Method-------------------
06/08/2015 00:18:47,026   INFO [main] (BasicTestObject.java:305) - END Test Method: verifyAdminLogin
06/08/2015 00:18:47,026   INFO [main] (BasicTestObject.java:306) - -------------END Test Method-------------------
06/08/2015 00:18:47,031   INFO [main] (BasicTestObject.java:304) - -------------END Test Method-------------------
06/08/2015 00:18:47,032   INFO [main] (BasicTestObject.java:305) - END Test Method: VerifyProfessorLogin
06/08/2015 00:18:47,032   INFO [main] (BasicTestObject.java:306) - -------------END Test Method-------------------
06/08/2015 00:18:47,036   INFO [main] (BasicTestObject.java:304) - -------------END Test Method-------------------
06/08/2015 00:18:47,036   INFO [main] (BasicTestObject.java:305) - END Test Method: VerifyStudentLogin
06/08/2015 00:18:47,037   INFO [main] (BasicTestObject.java:306) - -------------END Test Method-------------------
06/08/2015 00:18:47,038   INFO [main] (BasicTestObject.java:283) - ======END Test workflow============
06/08/2015 00:18:47,038   INFO [main] (BasicTestObject.java:284) - END Test: MlpBvt
06/08/2015 00:18:47,040   INFO [main] (BasicTestObject.java:285) - ======END Test workflow============
06/08/2015 00:18:47,100  DEBUG [main] (ProcessTool.java:36) - Getting current tool for LINUX
06/08/2015 00:18:47,100   WARN [main] (ProcessTool.java:40) - Could not find ProcessTool for LINUX
06/08/2015 00:18:47,101   WARN [main] (ProcessTool.java:88) - There was no ProcessTool for LINUX
06/08/2015 00:18:47,101  DEBUG [main] (ProcessTool.java:115) - process count for There was no ProcessTool for LINUX:1
Tests run: 12, Failures: 1, Errors: 0, Skipped: 11, Time elapsed: 1.976 sec <<< FAILURE!

Results :

Failed tests: 

提到

06/08/2015 00:18:47,002   WARN [main] (DebugUIDriver.java:311) - Called quit() on debugDriver containing null uiDriver

请就此事向我提供一些技术专长。我可以在linux上运行这个工作吗?请帮帮我

1 个答案:

答案 0 :(得分:5)

对于unix系统,您必须使用Xvfb在无头模式下运行测试,对于jenkins,您可以使用xvfb plugin

如何在无头模式下打开firefox的简单示例

from xvfbwrapper import Xvfb
from selenium import webdriver

xf = Xvfb()  #  xf = Xvfb(1920, 1080) - will create virtual display with 1920x1080 size
xf.start()
# browser won't appear
driver = webdriver.Firefox()
driver.get("http://google.com")