Appium 代码报错。求大神帮忙

枫瑕 · July 01, 2014 · Last by 枫瑕 replied at July 22, 2014 · 1243 hits

使用官方实例,运行时报错。

代码:

import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.URL;
import java.util.List;

public class AndroidContactsTest {
private AppiumDriver driver;

@Before
public void setUp() throws Exception {
// set up appium
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "./apps");
File app = new File(appDir, "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.3");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.example.android.contactmanager");
capabilities.setCapability("appActivity", ".ContactManager");
driver = new AppiumDriver(new URL("http://192.168.165.72:4723/wd/hub"), capabilities);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void addContact(){
WebElement el = driver.findElement(By.name("Add Contact"));
el.click();
List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.swipe(100, 500, 100, 100, 2);
driver.findElementByName("Save").click();
}

}

错误日志:

java.lang.RuntimeException: Stub!
at org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:5)
at org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:6)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:81)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:43)
at com.tydic.crm.AndroidContactsTest.setUp(AndroidContactsTest.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
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.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
at com.tydic.crm.AndroidContactsTest.tearDown(AndroidContactsTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
共收到 16 条回复 时间 点赞

貌似是在pc上直接跑用例了。 贴下adb的log吧

枫瑕 #3 · July 01, 2014 作者

不好意思,没有注意到发贴夫定。下次一次注意。

是直接在PC上跑的。

ADB上没有日志啊。 还没有连过去啊。还在eclipse上就直接报错了。

枫瑕 #4 · July 01, 2014 作者

就只有启动appium时的启动日志,就都没有了。

#3楼 @jian12278 这次请修改

@jian12278 driver = new AppiumDriver(new URL("http://192.168.165.72:14718/wd/hub"), capabilities); 这个是不行的,appium 启动的时候默认用了 4723


[['-p', '--port'], {
defaultValue: 4723
, required: false
, type: 'int'
, example: "4723"
, help: 'port to listen on'
}],

你这里的错误是 new URL("http://192.168.165.72:14718/wd/hub") 这个就不对了。

枫瑕 #7 · July 02, 2014 作者

@lihuazhang 我启动appium时,改了端口号为:14718,IP试过127.0.0.1,也试了本机真实IP地址。都是报同样的错的。

#7楼 @jian12278 把 server 的日志也给下吧。另外加下头像。

枫瑕 #9 · July 02, 2014 作者

@lihuazhang
只有Appium的启动信息,没有其它信息了。

C:\Users\Administrator>adb devices -l
List of devices attached
emulator-5554 device product:sdk model:sdk device:generic


C:\Users\Administrator>appium -Uemulator-5554
info: Welcome to Appium v1.1.0 (REV e433bbc31511f199287db7724e1ce692bcb32117)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: socket.io started
info: Non-default server args: {"udid":"emulator-5554"}
枫瑕 #10 · July 17, 2014 作者

有哪位大神知道这是啥问题吗?

枫瑕 #11 · July 17, 2014 作者

有哪位大神能有点好的建议啊!!

你的appium log
info: Appium REST http interface listener started on 0.0.0.0:4723

可是你的code寫的是
driver = new AppiumDriver(new URL("http://192.168.165.72:4723/wd/hub"), capabilities);

選一個ip跟port用吧, 兩邊要一樣才行

#12楼 @gigayaya 没关系, 0.0.0.0 应该是任意ip。通常情况下,网络中所说的0.0.0.0的IP地址表示整个网络,即网络中的所有主机。

#13楼 @lihuazhang
我剛剛試了一下, appium使用0.0.0.0, code使用192.168.0.1, appium沒有收到訊息沒有反應
appium使用0.0.0.0, code使用127.0.0.1, appium有收到訊息有反應,

不過我跳出的錯誤訊息是timeout, 跟樓主的錯誤訊息好像不一樣, 僅供參考

appium 1.2.0, 用的是Java

枫瑕 #15 · July 22, 2014 作者

启动配置,都进行指定了。

C:\Users\Administrator>appium -a127.0.0.1 -p4723 -Uemulator-5554
info: Welcome to Appium v1.1.0 (REV e433bbc31511f199287db7724e1ce692bcb32117)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: socket.io started
info: Non-default server args: {"udid":"emulator-5554","address":"127.0.0.1"}

代码中配置的是:

driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

还是一样的错。
appium版本是1.1.0,用的也是JAVA

枫瑕 #16 · July 22, 2014 作者

各引用库及软件的版本。

ADT版本是:adt-bundle-windows-x86_64-20140321
android驱动用的是: android-18
java-client用的是:1.5.0
selenium用的是: 2.41.0
Junit是用的ADT自带的JUNIT org.junit_4.11.0.v201303080030

请问大神,这版本是不是也会有配套版本的关系呢?

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up