#1 楼 @lihuazhang 做 rom 的公司会意识到这个工具,其实做工具的,不管是针对 app 还是 rom,应该都能从中找到有用的东西。
xml 文件用什么打开的,怎么是那样?
#4 楼 @mistyrain 我们采用的是利用 hierarchyviewer 来查看 id 的方式做的,因为 uiautomatorviewer 会报错,但是只要你能定位该控件,在 uiautomator 脚本中一样会执行成功,但是会等待 10 秒钟的时间。你需要耐心,不要急于达到你想要的结果。慢慢研究 uiautomator 的源码以及 api 对你会很有帮助的。
针对你第二个问题:
uiautomatorviewer 无法捕捉动态界面。可以看看下面 2 篇博客:
获取不到动态界面
获取不到动态界面的原因
#12 楼 @seveniruby 就是希望能有点用。以后会分享更多
加油!
#6 楼 @seveniruby 我是新人。
#5 楼 @yangchengtest 莫膜拜,大家都动起来,为 testerhome 做点事。
进百度,然后安心下来研究技术
分析 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
#10 楼 @lihuazhang
adb shell am start -n 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 }
Warning: Activity not started, its current task has been brought to the front
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>
#8 楼 @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();
}
}
不是获得我启动的那个 apk 么?
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"}
#1 楼 @lihuazhang
ecilpse 中用 java 调用 appiumDriver 的这个方法运行然后报错。