0

我正在尝试使用 CodeceptJS(它使用 Appium)来测试原生 Android 应用程序。我想使用 I.seeElement 方法来查看是否存在一个字段,但 Appium 服务器似乎只是挂起而没有错误消息。

这一步是输入电话号码,以便用户登录。在此之前我已经能够单击一个按钮,但那是因为我能够使用简单的文本标识符。

这是我写的。(I.click 方法在单击按钮时起作用。)


// in this file you can append custom step methods to 'I' object

module.exports = function() {
  return actor({

    login: function (I) {
        I.click('ALLOW');
        I.seeElement('#com.[package name removed]:id/phone');
    }

  });
}

这是错误消息:

[HTTP] --> POST /wd/hub/session/5e57e7af-ca1c-46bf-94ac-7e2f113a26fa/elements
[HTTP] {"using":"xpath","value":"//*[@resource-id='com.[package name removed]:id/phone']"}
[debug] [W3C (5e57e7af)] Calling AppiumDriver.findElements() with args: ["xpath","//*[@resource-id='com.[package name removed]:id/phone']","5e57e7af-ca1c-46bf-94ac-7e2f113a26fa"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@resource-id='com.[package name removed]:id/phone']","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@resource-id='com.[package name removed]:id/phone']","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[@resource-id='com.[package name removed]:id/phone']' using 'XPATH' with the contextId: '' multiple: true
4

2 回答 2

0

您可以使用智能选择器,例如一些动态 id 示例:

'div[id$="test"] textarea'    //ends with id test
'[id^='test']'      //start with id test

您也可以使用智能定位器,请参阅 codeceptjs 定位器

于 2019-07-18T12:37:57.523 回答
0

使用您必须看到的元素的文本。I.seeElement("~元素的文本")

于 2019-07-21T07:30:05.570 回答