gpt4 book ai didi

java - Selenide 测试因 org/openqa/selenium/NoSuchSessionException 失败

转载 作者:行者123 更新时间:2023-12-02 08:48:46 29 4
gpt4 key购买 nike

我正在尝试在 mvn 项目中使用 Selenide 和 testng 编写一个 selenium E2E 测试用例。这是我的第一个基本测试用例,我尝试打开一个链接。但是,当我使用 Idea intellij 运行测试时,我看到以下错误:

TestNG] Running:
/Users/Prajakta_Mahamuni/Library/Caches/IntelliJIdea2019.2/temp-testng-customsuite.xml
java.lang.NoClassDefFoundError: org/openqa/selenium/NoSuchSessionException
at com.codeborne.selenide.impl.WebDriverThreadLocalContainer.<init>(WebDriverThreadLocalContainer.java:39)

这是我的测试用例:

package com.symantec.epmp.scsem.web.management.controllers;

import org.testng.annotations.Test;
import static com.codeborne.selenide.Selenide.*;

public class ConsoleITTest {

@Test
public void mdrLogin() {

open("https://www.google.com");

}

}

和 pom.xml:

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.42.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.webdriver</groupId>
<artifactId>webdriver-selenium</artifactId>
<version>0.9.7376</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.42.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.42.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>2.42.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>2.42.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>

我发现此错误的原因是对 selenium-java 的依赖,但它存在于项目中。测试无法运行的原因可能是什么。

最佳答案

我认为这是由于 selenium-api 造成的。它仍然指向旧版本 2.42.0。另请检查您的其他驱动程序,如果您遇到同样的问题,请根据您喜欢执行的浏览器更新它们

请引用下面我正在使用的 POm 文件,该文件对我来说工作得很好。

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<selenium.hub.url>http://local.example.com:4444/wd/hub</selenium.hub.url>
<browser>firefox</browser>
<holdBrowserOpen>false</holdBrowserOpen>
<webdriver.gecko.driver>${user.home}/bin/geckodriver</webdriver.gecko.driver>
<webdriver.chrome.driver>${user.home}/bin/chromedriver</webdriver.chrome.driver>
<surefire.argLine></surefire.argLine>
<selenium.version>3.0.1</selenium.version>
<selenide.version>4.0</selenide.version>
</properties>

<prerequisites>
<maven>3.3</maven>
</prerequisites>

<profiles>
<profile>
<id>firefox</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<browser>firefox</browser>
</properties>
</profile>
<profile>
<id>chrome</id>
<properties>
<browser>chrome</browser>
</properties>
</profile>
<profile>
<id>phantomjs</id>
<properties>
<browser>phantomjs</browser>
</properties>
</profile>
<profile>
<id>ie</id>
<properties>
<browser>ie</browser>
</properties>
</profile>
<profile>
<id>safari</id>
<properties>
<browser>safari</browser>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>htmlunit</id>
<properties>
<browser>htmlunit</browser>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>ci-server</id>
<properties>
<surefire.argLine>-Dremote=${selenium.hub.url}</surefire.argLine>
</properties>
</profile>
<profile>
<id>local</id>
<properties>
<holdBrowserOpen>true</holdBrowserOpen>
</properties>
</profile>
</profiles>

<build>
<defaultGoal>clean test</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<detail>true</detail>
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>
<systemPropertyVariables>
<browser>${browser}</browser>
<holdBrowserOpen>${holdBrowserOpen}</holdBrowserOpen>
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
</systemPropertyVariables>
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>${selenide.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

关于java - Selenide 测试因 org/openqa/selenium/NoSuchSessionException 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60913724/

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