Android 如何使用appium编写用于显示应用程序页面的测试用例?
我想自动化基于jquery mobile的android应用程序。现在我使用appium框架进行测试。我已成功安装,可以使用appium在移动设备上打开应用程序。现在我想编写测试用例来检查当前页面。但是我找不到选择器元素。我尝试过各种解决方案,但都失败了。这是我的剧本Android 如何使用appium编写用于显示应用程序页面的测试用例?,android,node.js,testing,jquery-mobile,appium,Android,Node.js,Testing,Jquery Mobile,Appium,我想自动化基于jquery mobile的android应用程序。现在我使用appium框架进行测试。我已成功安装,可以使用appium在移动设备上打开应用程序。现在我想编写测试用例来检查当前页面。但是我找不到选择器元素。我尝试过各种解决方案,但都失败了。这是我的剧本 "use strict"; require("./helpers/setup"); var wd = require("wd"), _ = require('underscore'),
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("android simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.npm_package_config_sauce ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = process.env.npm_package_config_sauce ?
_.clone(require("./helpers/caps").android18) :
_.clone(require("./helpers/caps").android19);
desired.app = require("./helpers/apps").androidApiCsm;
if (process.env.npm_package_config_sauce) {
desired.name = 'android - simple';
desired.tags = ['sample'];
}
return driver
.init(desired)
.setImplicitWaitTimeout(5000)
.contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"]
driver.context(contexts[1]); // choose the webview context
});
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.npm_package_config_sauce) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should find an elment and click on the button ",function(){
return driver.getCurrentActivity(
function(err,element){
console.log("using xpath err: ", err);
console.log("using xpath element: ", element);
});
return driver.elementByAccessibilityId('LoginForm',
function(err,element){
console.log("using xpath err: ", err);
console.log("using xpath element: ", element);
});
});
});
结果如下。
npm运行android csm
android simple
> CALL init({"browserName":"","appium-version":"1.3","platformName":"Android","platformVersion":"4.4.2","deviceName":"Android Emulator","app":"http://localhost/mobileandroid-debug.apk"})
> POST /session {"desiredCapabilities":{"browserName":"","appium-version":"1.3","platformName":"Android","platformVersion":"4.4.2","deviceName":"Android Emulator","app":"http://localhost/mobileandroid-debug.apk"}}
Driving the web on session: 9bc4f487-6c3c-4896-b530-e61583e972bc
> RESPONSE setImplicitWaitTimeout(5000)
> CALL contexts()
> GET /session/:sessionID/contexts
> RESPONSE contexts() ["NATIVE_APP","WEBVIEW_com....."]
> CALL context("WEBVIEW_com.....")
> POST /session/:sessionID/context {"name":"WEBVIEW_com....."}
✓ should able to context switch
> CALL elementByAccessibilityId("LoginForm")
> POST /session/:sessionID/element {"using":"accessibility id","value":"LoginForm"}
> RESPONSE context("WEBVIEW_com....")
using xpath err: {"message":"[elementByAccessibilityId(\"LoginForm\")] 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.","status":7,"cause":{"status":7,"value":{"message":"An element could not be located on the page using the given search parameters."},"sessionId":"9bc4f487-6c3c-4896-b530-e61583e972bc"},"jsonwire-error":{"status":7,"summary":"NoS...
using xpath element: undefined
1) should find an elment and click on the button
1 failing
1) android simple should find an elment and click on the button :
Error: [elementByAccessibilityId("LoginForm")] 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.
at exports.newError (node_modules/wd/lib/utils.js:139:13)
at node_modules/wd/lib/callbacks.js:75:19
at node_modules/wd/lib/webdriver.js:174:5
at Request._callback (node_modules/wd/lib/http-utils.js:87:7)
at Request.self.callback (node_modules/request/request.js:368:22)
at Request.<anonymous> (node_modules/request/request.js:1219:14)
at IncomingMessage.<anonymous> (node_modules/request/request.js:1167:12)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
android simple
>调用init({“browserName”:“,“appium版本”:“1.3”,“platformName”:“Android”,“platformVersion”:“4.4.2”,“deviceName”:“Android仿真器”,“应用程序”:”http://localhost/mobileandroid-debug.apk"})
>后期/会话{“desiredCapabilities”:{“browserName”:“appium版本”:“1.3”,“platformName”:“Android”,“platformVersion”:“4.4.2”,“deviceName”:“Android仿真器”,“应用程序”:http://localhost/mobileandroid-debug.apk"}}
在会话中驱动web:9bc4f487-6c3c-4896-b530-e61583e972bc
>响应setImplicitWaitTimeout(5000)
>调用上下文()
>GET/session/:sessionID/context
>响应上下文()
>调用上下文(“WEBVIEW_com…”)
>POST/session/:sessionID/context{“name”:“WEBVIEW_com…”
✓ 应该能够切换上下文
>CALL elementByAccessibilityId(“LoginForm”)
>POST/session/:sessionID/element{“使用”:“可访问性id”,“值”:“LoginForm”}
>响应上下文(“WEBVIEW_com…”)
使用xpath错误:{“message”:“[elementByAccessibilityId(\“LoginForm\”)错误响应状态:7,NoTouchElement-无法使用给定的搜索参数在页面上定位元素。Selenium错误:无法使用给定的搜索参数在页面上定位元素。”,“状态”:7,“原因”:“{”状态:7,“值”:{“message”:“无法使用给定的搜索参数在页面上找到元素。”},“sessionId”:“9bc4f487-6c3c-4896-b530-e61583e972bc”},“jsonwire错误”:{“状态”:7,“摘要”:“编号…”。。。
使用xpath元素:未定义
1) 应该找到一个elment并点击按钮
1失败
1) android simple应找到一个elment并单击按钮:
错误:[elementByAccessibilityId(“LoginForm”)]错误响应状态:7,NoTouchElement-无法使用给定的搜索参数在页面上找到元素。Selenium错误:无法使用给定的搜索参数在页面上找到元素。
在exports.newError(node_modules/wd/lib/utils.js:139:13)
在节点_modules/wd/lib/callbacks.js:75:19
在节点_modules/wd/lib/webdriver.js:174:5
在请求时。\回调(节点\模块/wd/lib/httputils.js:87:7)
at Request.self.callback(node_modules/Request/Request.js:368:22)
请求时。(node_modules/Request/Request.js:1219:14)
输入消息时。(node_modules/request/request.js:1167:12)
在endReadableNT(_stream_readable.js:926:12)
at _combinedTickCallback(内部/流程/下一步_tick.js:74:11)
在进程中。_tick回调(内部/process/next_tick.js:98:9)