出现错误:无法访问 org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator
Posted
技术标签:
【中文标题】出现错误:无法访问 org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator【英文标题】:Getting error: cannot access org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator 【发布时间】:2020-10-01 06:46:41 【问题描述】:我正在尝试通过 maven 命令运行 appium 代码,但无法这样做。我搜索了很多,但没有找到任何问题的答案。
将代码作为 TestNG 运行时,它运行良好。但是,当我尝试使用 mvn test 运行时,我得到了错误。
Utilities.java(mvn 抛出错误的地方)
package practise.AppiumFramework;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class Utilities
AndroidDriver<AndroidElement> driver;
public Utilities(AndroidDriver<AndroidElement> driver)
this.driver = driver;
public void scrollToText(String text)
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\""+text+"\"));");
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>practise</groupId>
<artifactId>AppiumFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AppiumFramework</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.3.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.1.6</version>
</dependency>
</dependencies>
</project>
如果你们需要更多信息,请告诉我?
【问题讨论】:
【参考方案1】:日志中存在错误 -
Class file for org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator not found
Maven 无法加载上述类。
尝试如下设置useSystemClassLoader=false
-
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
参考 - https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html
【讨论】:
以上是关于出现错误:无法访问 org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator的主要内容,如果未能解决你的问题,请参考以下文章
为啥会出现此错误:无法在初始化程序中访问实例成员'*'。”?
出现错误:无法访问 org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator