Appium 代码报错。求大神帮忙

枫瑕 · 2014年07月01日 · 最后由 枫瑕 回复于 2014年07月22日 · 1336 次阅读

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

代码:

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 吧

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

是直接在 PC 上跑的。

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

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

@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") 这个就不对了。

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

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

@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 · 2014年07月17日 Author

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

枫瑕 #11 · 2014年07月17日 Author

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

你的 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 · 2014年07月22日 Author

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

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 · 2014年07月22日 Author

各引用库及软件的版本。

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

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

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册