gpt4 book ai didi

java - 此版本的 ChromeDriver 尚未在 Chrome 版本 75 和打开新浏览器窗口后出现 java.lang.IllegalStateException 上进行测试

转载 作者:行者123 更新时间:2023-12-02 01:25:15 24 4
gpt4 key购买 nike

我有一个测试类,其中有多个替代测试相继运行。为了确保测试是隔离的并且不给构建代理带来压力,我想在每个测试之间关闭并打开一个新的浏览器实例。

我遇到的问题是,当第一次打开新的浏览器实例后进行任何测试时,都会出现 IllegalStateException。

Selenide Version: 5.2.3
Chrome Version: 75.0.3770.100
Browser Driver Version: 74.0.3729.6
Selenium Version: 3.141.59
OS Version: Windows 10

到目前为止,我已尝试从测试中删除 Selenide.close() 方法调用,但这会导致每个测试使用相同的窗口。新的测试从上次测试完成的地方开始,这对我来说不太合适 - 我希望我的测试被隔离。我还尝试使用不同的方式实例化和关闭浏览器窗口,但使用最新的 Selenide 版本没有成功。

private static final String CHROMEDRIVER_V = "74.0.3729.6"
private static final String DEFAULT_TITLE = "Title";
private static final String TITLE_1 = "New alphabetic title";
private static final String TITLE_2 = "123456";

@BeforeEach
void beforeEach() throws Exception {
setup();
loginToService();
}

@Test
public void case_one() {
HomePage.title.shouldHave(Condition.text(DEFAULT_TITLE));
HomePageActions.changeTitle(TITLE_1));
HomePage.title.shouldHave(Condition.text(TITLE_1));
}

@Test
public void case_two() {
HomePage.title.shouldHave(Condition.text(DEFAULT_TITLE));
HomePageActions.changeTitle(TITLE_2));
HomePage.title.shouldHave(Condition.text(TITLE_2));
}

@AfterEach
void afterEach() throws Exception {
teardown();
}

private void setup() {
String url = "http://localhost:8080/login";
WebDriverManager.chromedriver()
.version(CHROMEDRIVER_V)
.timeout(20000)
.forceDownload()
.setup();
Selenide.open(url);
}

private void teardown() {
Selenide.close();
}

private void loginToService() {
LoginPage.loginField.setValue("login");
LoginPage.passField.setValue("pass");
LoginPage.loginButton.click();
HomePage.page.shouldBe(Condition.visible);

因此,对于上面的代码,我希望在启动整个测试类时:1. 执行 beforeEach() 方法,设置一个新的浏览器实例并登录到我们的服务。2.执行case_one()方法,测试所需的东西3. 执行 afterEach() 方法,关闭浏览器实例并释放资源4. 再次执行 beforeEach()5. 现在执行 case_two()6.再次执行afterEach(),测试套件完成

事实上,我得到的是 1-3 按预期运行,没有任何问题,并且明显地,当出现新的浏览器窗口时,步骤 4 开始正常,但在尝试执行步骤 4 中的登录代码时,运行会返回异常。

июл 15, 2019 6:22: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 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 7568
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1563204173.792][WARNING]: This version of ChromeDriver has not been tested with Chrome version 75.
июл 15, 2019 6:22:54 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
июл 15, 2019 6:22:54 PM com.codeborne.selenide.webdriver.BrowserResizer adjustBrowserSize
INFO: Set browser size to 1366x768
июл 15, 2019 6:22:55 PM com.codeborne.selenide.webdriver.WebDriverFactory logBrowserVersion
INFO: BrowserName=chrome Version=75.0.3770.100 Platform=XP
июл 15, 2019 6:22:55 PM com.codeborne.selenide.webdriver.WebDriverFactory createWebDriver
INFO: Selenide v. 5.2.3
июл 15, 2019 6:22:55 PM com.codeborne.selenide.webdriver.WebDriverFactory logSeleniumInfo
INFO: Selenium WebDriver v. 3.141.59 build time: 2018-11-14T08:17:03
июл 15, 2019 6:22:55 PM com.codeborne.selenide.drivercommands.CreateDriverCommand createDriver
INFO: Create webdriver in current thread 1: ChromeDriver -> ChromeDriver: chrome on XP (c531a2374a250d21a63eedec3d35c942)
июл 15, 2019 6:22:59 PM com.codeborne.selenide.drivercommands.CloseDriverCommand run
INFO: Close webdriver: 1 -> ChromeDriver: chrome on XP (c531a2374a250d21a63eedec3d35c942)
июл 15, 2019 6:22:59 PM com.codeborne.selenide.drivercommands.CloseBrowser run
INFO: Trying to close the browser ChromeDriver ...
июл 15, 2019 6:22:59 PM com.codeborne.selenide.drivercommands.CloseDriverCommand run
INFO: Closed webdriver 1 in 772 ms

java.lang.IllegalStateException: Webdriver has been closed. You need to call open(url) to open a browser again.

at com.codeborne.selenide.drivercommands.LazyDriver.getWebDriver(LazyDriver.java:64)
at com.codeborne.selenide.impl.ElementFinder.getSearchContext(ElementFinder.java:86)
at com.codeborne.selenide.impl.ElementFinder.getWebElement(ElementFinder.java:74)
at com.codeborne.selenide.commands.ToWebElement.execute(ToWebElement.java:11)
at com.codeborne.selenide.commands.ToWebElement.execute(ToWebElement.java:8)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:57)
at com.sun.proxy.$Proxy16.toWebElement(Unknown Source)
at com.codeborne.selenide.impl.ElementFinder.getSearchContext(ElementFinder.java:87)
at com.codeborne.selenide.impl.ElementFinder.getWebElement(ElementFinder.java:74)
at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:50)
at com.codeborne.selenide.commands.Should.should(Should.java:35)
at com.codeborne.selenide.commands.Should.execute(Should.java:29)
at com.codeborne.selenide.commands.Should.execute(Should.java:12)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)
at com.sun.proxy.$Proxy16.shouldBe(Unknown Source)
at my.project.java.TestClass.loginToService(TestClass.java:)
at my.project.java.TestClass.beforeEach(TestClass.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:628)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeMethodInExtensionContext(ClassTestDescriptor.java:302)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$synthesizeBeforeEachMethodAdapter$12(ClassTestDescriptor.java:290)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachMethods$2(TestMethodTestDescriptor.java:135)
at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:155)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachMethods(TestMethodTestDescriptor.java:134)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:109)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

任何帮助将不胜感激

最佳答案

此错误消息...

[WARNING]: This version of ChromeDriver has not been tested with Chrome version 75.

...意味着 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome 浏览器 session 。

您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:

  • 您正在使用 chromedriver=74.0
  • chromedriver=74.0 的发行说明明确提到以下内容:

Supports Chrome v74

Supports Chrome version 75

因此,ChromeDriver v74.0Chrome 浏览器 v75.0 之间存在明显的不匹配

<小时/>

解决方案

<小时/>

片尾

您可以在This version of ChromeDriver has not been tested with Chrome version 75 error with Selenium ChromeDriver and Chrome through facebook/php-webdriver中找到类似的讨论

关于java - 此版本的 ChromeDriver 尚未在 Chrome 版本 75 和打开新浏览器窗口后出现 java.lang.IllegalStateException 上进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57055117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com