【问题标题】:Why does a simple automation test with Appium fail?为什么使用 Appium 进行简单的自动化测试会失败?
【发布时间】:2020-07-21 22:31:21
【问题描述】:

我正在使用 React Native 开发应用程序,但在使用 Appium 框架进行自动化测试时遇到了困难。

我从未使用过该工具,我的第一个目标是检查主屏幕上是否存在以下元素。 PS:元素存在。

<TouchableOpacity
  testID="test-login"
  accessibilityLabel="test-login"
>
    <Text>test login</Text>
</TouchableOpacity>

在项目中,我使用 sample.test.js 文件创建了 test 文件夹

const webdriverio = require('webdriverio');

const androidOptions = {
  capabilities: {
    browserName: 'Chrome',
    allowInsecure: {},
    denyInsecure: {},
  },
  desiredCapabilities: {
    browserName: 'Chrome',
    path: '/wd/hub',
    port: 4723,
    platformName: 'Android',
    app:
      '/Users/xxx/android/app/build/outputs/apk/debug/app-debug.apk',
    deviceName: 'xxx', // adb devices
    automationName: 'Appium',
    appPackage: 'XXX',
    launchActivity: 'XXX.MainApplication',
    chromeOptions: {w3c: false},
    ensureWebviewsHavePages: true,
    platformVersion: '8.0.0',
  },
};

describe('things', () => {
  let client;

  before(async () => {
    client = await webdriverio.remote(androidOptions);
  });

  it('test', async () => {
    //await client.elementByAccessibilityId('test-login');
    //client.elementsByAccessibilityId('test-login');
    await client.findElementsByAccessibilityId('test-login');
    //let elementsOne = await client.elementsByAccessibilityId('test-login');
    //let elementsTwo = await client.elements('id', 'test-login');
    //await client.elementByAccessibilityId('test-login').isClickable;
  });

  after(async () => {
    return await client.deleteSession();
  });
});

并使用 node ./node_modules/.bin/mocha 运行它。

输出是

things
INFO webdriverio: Initiate new session using the devtools protocol
INFO devtools: Launch Google Chrome with flags: --disable-extensions --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-sync --metrics-recording-only --disable-default-apps --mute-audio --no-first-run --disable-hang-monitor --disable-prompt-on-repost --disable-client-side-phishing-detection --password-store=basic --use-mock-keychain --disable-component-extensions-with-background-pages --disable-breakpad --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-renderer-backgrounding --enable-features=NetworkService,NetworkServiceInProcess --disable-features=site-per-process,TranslateUI,BlinkGenPropertyTrees --window-position=0,0 --window-size=1200,900
INFO devtools: Connect Puppeteer with browser on port 51345
    1) test
    ✓ should create and destroy Android browser session
INFO devtools: COMMAND deleteSession()
INFO devtools: RESULT null

  0 passing (1s)
  1 failing

  1) things
        test:
      TypeError: client.findElementsByAccessibilityId is not a function
      at Context.it (test/sample.test.js:97:18)
      at process.topLevelDomainCallback (domain.js:126:23)

应用程序处于调试模式的安卓手机已连接到电脑。

我已经尝试过 sn-ps 但没有成功。

你能帮我迈出第一步吗?

谢谢大家。

【问题讨论】:

    标签: react-native automated-tests appium appium-android


    【解决方案1】:

    错误提示“TypeError:client.findElementsByAccessibilityId 不是函数”

    也就是说从 webdriverio.remote 返回的对象没有 findElementsByAccessibilityId 函数。

    你应该添加这样的东西:

    console.log(Object.getOwnPropertyNames(client));
    

    console.log(Object.getOwnPropertyNames(client).filter(x => typeof client[x] == 'function'));
    

    client.findElementsByAccessibilityId 调用之前查看它实际包含的内容。

    【讨论】:

    • 感谢汤姆的建议。我试过了,但不幸的是结果没有改变。
    猜你喜欢
    • 2012-07-03
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2021-08-27
    • 2014-09-28
    • 2021-05-09
    • 1970-01-01
    相关资源
    最近更新 更多