调用该方法出现如下错误:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command
望知道的人吼一嗓子
请详细描述,发 bug 也这么发么?
#1 楼 @lihuazhang
ecilpse 中用 java 调用 appiumDriver 的这个方法运行然后报错。
appium 控制台输出如下:
debug: Appium request initiated at /wd/hub/session/e64576a0-d47b-449b-909a-5ba62
be6ed92/appium/app/strings
debug: Request received with params: {}
debug: Apk doesn't exist locally
debug: executing: "D:\android\sdk\platform-tools\adb.exe" -s 16442209010961 shel
l "rm -rf /data/local/tmp/strings.json"
debug: Pushing command to appium work queue: ["updateStrings",{}]
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"updat
eStrings","params":{}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: updateStrings
debug: [BOOTSTRAP] [debug] Loading json...
debug: [BOOTSTRAP] [debug] Returning result: {"value":"Unable to load json file
and update strings.","status":13}
debug: Responding to client with error: {"status":13,"value":{"message":"An unkn
own server-side error occurred while processing the command.","origValue":"Unabl
e to load json file and update strings."},"sessionId":"e64576a0-d47b-449b-909a-5
ba62be6ed92"}
你的 apk 不存在本地,device 上也没有,就报错了。
不是获得我启动的那个 apk 么?
package com.saucelabs.appium;
import io.appium.java_client.AppiumDriver;
import java.net.URL;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.google.gson.JsonParser;
public class SettingTest {
private AppiumDriver driver;
private static final String url = "http://127.0.0.1:4723/wd/hub";
private static final HttpClient client = HttpClients.createDefault();
private static final JsonParser parser = new JsonParser();
@Test
public void qian() throws Exception {
// driver.findElement(By.id("com.sina.weibopro:id/tv_lgoin")).click();
// driver.closeApp();
// driver.lockScreen(3);
// driver.findElement(By.id("com.sina.weibopro:id/etLoginUsername")).sendKeys(
// "appiot@163.com");
// driver.findElement(By.id("com.sina.weibopro:id/etPwd")).sendKeys(
// "appiotappiot");
// driver.findElement(By.id("com.sina.weibopro:id/btn_login")).click();
// final String activity = driver.currentActivity();
// System.out.println(activity);
// driver.sendKeyEvent(AndroidKeyCode.BACK,
// AndroidKeyMetastate.META_ALT_LEFT_ON);
// driver.resetApp();
// driver.findElement(By.id("com.sina.weibopro:id/rl_weibo"));
Thread.sleep(10000);
System.out.println(driver.getAppStrings());
// final File classpathRoot = new File(System.getProperty("user.dir"));
// final File appDir = new File(classpathRoot,
// "../../../apps/ContactManager");
// final File app = new File(appDir, "ContactManager.apk");
// driver.installApp(app.getAbsolutePath());
// driver.runAppInBackground(5);
// System.out.println("start swipe");
// driver.swipe(75, 500, 75, 0, 800);
// driver.removeApp("com.sohu.newsclient");
}
@Before
public void setUp() throws Exception {
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("appPackage", "com.sina.weibopro");
capabilities.setCapability("appActivity", ".ui.HomeActivity");
driver = new AppiumDriver(new URL(url), capabilities);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
capabilities.setCapability("appPackage", "com.sina.weibopro");
capabilities.setCapability("appActivity", ".ui.HomeActivity");
这两个是说,你不是从本地重新安装 apk 的,你的 device 里面已经装好了。那你确认下,你的 device 里面装了 weibopro 没?
#8 楼 @lihuazhang
装了,且已经启动成功进入主界面。
Error: Bad component name: com.sina.weibopro.ui.HomeActivity
C:\Users\Administrator>adb shell am start -n com.sina.weibopro/ui.HomeActivity
Starting: Intent { cmp=com.sina.weibopro/ui.HomeActivity }
Error type 3
Error: Activity class {com.sina.weibopro/ui.HomeActivity} does not exist.
C:\Users\Administrator>adb shell am start -n com.sina.weibopro/ui.HomeActivity
Starting: Intent { cmp=com.sina.weibopro/ui.HomeActivity }
Error type 3
Error: Activity class {com.sina.weibopro/ui.HomeActivity} does not exist.
C:\Users\Administrator>
C:\Users\Administrator>adb shell am start -n com.sina.weibopro/.ui.HomeActivity
Starting: Intent { cmp=com.sina.weibopro/.ui.HomeActivity }
Warning: Activity not started, its current task has been brought to the front
#10 楼 @lihuazhang
adb shell am start -n com.sina.weibopro/.ui.HomeActivity
启动成功
分析 log 得知:
这个方法是获得 appium 事先放在手机端的临时目录里的 strings.json 文件里的数据,这个文件会在 case 初始化阶段在 PC 上解析你提供的 app 里的 strings.xml 文件,然后 push 到手机临时目录中的。所以不提供 app 路径是无法调用该方法的。
debug: java -jar "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium
\node_modules\appium-adb\jars\strings_from_apk.jar" "D:\java-client-master\src\t
est\java\io\appium\java_client\Weibo.apk" "C:\Windows\Temp\com.example.android.a
pis" zh
debug: No strings.xml for language 'zh', getting default strings.xml
debug: java -jar "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium
\node_modules\appium-adb\jars\strings_from_apk.jar" "D:\java-client-master\src\t
est\java\io\appium\java_client\Weibo.apk" "C:\Windows\Temp\com.example.android.a
pis"
debug: executing: "D:\android\sdk\platform-tools\adb.exe" -s 16442209010961 push
"C:\Windows\Temp\com.example.android.apis\strings.json" /data/local/tmp