我正在尝试使用 appium java 客户端进行 Android UI 测试。但是,我无法让它运行。这是我的 build.gradle 和错误消息。
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.wpjtest2"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
androidTestImplementation 'io.appium:java-client:5.0.4'
}
error:
Information:Gradle tasks [:app:assembleDebug, :app:assembleDebugAndroidTest]
Error:java.lang.IllegalAccessException: no such method: org.springframework.core.io.buffer.DataBufferUtils.lambda$read$0(ReadableByteChannel)ReadableByteChannel/invokeStatic
Error:java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
Error:java.lang.ClassNotFoundException: Class org.reactivestreams.Publisher not found
Error:java.nio.file.DirectoryNotEmptyException: C:\Users\zil\AppData\Local\Temp\lambdas5516872364251960030\org\springframework\core\io
Error:java.lang.IllegalAccessException: no such method: org.springframework.beans.factory.config.YamlMapFactoryBean.lambda$createMap$0(Map,Properties,Map)void/invokeSpecial
Error:java.lang.NoClassDefFoundError: org/yaml/snakeyaml/reader/UnicodeReader
Error:java.lang.ClassNotFoundException: Class org.yaml.snakeyaml.reader.UnicodeReader not found
Error:Execution failed for task ':app:transformClassesWithDesugarForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.google.devtools.build.android.desugar.Desugar with arguments {@C:\Users\xxx\project\WPJTest2\app\build\intermediates\tmp\desugar_args221997254795871866}
Information:BUILD FAILED in 15s
Error:java.lang.ClassNotFoundException: Class javax.validation.Validator not found
Information:9 errors
Information:0 warnings
Information:See complete output in console
谁能帮我检查一下我是否有正确且足够的依赖关系?有很多关于添加 Appium 的教程,但没有一个适合我。
另一方面,如果我可以使用Java 7与Appium集成,我应该怎么做?
虽然Appium http://appium.io文档齐全且用途广泛,Android Studio 的工作组合花了我一天的时间。就我而言,它是浓缩咖啡的替代品,因为它目前不支持免安装应用的多功能测试 https://stackoverflow.com/q/49609987/1112963。此外,Appium 还提供了更广泛的可能性来测试应用程序集成,例如 Firebase 消息传递、使用其他应用程序等。
-
安装Appium服务器 as UI https://github.com/appium/appium-desktop/releases.
-
Setup Appium Server for your localhost:
- 主机:127.0.0.1 端口:4723
- 编辑配置 -> 设置 ANDROID_HOME 和 JAVA_HOME 路径。
- Start server. You'll see a console, leave this window open.
-
运行安卓模拟器来自 Android Studio。
-
Start Appium Session for your Emulator in Appium UI (File -> New Session Window):
- If everything goes fine and console shows no log errors, then Appium Inspector window will open. Also your app will be run in the Emulator. In Inspector find elements by clicking on a screenshot. Record your actins with buttons atop and get autogenerated code:
-
添加库到你的项目app
or my_feature
gradle 文件。 Appium 和 Selenium 版本应该注意避免“没有这样的方法错误” -查看答案 https://stackoverflow.com/a/51960660/1112963:
dependencies {
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'io.appium:java-client:5.0.1'
androidTestImplementation 'org.seleniumhq.selenium:selenium-java:3.4.0'
}
-
创建 JUnit 功能测试类在你的Android项目中.../src/androidTest/java/
文件夹。您也可以使用简单的 JUnit 测试包装器。为了满足测试需求,您可以创建一个单独的 Java 项目或 Java 类main
方法在您的 Android 项目中,但将 Appium 测试集成到 Android Studio 测试功能中会更方便。还要检查您是否导入其他测试库,并且不要在代码中混合使用它(例如,@Test 可用于 TestNG 以及 JUnit)。在您的方法中使用 Appium Inspector 自动生成的代码,例如:
package com.example.my_project;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class SampleTest {
private AndroidDriver<MobileElement> driver;
@Test
public void testPlan()
throws MalformedURLException {
setUp();
testWorkUnit_WithCertainState_ShouldDoSomething();
abotherTestWorkUnit_WithCertainState_ShouldDoSomething();
tearDown();
}
public void setUp()
throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
desiredCapabilities.setCapability(
"platformName",
"Android");
desiredCapabilities.setCapability(
"deviceName",
"Android Emulator");
desiredCapabilities.setCapability(
"appPackage",
"com.example.my_project");
desiredCapabilities.setCapability(
"appActivity",
"com.example.my_project.MyActivity");
driver =
new AndroidDriver<>(
remoteUrl,
desiredCapabilities);
}
public void testWorkUnit_WithCertainState_ShouldDoSomething() {
MobileElement el1 =
driver.findElementById(
"com.example.my_project:id/urlField");
el1.sendKeys("example.com");
}
public void tearDown() {
driver.quit();
}
}
至于代码中的注释:@Before
and @After
在班级中的每个测试用例之前和之后使用(@BeforeClass
and @AfterClass
需要静态且不易处理)。因此,它每次都会重新启动应用程序,并且不方便进行链接测试。所以最好将一种方法注释为@Test
,它将调用其他未注释的方法来设置、按要求的顺序执行测试用例并完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)