Appium 新手贴:Windows 平台上的使用 Java 语言实现 appium 自动化程序 for Android (完整版)

Mr Wang · 2014年04月02日 · 最后由 小青 回复于 2017年04月28日 · 3773 次阅读
本帖已被设为精华帖!

首先说下楼主也是个新手,摸索了好几天天 终于完成了第一个 appium 程序,帖子写的不合理的地方,请大家轻喷,指导,大家一起学习。写这个帖子就是为了方便新手能快速入门,也算是自己的一种巩固吧。好了,开始直奔主题!

一,环境配置篇
在 Windows 上配置
1)下载安装 node.js(http://nodejs.org/download/)安装的时候有选项,记得把环境变量添加到 path 路径
2)使用 npm 安装 appium,运行 CMD 输入 npm install -g appium(有些朋友反应在 cmd 下运行 npm 无效,如果这样请把 nodejs 的目录添加到用户变量的 path 下重启 cmd 即可 参考帖子:http://blog.csdn.net/iispring/article/details/8023319),如下图:

3)下载安装 Android SDK(http://developer.android.com/sdk/index.htmlANDROID_HOME 环境变量指向 SDK 路径,PATH 变量设定%),设置 ANDROID_HOME%\tools 和% ANDROID_HOME%\platform-tools
4)安装 JDK 并设置 JAVA_HOME 环境变量
5)安装 ANT,并将%ANT_HOME%\bin 路径加到 PATH
6)安装 MAVEN,设置%M2_HOME%\bin,并添加到 PATH 中
7)安装 Git
8)运行 CMD 输入 appium-doctor 检查你的环境是不是都配置好了 如图:

9)下载 selenium 类库(http://docs.seleniumhq.org/download/ 请下载 java 平台的)
10)Eclipse 自定义库中新建一个 selenium 库 指向本地的硬盘 selenium lib 的路径 如图:

到此 环境算是配置好了,其中(5,6,7 这三步骤只是为了构建项目和从 github 拖拽项目时候需要的,我的帖子不涉及到,但是为了 appium-doctor 顺利检查成功通过还是设置下)

二,appium 启动篇
由于我测试是连接真机的,所以这里需要先通过 adb devices -l 命令获得 真机的 udid 号,详细步骤如下:
1)真机(安卓版本 4.2.2)通过 USB 连接 电脑,驱动装好,打开 USB 调试模式
2)运行 cmd 输入 adb devices -l 查看 UDID 如图:

3)再在 cmd 中输入 appium -a 127.0.0.1 -p4723 -U4d007e9a1b0050d1 (-a 表示 ip,-p 表示端口,-U 表示设备的 udid 可以通过 appium -h 查看更多命令)
4)如果如下图所示 就表示 appium 服务启动成功了,注意这个窗口不要关闭 因为这是 appium 的服务 关了就关了服务,后面过程无法执行,而且这个窗口也是 日志输出的窗口用于排错。

三,代码执行篇
这块我主要是执行的是官方的演示代码:通讯录管理 app,安装打开 app,并添加一个联系人保存的操作
1)首先去下载 ContactManager.apk(http://yunpan.cn/QInSWzP2YWgTJEclipse 工作目录的 apps 文件夹下),等会放在
2)打开 Eclipse,新建一个 java project,去 appium 的 github(https://github.com/appium/appium/tree/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appiumAndroidContactsTest.java 拷贝下来)上将 放到自己的包下,如下图所示:

其中 apps 目录 是我放 ContactManager.apk 用的
3)在 Project 上右键点击 Build Path -> Add Libraries.. ->User Library -> 勾选自己刚刚自建的 selenium 库(环境配置篇 第 10 步)这样代码就不会因为在不到对应的库而报错了
4)对代码进行部分修改:

package com.incito.appiumdemo;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
import java.net.URL;
import java.util.List;

public class AndroidContactsTest {
    private WebDriver driver;

