【问题标题】:Appium - Driver.source() showing android home page even with app on screenAppium - Driver.source() 显示 android 主页,即使屏幕上有应用程序
【发布时间】:2019-04-24 09:20:36
【问题描述】:

我是 Appium 的新手,我正在尝试让它在 react-native 应用程序上运行。我正在关注this tutorial,但我有一些问题。

我正在尝试使用accessibilityLabel="testview" 查找元素,但是当我执行代码时,我找不到该元素。所以,我输入命令console.log(await driver.source()); 来查看XML 代码。即使在模拟器上打开了应用程序,我还是从 Android 主页获取 XML 代码,但没有从我的应用程序获取代码。

我的测试代码是:

import wd from 'wd';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
const PORT = 4723;
const config = {
  platformName: 'Android',
  deviceName: 'Android Emulator',
  app: './android/app/build/outputs/apk/debug/app-debug.apk', // relative to root of project
  appPackage: 'com.example.android',
  appActivity: 'com.example.MainActivity'
};
const driver = wd.promiseChainRemote('localhost', PORT);

beforeAll(async () => {
  await driver.init(config);
  await driver.sleep(8000); // wait for app to load
})

test('appium renders', async () => {
  console.log(await driver.source());
  expect(await driver.hasElementByAccessibilityId('testview')).toBe(true);
});

有谁知道我为什么要从我的应用程序中获取此 XML 代码而不是 XML 代码?有什么配置错误吗?我正在使用 Windows、genymotion、android 模拟器和 uiautomator。

【问题讨论】:

  • 文件夹/android/app/build/outputs/apk/debug/中有app-debug.apk apk吗?您的应用是否有带有“testview”作为automationID/conten-desc 的元素?

标签: appium appium-android


【解决方案1】:

我通过更改使用的 uiautomator 版本解决了这个错误。我只是在配置中添加了一行:

const config = {
  platformName: 'Android',
  deviceName: 'Android Emulator',
  app: './android/app/build/outputs/apk/debug/app-debug.apk', // relative to root of project
  appPackage: 'com.example.android',
  appActivity: 'com.example.MainActivity'
  automationName: 'uiautomator2'
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    相关资源
    最近更新 更多