我在我的系统中安装了Appium,Andorid studio和Node Js。我有Java 1.8。
我的 build.gradle 文件是
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.bhupendra.appiumdemo"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'org.seleniumhq.selenium:selenium-java:2.53.0'
compile 'io.appium:java-client:3.4.1'
}
我的测试类 CalculatorTest.java
package com.example.bhupendra.appiumdemo;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
public class CalculatorTest {
public static AndroidDriver driver;
@BeforeClass
public static void setUp() throws Exception {
// set up appium
// File classpathRoot = new File(System.getProperty("user.dir"));
//TODO: Set correct ClassPath
// File appDir = new File(classpathRoot, "\selendroid-test-app\app\build\outputs\apk");
// File app = new File(appDir, "app-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformVersion", "6.0");
//capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.selendroid.testapp");
capabilities.setCapability("appActivity", "io.selendroid.testapp.HomeScreenActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterClass
public static void tearDown() throws Exception {
driver.quit();
}
/**
* Test for selendroid-test-app
*
* @author - bhupendra.dhore@theleanapps.com
* Generated using Barista - http://moquality.com/barista
*/
@Test
public void test_testselenium() {
new TouchAction(driver).longPress(driver.findElement(By.id("my_text_field"))).release().perform();
driver.findElement(By.id("my_text_field")).click();
Assert.assertTrue(driver.findElement(By.id("my_text_field")).isEnabled());
driver.findElement(By.id("my_text_field")).sendKeys("my name is bhupendra");
}
}
在运行我的测试时,我收到此错误
"C:\Program Files\Java\jdk1.8.0_111\bin\java" -ea -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files\Android\Android Studio\bin" -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Android\Android Studio\lib\idea_rt.jar;C:\Program Files\Android\Android Studio\plugins\junit\lib\junit-rt.jar;C:\Users\Bhupendra\AppData\Local\Android\Sdk\platforms\android-24\data\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\classes\test\debug;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\classes\debug;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-v4\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-v4\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-compat\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-compat\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-compat\24.2.1\jars\libs\internal_impl-24.2.1.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\animated-vector-drawable\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\animated-vector-drawable\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-fragment\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-fragment\24.2.1\jars\libs\internal_impl-24.2.1.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-fragment\24.2.1\jars\classes.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\io.netty\netty\3.5.7.Final\811465e6dfc89d7c78d21de6a9747b6046cb5403\netty-3.5.7.Final.jar;C:\Program Files\Android\Android Studio\gradle\m2repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\commons-beanutils\commons-beanutils\1.9.2\7a87d845ad3a155297e8f67d9008f4c1e5656b71\commons-beanutils-1.9.2.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\com.google.code.gson\gson\2.6.2\f1bc476cc167b18e66c297df599b2377131a8947\gson-2.6.2.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.apache.ant\ant-launcher\1.9.4\334b62cb4be0432769679e8b94e83f8fd5ed395c\ant-launcher-1.9.4.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.apache.commons\commons-exec\1.3\8dfb9facd0830a27b1b5f29f84593f0aeee7773b\commons-exec-1.3.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\cglib\cglib\3.2.1\e5358fe643ab732ca07b2c0a7bbdd47719cca166\cglib-3.2.1.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.apache.ant\ant\1.9.4\6d473e8653d952045f550f4ef225a9591b79094a\ant-1.9.4.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-ie-driver\2.53.0\27b703e9fba9c0f636109cf4bd697c1f208ac825\selenium-ie-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\cglib\cglib-nodep\2.1_3\58d3be5953547c0019e5704d6ed4ffda3b0c7c66\cglib-nodep-2.1_3.jar;C:\Program Files\Android\Android Studio\gradle\m2repository\org\ow2\asm\asm\5.0.3\asm-5.0.3.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-firefox-driver\2.53.0\5dc655b1999898d2fc3791c649b7355d98629a69\selenium-firefox-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.apache.commons\commons-lang3\3.4\5fe28b9518e58819180a43a850fbc0dd24b7c050\commons-lang3-3.4.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-leg-rc\2.53.0\bdabcf672449c588913ae32973dd8f7d54f510de\selenium-leg-rc-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\net.java.dev.jna\jna\4.1.0\1c12d070e602efd8021891cdd7fd18bc129372d4\jna-4.1.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\io.appium\java-client\3.4.1\290ad98ce2df8d3409c3ff64a93a5495a1c86f05\java-client-3.4.1.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-media-compat\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-media-compat\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-media-compat\24.2.1\jars\libs\internal_impl-24.2.1.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-safari-driver\2.53.0\c80224258a8b702c99f2d7b3847ce89dc1bcd2bd\selenium-safari-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\19.0\6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9\guava-19.0.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-ui\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-ui\24.2.1\jars\libs\internal_impl-24.2.1.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-ui\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-vector-drawable\24.2.1\jars\classes.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-vector-drawable\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-utils\24.2.1\res;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-utils\24.2.1\jars\libs\internal_impl-24.2.1.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\exploded-aar\com.android.support\support-core-utils\24.2.1\jars\classes.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-api\2.53.0\a6105ad5c43dcc02c1cf87250111b0a7f1a7c2e6\selenium-api-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\commons-collections\commons-collections\3.2.2\8ad72fe39fa8c91eaaf12aadb21e0c3661fe26d5\commons-collections-3.2.2.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-remote-driver\2.53.0\eb76ed037ba5a7c11cce11effd0e2175056905ac\selenium-remote-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-java\2.53.0\645a24b52c9e5704e900ac755b5800352e981af7\selenium-java-2.53.0.jar;C:\Users\Bhupendra\AppData\Local\Android\Sdk\extras\android\m2repository\com\android\support\support-annotations\24.2.1\support-annotations-24.2.1.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\commons-validator\commons-validator\1.5.0\26b98c21975c5caf6bf34bacdeb7183be7a65970\commons-validator-1.5.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-chrome-driver\2.53.0\7541a3948c3fb31122ee9633731e8103f3292b0a\selenium-chrome-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\net.java.dev.jna\jna-platform\4.1.0\23457ad1cf75c2c16763330de5565a0e67b4bc0a\jna-platform-4.1.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-edge-driver\2.53.0\9f3da0dfa620ae8cd71afacfdd6ddae5028ce1ea\selenium-edge-driver-2.53.0.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\commons-digester\commons-digester\1.8.1\3dec9b9c7ea9342d4dbe8c38560080d85b44a015\commons-digester-1.8.1.jar;C:\Users\Bhupendra\.gradle\caches\modules-2\files-2.1\org.seleniumhq.selenium\selenium-support\2.53.0\3706aa8a696d1b7938365a41ee7ca46309a0b2d\selenium-support-2.53.0.jar;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\sourceFolderJavaResources\test\debug;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\app\build\intermediates\sourceFolderJavaResources\debug;C:\Users\Bhupendra\AndroidStudioProjects\AppiumDemo\build\generated\mockable-android-24.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.example.bhupendra.appiumdemo.CalculatorTest
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:96)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:70)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:58)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
at com.example.bhupendra.appiumdemo.CalculatorTest.setUp(CalculatorTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
java.lang.NullPointerException
at com.example.bhupendra.appiumdemo.CalculatorTest.tearDown(CalculatorTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Process finished with exit code -1
我真的很感激任何建议。