Appium AppiumDriver.getAppStrings()

易寒 · 2014年07月16日 · 最后由 恒温 回复于 2014年07月16日 · 2545 次阅读

调用该方法出现如下错误:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command

望知道的人吼一嗓子

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 14 条回复 时间 点赞

请详细描述,发 bug 也这么发么?

#1 楼 @lihuazhang
ecilpse 中用 java 调用 appiumDriver 的这个方法运行然后报错。

#1 楼 @lihuazhang

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 上也没有,就报错了。

#4 楼 @lihuazhang

不是获得我启动的那个 apk 么?

#5 楼 @doctorq 把代码贴上来好么, 我说了,就算是报 bug,也要上下文都齐全啊。谁能只看个异常就知道你哪里出错啊

#6 楼 @lihuazhang

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
装了,且已经启动成功进入主界面。

#8 楼 @lihuazhang

adb shell am start -n com.sina.weibopro.ui.HomeActivity

试试看 这个命令 有结果么?

易寒 #11 · 2014年07月16日 Author

#10 楼 @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>

易寒 #12 · 2014年07月16日 Author

#10 楼 @lihuazhang

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

易寒 #13 · 2014年07月16日 Author

#10 楼 @lihuazhang
adb shell am start -n com.sina.weibopro/.ui.HomeActivity
启动成功

易寒 #14 · 2014年07月17日 Author

分析 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

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