如何使用CodeceptJS在Appium中标识ID的字段?

时间:2019-07-17 15:40:58

标签: android xpath appium appium-android codeceptjs

我正在尝试使用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

2 个答案:

答案 0 :(得分:0)

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

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

您还可以使用智能定位器查看codeceptjs定位器

答案 1 :(得分:0)

使用文本作为必须查看的元素。 I.seeElement(“〜元素的文本”)