我先描述下我的环境:Appium win7 java
测试的设备是:android 2.3
我遇到的问题是:测试用例仅执行到点击登陆按钮,appium 不会有任何问题。若我在登陆后进行登出测试,则 appium 报错。
报错信息如下:
info: [debug] Selendroid server is alive!
info: [debug] Listening for Selendroid logs
info: [debug] Creating Selendroid session
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session","method":
"POST","json":{"desiredCapabilities":{"warnings":{},"desired":{"automationName":"Selendroid","platfo
rmVersion":"2.3","platform":"WINDOWS","app":"E:\\zhijin_work\\helloAppium\\apps\\EnjoyLearning1.1.ap
k","deviceName":"device","platformName":"Android","appActivity":"com.zj.learning.control.common.Logi
nActivity","udid":"7DF000029EDC0000","appPackage":"com.zj.learning"},"automationName":"Selendroid","
platformVersion":"2.3","platform":"WINDOWS","app":"E:\\zhijin_work\\helloAppium\\apps\\EnjoyLearning
1.1.apk","deviceName":"device","platformName":"Android","appActivity":"com.zj.learning.control.commo
n.LoginActivity","udid":"7DF000029EDC0000","appPackage":"com.zj.learning"}}}
info: [debug] Successfully started selendroid session
info: [debug] Waiting for pkg "com.zj.learning" and activity "com.zj.learning.control.common.LoginAc
tivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s 7DF000029EDC0000 shell
"dumpsys window windows"
info: [debug] Overriding session id with "c4de4f22-11a9-2e40-a85d-19226e1708e1"
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId c4de4f22-11a9-2e40-a85d-19226e1708e1
info: <-- POST /wd/hub/session 303 11351.597 ms - 74
info: --> GET /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1 {}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1","method":"GET"}
info: [debug] Proxied response received with status 200: {"value":{"automationName":"selendroid","pl
atform":"android","app":"E:\\zhijin_work\\helloAppium\\apps\\EnjoyLearning1.1.apk","acceptSslCerts":
true,"javascriptEnabled":true,"browserName":"selendroid","appActivity":"com.zj.learning.control.comm
on.LoginActivity","networkConnectionEnabled":true,"rotatable":true,"desired":{"automationName":"Sele
ndroid","platformVersion":"2.3","platform":"WINDOWS","app":"E:\\zhijin_work\\helloAppium\\apps\\Enjo
yLearning1.1.apk","deviceName":"device","platformName":"Android","appActivity":"com.zj.learning.cont
rol.common.LoginActivity","udid":"7DF000029EDC0000","appPackage":"com.zj.learning"},"udid":"7DF00002
9EDC0000","appPackage":"com.zj.learning","version":"0.15.0","platformVersion":"10","deviceName":"dev
ice","platformName":"android","handlesAlerts":true,"warnings":{},"takesScreenshot":true},"status":0,
"sessionId":"c4de4f22-11a9-2e40-a85d-19226e1708e1"}
info: <-- GET /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1 200 68.239 ms - 894
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element {"using":"id","value":"u
ser_login_et_username"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element","method":"POST","json":{"using":"id","value":"user_login_et_username"}}
info: [debug] Proxied response received with status 200: {"value":{"ELEMENT":"5abcadb8-ff9f-5c63-544
a-9a48679db40b"},"status":0,"sessionId":"c4de4f22-11a9-2e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element 200 41.441 ms - 122
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/5abcadb8-ff9f-5c63-544a-
9a48679db40b/value {"id":"5abcadb8-ff9f-5c63-544a-9a48679db40b","value":["wangliting1220"]}
info: [debug] Setting text on element '5abcadb8-ff9f-5c63-544a-9a48679db40b': 'wangliting1220'
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element/5abcadb8-ff9f-5c63-544a-9a48679db40b/value","method":"POST","json
":{"value":["wangliting1220"]}}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"c4de4f22-11a9-2
e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/5abcadb8-ff9f-5c63-544a-
9a48679db40b/value 200 1124.484 ms - 74 {"status":0,"value":"","sessionId":"c4de4f22-11a9-2e40-a85d-
19226e1708e1"}
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element {"using":"id","value":"u
ser_login_et_pswd"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element","method":"POST","json":{"using":"id","value":"user_login_et_pswd
"}}
info: [debug] Proxied response received with status 200: {"value":{"ELEMENT":"51aca496-7e10-eb03-175
0-fdb0a85799cf"},"status":0,"sessionId":"c4de4f22-11a9-2e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element 200 43.543 ms - 122
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/51aca496-7e10-eb03-1750-
fdb0a85799cf/value {"id":"51aca496-7e10-eb03-1750-fdb0a85799cf","value":["ting931220"]}
info: [debug] Setting text on element '51aca496-7e10-eb03-1750-fdb0a85799cf': 'ting931220'
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element/51aca496-7e10-eb03-1750-fdb0a85799cf/value","method":"POST","json
":{"value":["ting931220"]}}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"c4de4f22-11a9-2
e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/51aca496-7e10-eb03-1750-
fdb0a85799cf/value 200 1322.564 ms - 74 {"status":0,"value":"","sessionId":"c4de4f22-11a9-2e40-a85d-
19226e1708e1"}
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/appium/device/hide_keyboard {}
info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s 7DF000029EDC0000 shell
"dumpsys input_method"
info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s 7DF000029EDC0000 shell
"input keyevent 4"
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c4de4f22-11a9
-2e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/appium/device/hide_keyboard 200
640.266 ms - 76 {"status":0,"value":null,"sessionId":"c4de4f22-11a9-2e40-a85d-19226e1708e1"}
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element {"using":"id","value":"u
ser_login_btn_login"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element","method":"POST","json":{"using":"id","value":"user_login_btn_log
in"}}
info: [debug] Proxied response received with status 200: {"value":{"ELEMENT":"d52e653d-2282-434b-c9d
f-4ab8fcf9337d"},"status":0,"sessionId":"c4de4f22-11a9-2e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element 200 44.301 ms - 122
info: --> POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/d52e653d-2282-434b-c9df-
4ab8fcf9337d/click {"id":"d52e653d-2282-434b-c9df-4ab8fcf9337d"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/c4de4f22-1
1a9-2e40-a85d-19226e1708e1/element/d52e653d-2282-434b-c9df-4ab8fcf9337d/click","method":"POST","json
":{"id":"d52e653d-2282-434b-c9df-4ab8fcf9337d"}}
info: [debug] Proxied response received with status 200: {"value":"","status":0,"sessionId":"c4de4f2
2-11a9-2e40-a85d-19226e1708e1"}
info: <-- POST /wd/hub/session/c4de4f22-11a9-2e40-a85d-19226e1708e1/element/d52e653d-2282-434b-c9df-
4ab8fcf9337d/click 200 679.751 ms - 74
info: [debug] [SELENDROID ERR] com.zj.learning.model.forum.Tag
info: [debug] [SELENDROID ERR] at java.lang.Class.classForName(Native Method)
info: [debug] [SELENDROID ERR] at java.lang.Class.forName(Class.java:234)
info: [debug] [SELENDROID ERR] at java.lang.Class.forName(Class.java:181)
info: [debug] [SELENDROID ERR] at com.zj.support.dao.b.a(Unknown Source)
info: [debug] [SELENDROID ERR] at com.zj.support.dao.a.onCreate(Unknown Source)
info: [debug] [SELENDROID ERR] at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLi
teOpenHelper.java:126)
info: [debug] [SELENDROID ERR] at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLi`
teOpenHelper.java:187)
info: [debug] [SELENDROID ERR] at com.zj.support.dao.c.a(Unknown Source)
info: [debug] [SELENDROID ERR] at com.zj.support.a.a.a(Unknown Source)
info: [debug] [SELENDROID ERR] at com.zj.support.a.b.a(Unknown Source)
info: [debug] [SELENDROID ERR] at com.zj.support.a.b.doInBackground(Unknown Source)
info: [debug] [SELENDROID ERR] at android.os.AsyncTask$2.call(AsyncTask.java:185)
info: [debug] [SELENDROID ERR] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306
)
info: [debug] [SELENDROID ERR] at java.util.concurrent.FutureTask.run(FutureTask.java:138)
info: [debug] [SELENDROID ERR] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecu
tor.java:1088)
info: [debug] [SELENDROID ERR] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExec
utor.java:581)
info: [debug] [SELENDROID ERR] at java.lang.Thread.run(Thread.java:1019)
info: [debug] [SELENDROID ERR] com.zj.learning.model.forum.Tag
info: [debug] [SELENDROID ERR] ... 17 more
info: [debug] [SELENDROID ERR] com.zj.learning.model.forum.Tag in loader dalvik.system.PathClassLoad
er[/system/framework/android.test.runner.jar:/data/app/com.zj.learning.selendroid-1.apk:/data/app/co
m.zj.learning-1.apk]
info: [debug] [SELENDROID ERR] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
info: [debug] [SELENDROID ERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
info: [debug] [SELENDROID ERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
info: [debug] [SELENDROID ERR] ... 17 more
info: [debug] [SELENDROID] encode = 1
我具体描述一下我的情况:
若我只执行下面的代码,则能正常通过。
public void login() throws InterruptedException {
driver.findElement(By.id("user_login_et_username")).sendKeys(
"wangg1220");
driver.findElement(By.id("user_login_et_pswd")).sendKeys("ting930");
driver.hideKeyboard();
driver.findElement(By.id("user_login_btn_login")).click();
}
而当我执行下面的代码时,则会提示如上错误。
@Test
public void login() throws InterruptedException {
driver.findElement(By.id("user_login_et_username")).sendKeys(
"wangg1220");
driver.findElement(By.id("user_login_et_pswd")).sendKeys("ting930");
driver.hideKeyboard();
driver.findElement(By.id("user_login_btn_login")).click();
Thread.sleep(60000);
loout();
}
public void loout() throws InterruptedException {
String cuString = driver.currentActivity();
System.out.println("cuString" + cuString);
driver.findElement(By.id("main_rbtn_course_me")).click();//
// 找到“我的”id進行点击
driver.swipe(75, 50, 75, 200, 2);//
driver.findElement(By.id("user_exit_btn")).click();
}
我现在不清楚到底是我代码写的有问题还是开发的代码问题。
这个 apk 是开发打包给我的,我正常安装使用不会有任何问题,但当我通过代码安装时,就会出现上面的错误。
请大神指教!