我想自动化一个简单的appium脚本,以从主屏幕打开play store应用。当我尝试运行脚本时,出现以下错误:
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());
}
}
}
答案 0 :(得分:0)
如果这是项目中唯一的类,则只需一个依赖项:Appium java-client-7.0.0。
您不需要其他人,因为通过Maven的transitive dependencies mechanism已解决了他们。在您的情况下,您正遭受Jar Hell的困扰,导致我在Classpath
中遇到了多个不同的Appium Java Client库因此给出了这个 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文章。