我有一些用Selenide/Java编写的测试。我的Windows上也有本地Jenkins,测试在这个Jenkins下运行得很好,但是我在外部Jenkins(Linux)上运行同一个仓库的测试时有问题。
Jenkins的日志:
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running [1mTests[m
ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
1491 [main] INFO com.github.javafaker.Faker - Using default locale en
Jul 08, 2019 2:36:49 PM com.codeborne.selenide.drivercommands.LazyDriver getAndCheckWebDriver
INFO: No webdriver is bound to current thread: 1 - let's create a new webdriver
Jul 08, 2019 2:36:49 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
2687 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://chromedriver.storage.googleapis.com/ to seek chromedriver
3700 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Latest version of chromedriver is 76.0.3809.25
3704 [main] INFO io.github.bonigarcia.wdm.Downloader - Downloading https://chromedriver.storage.googleapis.com/76.0.3809.25/chromedriver_linux64.zip
4066 [main] INFO io.github.bonigarcia.wdm.Downloader - Extracting binary from compressed file chromedriver_linux64.zip
4194 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as /var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/76.0.3809.25/chromedriver
Starting ChromeDriver 76.0.3809.25 (a0c95f440512e06df1c9c206f2d79cc20be18bb1-refs/branch-heads/3809@{#271}) on port 28990
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Jul 08, 2019 2:36:52 PM com.codeborne.selenide.drivercommands.LazyDriver getAndCheckWebDriver
INFO: No webdriver is bound to current thread: 1 - let's create a new webdriver
Starting ChromeDriver 76.0.3809.25 (a0c95f440512e06df1c9c206f2d79cc20be18bb1-refs/branch-heads/3809@{#271}) on port 30572
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[ERROR] [1;31mTests [0;1mrun: [0;1m3[m, [1;31mFailures: [0;1;31m3[m, Errors: 0, Skipped: 0, Time elapsed: 5.878 s[1;31m <<< FAILURE![m - in [1mTests[m
[ERROR] test001_logowanie_programs(Tests) Time elapsed: 3.105 s <<< FAILURE!
java.lang.IllegalStateException: No webdriver is bound to current thread: 1. You need to call open(url) first.
at Tests.test001_logowanie_programs(Tests.java:38)
[ERROR] test002_logowanie_evaluation(Tests) Time elapsed: 0.058 s <<< FAILURE!
java.lang.IllegalStateException: No webdriver is bound to current thread: 1. You need to call open(url) first.
at Tests.test002_logowanie_evaluation(Tests.java:50)
[ERROR] test003_fail(Tests) Time elapsed: 0.159 s <<< FAILURE!
java.lang.IllegalStateException: No webdriver is bound to current thread: 1. You need to call open(url) first.
at Tests.test003_fail(Tests.java:67)
[INFO]
[INFO] Results:
[INFO]
[ERROR] [1;31mFailures: [m
[ERROR] [1;31m Tests.test001_logowanie_programs:38 » IllegalState No webdriver is bound to cu...[m
[ERROR] [1;31m Tests.test002_logowanie_evaluation:50 » IllegalState No webdriver is bound to ...[m
[ERROR] [1;31m Tests.test003_fail:67 » IllegalState No webdriver is bound to current thread: ...[m
[INFO]
[ERROR] [1;31mTests run: 3, Failures: 3, Errors: 0, Skipped: 0[m
[INFO]
[ERROR] There are test failures.
Please refer to /var/lib/jenkins/jobs/nawa_selenide/workspace/target/surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.071 s
[INFO] Finished at: 2019-07-08T14:36:56+02:00
[INFO] Final Memory: 31M/330M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/lib/jenkins/jobs/nawa_selenide/workspace/pom.xml to com/nawa/1.0-SNAPSHOT/nawa-1.0-SNAPSHOT.pom
channel stopped
Finished: UNSTABLE
在每次测试中,我们都有:java.lang.IllegalStateException:没有Web驱动程序绑定到当前线程:您有类似情况的经验吗?为什么在本地机器上测试是正确的,但在公司的主Jenkins上只有故障是由没有webdriver绑定到当前线程引起的?只有操作系统不同。这是Linux下的Jenkins配置问题吗?当我在本地运行测试时,使用Jenkins(使用Maven),我得到了同样的消息,但是WebDriver实际上已经创建并运行了我的测试用例。mvn清洁测试-Puat
测试中的铬声明:
@BeforeClass
public void setUp() throws Exception {
Configuration.holdBrowserOpen = false;
Configuration.browser = "chrome";
Configuration.timeout = 10000;
Configuration.headless = true;
SelenideLogger.addListener("AllureSelenide", new AllureSelenide().screenshots(true).savePageSource(true));
objReader.environmentPropertiesLoader();
}
现在我在Jenkins作业构建环境中检查了构建前启动Xvfb,并在构建后关闭它,我读到这一点非常重要,可能是Xvfb的原因,我不知道,现在在控制台中我有
java.io.IOException: Cannot run program "Xvfb": error=2, No such file or directory
2条答案
按热度按时间gkn4icbw1#
有人回答了吗?您需要在设置方法结束时调用打开URL,因为错误显示为. driver.open(URL HERE)。
vatpfxk52#
这是我解决方案:open()之后,存储当前webDriver,使用之前-恢复webDriver