如何识别来自 Sencha Touch App 的 UI 元素以使用 Appium 进行测试?
How to identify UI Elements from Sencha Touch App for Testing with Appium?
我在使用此 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!
[...]
由于您的应用是在 Cordova 上构建的,因此只是一个试用,请在 Chrome/Safari 上使用检查设备检查元素 primary-login-container-new-account-button
。在您能够访问它之前,您必须在检查时找到一些属性,例如 css
或 class
。
话虽如此,如果您能够使用 Chrome/Safari 检查它们,那么您正在查看一个 webview,您必须将其上下文切换到 Webview 才能访问此处的元素。
由于元素是由 Sencha 动态生成的,因此这些属性也可能被分配了一些 random key-value
。在这种情况下,您必须指定生成的值才能访问您的视图元素。
Note : It would be great to look at a screenshot of Chrome Inspected
elements on the view from your application along with the Appium Inspector
screenshot corresponding to the same.
我在使用此 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!
[...]
由于您的应用是在 Cordova 上构建的,因此只是一个试用,请在 Chrome/Safari 上使用检查设备检查元素 primary-login-container-new-account-button
。在您能够访问它之前,您必须在检查时找到一些属性,例如 css
或 class
。
话虽如此,如果您能够使用 Chrome/Safari 检查它们,那么您正在查看一个 webview,您必须将其上下文切换到 Webview 才能访问此处的元素。
由于元素是由 Sencha 动态生成的,因此这些属性也可能被分配了一些 random key-value
。在这种情况下,您必须指定生成的值才能访问您的视图元素。
Note : It would be great to look at a screenshot of
Chrome Inspected
elements on the view from your application along with theAppium Inspector
screenshot corresponding to the same.