gpt4 book ai didi

java - AndroidDriver 不是通用的,不能参数化

转载 作者:行者123 更新时间:2023-12-02 05:05:12 34 4
gpt4 key购买 nike

我想自动化一个简单的appium脚本来从主屏幕打开Play商店应用程序。当我尝试运行脚本时,出现以下错误:

AppiumDriver 类型不是通用的;它不能用参数参数化 AndroidDriver 类型不是通用的;它不能用参数进行参数化

我安装的依赖项是:

selenium-server-standalone-3.141.59.jar、commons-lang3-3.9.jar、client-combined-3.141.59.jar、client-combined-3.141.59-sources.jar、java-client-2.1 .0.jar、java-client-7.0.0.jar、java-client-4.1.2.jar

封装测试;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class AppiumTest {

public static void main(String[] args) {

//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "RZ8M41XNX1E"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "6.0");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");

//Instantiate Appium Driver
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);

} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}

最佳答案

如果这是您项目中唯一的类,您只需要一个依赖项:Appium java-client-7.0.0

您不需要其他的,因为它们是通过 Maven 的 transitive dependencies mechanism 解决的。在您的情况下,您正在遭受Jar Hell的困扰导致我在 Classpath 中出现多个不同的 Appium Java 客户端库冲突

鉴于这个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>testing.appium</groupId>
<artifactId>appium-java</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>
</dependencies>

</project>

您将获得以下依赖项:

>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< testing.appium:appium-java >---------------------
[INFO] Building appium-java 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ appium-java ---
[INFO] testing.appium:appium-java:jar:0.0.1-SNAPSHOT
[INFO] \- io.appium:java-client:jar:7.0.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-chrome-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-edge-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-firefox-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-ie-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-opera-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-remote-driver:jar:3.141.59:compile
[INFO] | +- org.seleniumhq.selenium:selenium-safari-driver:jar:3.141.59:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.8.15:compile
[INFO] | +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] | +- com.google.guava:guava:jar:25.0-jre:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | | +- org.checkerframework:checker-compat-qual:jar:2.0.0:compile
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.1.3:compile
[INFO] | | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] | | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] | +- com.squareup.okhttp3:okhttp:jar:3.11.0:compile
[INFO] | \- com.squareup.okio:okio:jar:1.14.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-support:jar:3.141.59:compile
[INFO] +- org.seleniumhq.selenium:selenium-api:jar:3.141.59:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.6:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.10:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- cglib:cglib:jar:3.2.8:compile
[INFO] | +- org.ow2.asm:asm:jar:6.2.1:compile
[INFO] | \- org.apache.ant:ant:jar:1.10.3:compile
[INFO] | \- org.apache.ant:ant-launcher:jar:1.10.3:compile
[INFO] +- commons-validator:commons-validator:jar:1.6:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] | +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.8:compile
[INFO] +- commons-io:commons-io:jar:2.6:compile
[INFO] +- org.springframework:spring-context:jar:5.1.0.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.1.0.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:5.1.0.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:5.1.0.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.1.0.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.1.0.RELEASE:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.9.1:compile
[INFO] \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.801 s
[INFO] Finished at: 2019-05-29T15:00:39+02:00
[INFO] ------------------------------------------------------------------------

您还可以查看appium-java-testng示例项目并熟悉 Parallel Tests - Best Practices文章。

关于java - AndroidDriver 不是通用的,不能参数化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56356605/

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