【问题标题】:Selenide / Jenkins: java.lang.IllegalStateException: No webdriver is bound to current thread:Selenide / Jenkins:java.lang.IllegalStateException:没有 webdriver 绑定到当前线程:
【发布时间】:2019-11-18 15:39:38
【问题描述】:

我有一些用 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: No webdriver is bound to current thread: 你有过类似情况的经历吗? 为什么在本地机器上测试正确完成,但在公司的主要 Jenkins 上只有 No webdriver is bound to current thread 引起的故障? 只有操作系统是不同的。 这是Linux下jenkins配置的问题吗? 当我使用 Jenkins(使用 Maven)在本地运行测试时,我收到相同的消息,但实际上创建了 WebDriver 并运行我的测试用例。 我的 maven 目标是: mvn clean test -Puat

在测试中声明 Chrome:

    @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();
}

_______________编辑 现在我在构建之前检查 Start Xvfb,然后在 Jenkins 工作构建环境中将其关闭,我读到这很重要,也许 xvfb 是原因,我不知道,现在在控制台中我有

java.io.IOException: Cannot run program "Xvfb": error=2, No such file or directory

【问题讨论】:

  • 对我来说同样的问题。你能找到解决办法吗?

标签: jenkins selenide


【解决方案1】:

有人回答吗?如错误所示,您需要调用 open Url 。 driver.open(URL HERE) 在设置方法的末尾。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多