    @Before
    public void setUp() throws Exception {
        // set up appium
        File classpathRoot = new File(System.getProperty("user.dir"));
        //存放app目录:apps
        File appDir = new File(classpathRoot, "apps");
        File app = new File(appDir, "ContactManager.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("device","Android");
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
         //我真机的安卓版本是4.2.2
        capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
         //使用的是windows平台
        capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("app-package", "com.example.android.contactmanager");
        capabilities.setCapability("app-activity", ".ContactManager");
        driver = new SwipeableWebDriver(new URL("http://127.0.0.1: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.findElements(By.tagName("textfield"));
       textFieldsList.get(0).sendKeys("wangyang");
        textFieldsList.get(1).sendKeys("18872573204");
        textFieldsList.get(2).sendKeys("stephenwang@gmail.com");
        driver.findElement(By.name("Save")).click();
    }

    public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
        private RemoteTouchScreen touch;

        public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
            super(remoteAddress, desiredCapabilities);
            touch = new RemoteTouchScreen(getExecuteMethod());
        }

        public TouchScreen getTouch() {
            return touch;
        }
    }
}

5)代码右键 run as "Junit test" appium 窗口会有日志记录,代码无报错 而且在真机上完成了这个安装 apk 添加联系人的操作(注意输入法不要默认是中文输入,不然会报错),如图:


注意:我的 appium 版本是 0.16.0 据说最新版本的上面会报报 EXDEV error 解决办法见:http://testerhome.com/topics/639
基于 Windows 平台上的使用 Java 语言实现 appium 自动化程序 for Android devices 的详细步骤就算是写完了 有点像记流水账 ,希望对于新手有点用。 请各位大神轻喷,我也是新手。有时间的话 在写个完整版的基于 Windows 平台上的使用 Python 语言实现 appium 自动化程序 for Android devices。

共收到 59 条回复 时间 点赞

#8 楼 @yhl_1103 *** 或者找 proxy,另外请加个头像。

我跟 14 楼一样的错。@ 楼主。

浅显易懂,楼主不错支持

写的不错啊,补充下,

npm install -g appium

然后 appium 启动 ip 和端口 可以不用指定,使用默认就可以了。

#1 楼 @lihuazhang 我每次指定的 原来可以不指定啊 谢谢

入门神器,顶之

新手宝典

#3 楼 @eric 你们看看能通过吗 自己试试

#4 楼 @panzhigang 你们看看能通过吗 自己试试

写得很详细,学习中

感谢楼主,在参考安装,但是停留在第二步很长时间了也没安装好 appium 呢

#8 楼 @yhl_1103 可能是天朝的网络原因吧

#10 楼 @lihuazhang 我用的 goagent

