Jenkins在后台模式(如无头模式)下启动chromedriver

时间:2019-11-18 12:07:08

标签: selenium jenkins selenium-chromedriver

我已经在Windows 10计算机上设置了Jenkins服务器。运行作业(简称为mvn test -DsuiteXmlFile=%TestSuite%)时,作业将成功编译并开始测试。我看到第一个被跳过,第二个失败,然后又开始一个又一个地通过。没有打开任何Chrome窗口,但是当我签入任务管理器时,可以看到它在后台打开了多个Chrome进程。在CMD(同样在Power Shell中)中调用mvn test -DsuiteXmlFile=TestSuite时,它将在前面打开Chrome。 查看jenkins日志,我发现它在c:/ System / TEMP /目录中创建了一个.bat文件并执行了该批处理文件。我什至尝试复制文件,将其放在项目的根目录下,并通过CMD进行调用,相同的.bat文件可以按预期工作。詹金斯仍然在后台打开Chrome。知道是什么原因造成的吗?如何迫使Jenkins在Foreground中运行测试?

我的chromedriver版本是78.0.3904.70(如果需要)。 两种情况下的日志都相同:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
18.11.2019 03:50:38.019 INFO  - [AutomationListener]:Staring to run test suite with 11 tests
Nov 18, 2019 3:50:38 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 39924
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1574077841.726][WARNING]: Timed out connecting to Chrome, retrying...
Nov 18, 2019 3:50:43 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1574077845.835][WARNING]: Timed out connecting to Chrome, retrying...
18.11.2019 03:50:55.489 INFO  - [BasePage]:The element: By.cssSelector: polygon is clicked
18.11.2019 03:50:55.494 INFO  - [AutomationListener]:----------------------------------------------------------------------
18.11.2019 03:50:55.495 INFO  - [AutomationListener]:Starting to run TestMethod test method
18.11.2019 03:50:55.495 INFO  - [AutomationListener]:----------------------------------------------------------------------

1 个答案:

答案 0 :(得分:1)

当Jenkins从属服务器在后台作为服务运行时,它启动的每个程序(例如运行批处理文件)也将在后台运行。解决方案是将Jenkins从站作为常规程序在前台运行。