【问题标题】:How to identify UI Elements from Sencha Touch App for Testing with Appium?如何从 Sencha Touch App 中识别 UI 元素以进行 Appium 测试?
【发布时间】:2016-02-06 19:49:04
【问题描述】:

我在使用此 Node.js 库的最新版本 (0.4.0) 编写客户端测试时遇到问题:https://github.com/admc/wd。我正在使用 Sencha Touch 2.4。

我可以将 selenium webdriver 连接到 Appium 应用程序 (v 1.4.13) 服务器,这反过来似乎可以在我指定的 iPhone 模拟器中正确加载我的 Sencha Touch 应用程序。我可以使用 Appium Inspector 检查元素。

但是,在编写测试时,我无法在应用的初始视图中识别任何 UI 元素。在 Sencha Architect 中,我将按钮组件 id 属性设置为 primary-login-container-new-account-button

例如,对于以下每种情况,似乎从未找到该元素。恐怕是Sencha动态生成元素是我找不到元素的原因。然而,我读过 Selenium 是用于 UI 测试 Sencha 应用程序的一个选项,所以它一定很容易实现对吧?我的项目也包含在 Cordova 中。

1.

[...]
it("should be able to click on Create New Account button1", function () {
  return driver
    .elementById('primary-login-container-new-account-button')
    .text().should.become('Create New Account');
});
// Error: [elementById("primary-login-container-new-account-button")] Error response status: 7, , NoSuchElement - An element could not be located on the page using the given search parameters. Selenium error: An element could not be located on the page using the given search parameters.

2.

it("should be able to click on Create New Account button2", function () {
  return driver
    .elementByAccessibilityId('primary-login-container-new-account-button')
    .text().should.become('Create New Account');
});
// Error: [elementByAccessibilityId("primary-login-container-new-account-button")] Error response status: 7, , NoSuchElement - An element could not be located on the page using the given search parameters. Selenium error: An element could not be located on the page using the given search parameters.

3.

it("should be able to click on Create New Account button3", function () {
  return driver
    .elementByIdOrNull('primary-login-container-new-account-button', function(err, element) {
  });
});
// returns element and err as null

4.

it("should be able to click on Create New Account button4", function () {
    return driver
      .elementByCssSelector('#primary-login-container-new-account-button')
      .text().should.become('Create New Account');
  });
// Error: [elementByCssSelector("#primary-login-container-new-account-button")] Error response status: 9, , UnknownCommand - The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. Selenium error: Invalid locator strategy: css selector

5.

it("should be able to click on Create New Account button5", function () {
  return driver
    .elementByName('createUserAccountButton')
    .text().should.become('Create New Account');
});
// Error: [elementByName("createUserAccountButton")] Error response status: 7, , NoSuchElement - An element could not be located on the page using the given search parameters. Selenium error: An element could not be located on the page using the given search parameters.

6.

 it("should be able to click on Create New Account button6", function () {
   return driver
     .waitForElementById('#primary-login-container-new-account-button', 30000)
     .text().should.become('Create New Account');
 });
 // Error: [waitForElementById("#primary-login-container-new-account-button",30000)] Element condition wasn't satisfied!
 [...]

【问题讨论】:

    标签: ios cordova selenium-webdriver sencha-touch appium


    【解决方案1】:

    由于您的应用是在 Cordova 上构建的,因此只是试用版,请使用 Chrome/Safari 上的检查设备检查元素 primary-login-container-new-account-button。在您能够访问它之前,必须在检查时找到一些属性,例如 cssclass。 话虽如此,如果您能够使用 Chrome/Safari 检查它们,则您正在查看一个 webview,您必须将其上下文切换到 Webview 才能访问此处的元素。

    由于元素是由 Sencha 动态生成的,可能这些属性也被分配了一些random key-value。在这种情况下,您必须指定生成的值才能访问您的视图元素。

    注意:看看Chrome Inspected的截图会很棒 应用程序视图上的元素以及对应的Appium Inspector 屏幕截图。

    【讨论】:

    • 如果我使用 Chrome 或 Safari 来检查元素会有什么不同吗?在 iOS 设备的 Safari 中操作要容易得多。
    • 我在 Safari 检查器的父 div 中看到了 Id。我还尝试在驱动程序初始化后从 Mocha 调用 done(),以确保在 before 块之后执行测试。我确实看到在执行第一个测试的第一行时,我的应用程序视图在模拟器中呈现。我还尝试过在无法检索任何元素的地方搜索 elementsByClassName(例如 normal-none 类)。然而,当我用 UIAnormal-none 搜索时,我没有得到错误响应,但它最终是一个空数组。我的截图在这里:imgur.com/a/PwfER
    • 好吧,您的屏幕截图中没有带有primary-login-container-new-account-button 的元素。可能将它包装在 Cordova 中是改变这种情况的原因。为了碰碰运气,您可以在同一视图上使用 XPath 访问元素,以了解您是否能够访问它们。附带说明:我相信您必须将上下文切换到 Webview 才能访问此处的元素。
    • primary-login-container-new-account-button 显示为父 div 的 id。你建议我如何将上下文切换到 Webview。单击并展开以在检查器中查看我的目标元素似乎是我唯一的选择。更正:我没有搜索 UIAnormal-none 类,而是搜索UIAnone-normal 类。
    • 调用driver.elementsByXPath('//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[5]' 似乎可行,但使用xpath 来识别此处的元素似乎不适用于编写测试。
    猜你喜欢
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    相关资源
    最近更新 更多