#10 楼 @lihuazhang 我找了 proxy 代理,然后安装 npm install appium 但是还是报解析的错误,请帮忙看看,谢谢!
ary-cookies":"~0.1.1"},"scripts":{"test":"grunt travis","start":"node server.js
},"devDependencies":{"mocha":"~1.8.1","should":"~1.2.1","grunt":"~0.4.0","grunt
cli":"~0.1.6","wd":"git://github.com/admc/wd.git","assert":"~0.4.9","grunt-moch
-test":"~0.2.0","difflib":"~0.2.4","prompt":"~0.2.9","grunt-contrib-jshint":"~0
1.1","saucelabs":"~0.0.7","markdown":"~0.4.0"},"contributors":[{"name":"Authors
ordered by first contribution"},{"name":"Dan Cuellar","email":"dancuellar@me.co
"},{"name":"E. James Infusino","email":"jinfusino@gmail.com"},{"name":"Jason Hu
gins","email":"hugs@saucelabs.com"},{"name":"Jason Carr","email":"jcarr@saucela
s.com"},{"name":"Jayme Deffenbaugh","email":"jdeffenbaugh@me.com"},{"name":"Rom
n Salvador","email":"roman.salvador@gmail.com"},{"name":"Luke Inman-Semerau","e
ail":"luke.semerau@gmail.com"},{"name":"Pradeep Bishnoi","email":"pradeepbishno
@gmail.com"},{"name":"Charles Nowacek","email":"charlie.nowacek@gmail.com"},{"n
me":"Jayakumar Chinnappan","email":"jayakumareee21@gmail.com"},{"name":"Robin K
ller","email":"robinthekeller@gmail.com"},{"name":"Adam Christian","email":"ada
.christian@gmail.com"},{"name":"Jonathan Lipps","email":"jlipps@gmail.com"},{"n
me":"Sebastian Tiedtke","email":"sebastiantiedtke@gmail.com"},{"name":"Jeremy A
net"},{"name":"Bernard Kobos","email":"bkobos@extensa.pl"},{"name":"Santiago Su
rez Ordoñez","email":"santiycr@gmail.com"},{"name":"Joe Mathes"}],"_id":"appium
0.2.3","dist":{"shasum":"d1e63e4e179547df067883df4b2049856f66130d","tarball":"h
tp://registry.npmjs.org/appium/-/appium-0.2.3.tgz"},"_npmVersion":"1.2.0","_npm
ser":{"name":"jlipps","email":"jlipps@gmail.com"},"maintainers":[{"name":"admc"
"email":"adam.christian@gmail.com"},{"name":"sourishkrout","email":"sebastianti
dtke@gmail.com"},{"name":"jlipps","email":"jlipps@gmail.com"}]},"0.3.0":{"name"
"appium","description":"Automation for Apps.","tags":["automation","javascript"
,"version":"0.3.0","author":{"name":"appium-discuss@googlegroups.com"},"reposit
ry":{"type":"git","url":"https://github.com/appium/appium.git,"bugs":{"url":"}"
ttps://github.com/appium/appium/issues"},"engines":["node"],"main":"./server.js
,"bin":{"appium":"./app/bin.js","instruments_client":"./instruments/client_bin.
s"},"directories":{"lib":"./app"},"dependencies":{"underscore":"~1.4.3","colors
:"~0.6.0-1","express":"~3.0.6","argparse":"~0.1.10","path":"~0.4.9","rimraf":"~
.1.1","uuid-js":"~0.7.4","temp":"~0.5.0","winston":"~0.6.2","request":"~2.12.0"
"bplist-parser":"~0.0.4","bufferpack":"0.0.6","node-bplist-creator":"~0.0.1","n
de-uuid":"~1.4.0","underscore.string":"~2.3.1","glob":"~3.1.20","unzip":"~0.1.1
,"ncp":"~0.4.2","swig":"~0.13.5","async":"~0.2.6","mkdirp":"~0.3.5","binary-coo
ies":"~0.1.1"},"scripts":{"test":"grunt travis","start":"node server.js"},"devD
pendencies":{"mocha":"~1.8.1","should":"~1.2.1","grunt":"~0.4.0","grunt-cli":"~
.1.6","wd":"git://github.com/admc/wd.git","assert":"~0.4.9","grunt-mocha-test":
~0.2.0","difflib":"~0.2.4","prompt":"~0.2.9","grunt-contrib-jshint":"~0.1.1","s
ucelabs":"~0.0.7","namp":"~0.2.25"},"contributors":[{"name":"Authors ordered by
first contribution"},{"name":"Dan Cuellar","email":"dancuellar@me.com"},{"name"
"E. James Infusino","email":"jinfusino@gmail.com"},{"name":"Jason Huggins","ema
l":"hugs@saucelabs.com"},{"name":"Jason Carr","email":"jcarr@saucelabs.com"},{"
ame":"Jayme Deffenbaugh","email":"jdeffenbaugh@me.com"},{"name":"Roman Salvador
,"email":"roman.salvador@gmail.com"},{"name":"Luke Inman-Semerau","email":"luke
semerau@gmail.com"},{"name":"Pradeep Bishnoi","email
npm ERR! at Object.parse (native)
npm ERR! at RegClient. (C:\Program Files\nodejs\node_modules\npm
node_modules\npm-registry-client\lib\request.js:203:23)
npm ERR! at Request.self.callback (C:\Program Files\nodejs\node_modules\npm
node_modules\request\request.js:123:22)
npm ERR! at Request.EventEmitter.emit (events.js:98:17)
npm ERR! at Request. (C:\Program Files\nodejs\node_modules\npm\n
de_modules\request\request.js:893:14)
npm ERR! at Request.EventEmitter.emit (events.js:117:20)
npm ERR! at IncomingMessage. (C:\Program Files\nodejs\node_modul
s\npm\node_modules\request\request.js:844:12)
npm ERR! at IncomingMessage.EventEmitter.emit (events.js:117:20)
npm ERR! at _stream_readable.js:920:16
npm ERR! at process._tickCallback (node.js:415:13)
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/npm/npm/issues

npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\no
ejs\node_modules\npm\bin\npm-cli.js" "install" "appium"
npm ERR! cwd C:\Users\cylboy
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! type unexpected_eos
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\cylboy\npm-debug.log
npm ERR! not ok code 0

ANT MAVEN Git ,一定要安装吗?装了有什么作用?

#14 楼 @cylboy @yhl_1103 http://testerhome.com/topics/653
@bestfei 试试看呗,肯定会提示你要安装的。 至于什么用, ANT 是 android 需要的, maven 是 sample code 里面的构建环境, git 有些代码是在 github 上的,没有 git 拉不下来啊。

已经试验成功,楼主写的很棒

按照楼主的教程,只过没有安装 git,是把代码拷贝过来的,为什么报 Failed to launch test

我装完 ant 和 aven,也按照 npm 的命令装好了 appium,但是 appium-doctor 的命令就是提示 appium 不是系统命令,怎么回事啊?

#20 楼 @blue_momo2009 很显然 win 没有找到你安装的 appium 路径(与你装不装 ant,maven 的没没关系,你只要确定你 appium 装好的就 OK),最简单的办法,按 win 键,在搜索框中输入 “appium” 好,你会看到一个 cmd 文件 “appium-doctor”(该文件是 appium 自检其环境配置的文件默认是在/node——modules/.bin)右键 “打开文件位置”,好了打开后你应该就看见了你要的,与他同级目录的 “appium.cmd”,把这个文件的路径 copy 到你系统环境变量 PATH 中保存,再重新打开命令行输入"appium",搞定~!
你应该用的是图片中显示的命令 npm install appium 但是最好用 npm install -g appium,-g 应该是全局配置,总之根源给你找到了。

@softblank 多谢,我已经弄好了。还想问下,如果我连接的是模拟器呢?没有 udid 怎么办

@blue_momo2009 windows 我知识配置了下 appium 的环境,没有做 demo 的相关尝试,但是你的应该是 android,android 模拟器正确启动后 AVD 一会有 id 的你在 cmd 下运行 “adb devices” 就会得到
“List of devices attached
emulator-5554 device”
同样你的 native 控件也是可以用 hierarchy View 查看,模拟器默认 USB debug 模式是开的,但是模拟器延迟是硬伤:-)

试过了,模拟器就直接命令 appium 就行了,ip 是 0.0.0.0,端口还是 4723

textFieldsList.get(0).sendKeys("Alice");
这里的 get(index) 的 index 是通过 hierarchyview 查看的 index 吗?那名字不应该是 3 吗?

搞通了 下的最新版的 selsenium。。。找不到 jar 包了

老大我所有的都是你的来 但是就是出错了
Opens the new class wizard to create the type.
import org.openqa.selenium.interactions.HasTouchScreen;各种报错

org.openqa.selenium.interactions 这个库全报错

搞出来了 但是刚到 List textFieldsList = driver.findElements(By.tagName("textfield")); 就出错了 ,根本不知道什么原因
也不往下输入文字了

List确定可以么?

你好,请教一下楼主,为什么要同时下载安装 setuptools 和 pip,这两个都是 python 中的包管理工具?安装 pip 并不需要安装 setuptools 吧?

匿名 #32 · 2014年08月17日

mark 学习!

楼主,我启动 appium,使用命令 appium -a127.0.0.1 -p4723 -U15C3E100811FB0500_MTPADB 时,提示找不到.appiumconfig.json 文件,这个文件该怎么生成呢?麻烦指导一下。

不错,已经运行成功了。 我看到你代码里面有添加了一个联系人号码(wangfang),为什么我打开手机通讯录没找到呢?

File app = new File(appDir, "ContactManager.apk");

app 设置是必须的吗?如果测试已经安装好的应用?

输入命令 appium -a127.0.0.1 -p4723 -U10d598f5 后,结果跟楼主的不一样,请问是什么原因啊?

info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"udid":"10d598f5","address":"127.0.0.1"}
info: Console LogLevel: debug

#36 楼 @lfxx 我也是这个这个提示,麻烦问下,你现在是咋个处理的呢

@lfxx@ harryguo 我也遇到这个问题了 请问你们是怎么解决的呀

我也是这个问题,请问大家是怎么解决的?

#29 楼 @duanxu3 "List textFieldsList = driver.findElements(By.tagName("textfield")); " 这个问题你解决了吗 ? 求解决办法呀,我也是呢 ,直接闪回主菜单了

#37 楼 @harryguo @ purely 没解决 现在还这样

#38 楼 @purely 没解决 现在还这样

相同代码 public void addContact(){

System.out.println(driver);
WebElement el = driver.findElement(By.id("addContactButton"));

el.click();

List textFieldsList = driver.findElements(By.tagName("textfield"));

textFieldsList.get(0).sendKeys("Some Name");

textFieldsList.get(2).sendKeys("Some@example.com");

driver.findElement(By.name("Save")).click();

加了句 System.out.println(driver); 打印出来 driver 为 NULL 报空指针 为什么 driver 数 NULL 啊

本地访问http://127.0.0.1:4723/wd/hub 也访问不了


这样子是 appium 服务启动成功了吗?


运行后,提示没有网络权限。按照提示添加语句了,还是不成功,怎么解决呢?

同学好!请教一下自建 selenium 库 结构内容是什么

我运行了 appium-doctor 显示结果有错误: ADB could not be found at F:\Android\android-sdk\platform-tools\adb.exe
肿么破

博主知不知道怎么在 linux 下获得设备的 udid, 表示在 linux 下使用 adb devices -l 得到的那一串标志在执行 appium 的时候会有提示"Non-default server args: {"udid":"c0fdc417"}"

我运行了后,appium log 显示没有成功进入 apk 所在路径
error:Faild to start an Appium session,err was:Error: Bad app:D:/AndroidProjects\Appium-demo\apps\ContactManager.apk.App paths need to be absolute, or relative to the appium server install dir,or a URL to compressed file,or special app name.cause:Error:Error locating the app ENOENT,
楼主帮忙看看可能是什么地方导致?

你好!我按照你写的步骤成功安装了 appium,但是在运行 ContactManager 的测试时出现了报错。按照报错应该是 deviceName 和 platformName 写错了。可是我也是用真机运行的啊,电脑是 windows 的。后来把 platformName 改成 Android 也不行

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not determine your device from Appium arguments or desired capabilities. Please make sure to specify the 'deviceName' and 'platformName' capabilities)

#47 楼 @leticia 那是不是你的 Android 的 sdk 配置有问题啊?

楼主,你好,我现在无法下载 “这块我主要是执行的是官方的演示代码:通讯录管理 app,安装打开 app,并添加一个联系人保存的操作
1)首先去下载 ContactManager.apk(http://yunpan.cn/QInSWzP2YWgTJEclipseapps 文件夹下),等会放在”工作目录的 该如何操作呀

#52 楼 @qm_sungirl 下载链接有问题啊,可以直接去官网下 https://github.com/appium/sample-code

#47 楼 @leticia adb 路径有问题

@cuijinxin ContactMangerTest
studyBao.ContactMangerTest
addContact(studyBao.ContactMangerTest)
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 148 milliseconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'PC-TEST', ip: '192.168.3.254', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_111'
Driver info: studyBao.ContactMangerTest$SwipeableWebDriver

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)

at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)

at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)

at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)

at studyBao.ContactMangerTest$SwipeableWebDriver.(ContactMangerTest.java:60)

at studyBao.ContactMangerTest.setUp(ContactMangerTest.java:37)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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 studyBao.ContactMangerTest.tearDown(ContactMangerTest.java:42)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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)

我的是什么问题啊

给位前辈,如果 app 有 loading 页会不会影响测试?我测试手机自带应用都能通过,但是遇到有加载页的应用,就会报错,错误说无法定位元素,我想会不会是这个原因呢?求解~ 谢谢


跟老师的不一样,如何破

上面提到的不能输入联系人,电话,邮箱的问题,用 Uiautomator Viewer 查看三个 editText 的 className 相同,改成 List textFieldsList = driver.findElements(By.className("android.widget.EditText")); 就可以了。

jessens 回复

我也遇到了这个情况,请问现在有解决吗

有些朋友反应在 cmd 下运行 npm 无效,如果这样请把 nodejs 的目录添加到用户变量的 path 下即可 参考帖子:http://blog.csdn.net/iispring/article/details/8023319

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