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

Posted

技术标签:

【中文标题】AndroidDriver 不是通用的,不能参数化【英文标题】:AndroidDriver is not generic, it cannot be parameterised 【发布时间】:2019-10-14 19:58:13 【问题描述】:

我想自动化一个简单的 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());
        
    

【问题讨论】:

在同一个包中是否还有另一个名为AndroidDriver的类? 不,我没有另一个 It 可能有帮助 【参考方案1】:

如果这是您项目中唯一的类,您只需要一个依赖项: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 文章。

【讨论】:

以上是关于AndroidDriver 不是通用的,不能参数化的主要内容,如果未能解决你的问题,请参考以下文章

为什么在外部参数化类中创建一个数组,其中组件类型是一个被认为是“通用数组创建”的内部类?

为什么可以将int []作为通用类型参数,但不能将int作为常规类型参数? [关闭]

在 TypeScript 中扩展参数化接口的通用接口

将实例化的 System.Type 作为通用方法的类型参数传递

子类化 Javascript 数组。 TypeError:Array.prototype.toString 不是通用的

jmeter通用场景设置以及参数化策略