moj*_*jjj 6 android webdriver angularjs appium protractor
我(新)使用量角器来进行e2e黄瓜测试.我有一个基于angularJS的网络应用程序.我正在使用appium在真正的Android设备上远程运行测试.以下是我正在使用的版本:
windows8.1
protractor@1.3.1 (with submodule selenium-webdriver@2.43.5)
appium@1.3.0beta1
android device with 4.4.4
Run Code Online (Sandbox Code Playgroud)
我的量角器配置(摘录),对应于https://github.com/angular/protractor/blob/master/docs/browser-setup.md:
currentDeviceUDID = (...);
var appToTestURL = 'http://my.website.com:9000/app/index.html';
exports.config = {
seleniumAddress: 'http://localhost:4723/wd/hub';
chromeOnly: false,
specs: ['features/sample.feature'],
capabilities: {
browserName: 'chrome',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.4.4',
udid: currentDeviceUDID
},
baseUrl: appToTestURL
framework: 'cucumber',
cucumberOpts: {
require: 'features/stepDefinitionsSample.js',
tags: '@dev',
format: 'progress'
},
// configuring wd in onPrepare
onPrepare: function () {
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
},
allScriptsTimeout: 30000,
getPageTimeout: 30000
};
Run Code Online (Sandbox Code Playgroud)
如您所见,我已经用appium webdriver替换了量角器的webdriver url.我使用"appium&"从命令行启动appium,然后用"protactor cucumbertest.conf"运行测试
手机打开Chrome浏览器并导航到我给它的网址"browser.get(url)"
问题如下: 调用waitForAngular(),异步等待网站加载和所有打开的http请求(据我所知),在手机上没有成功执行.电话不响应呼叫,webdriver代理返回500.
对应于https://github.com/angular/protractor/issues/1358,我明白waitForAngular()函数在量角器中混合到调用中
['getCurrentUrl', 'getPageSource', 'getTitle'];
Run Code Online (Sandbox Code Playgroud)
在protractor.js文件中的waitForAngular()后面是下面的函数,它代理到手机:
functions.waitForAngular = function(selector, callback) {
var el = document.querySelector(selector);
try {
if (angular.getTestability) {
angular.getTestability(el).whenStable(callback);
} else {
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
}
} catch (e) {
callback(e);
}
};
Run Code Online (Sandbox Code Playgroud)
附加信息:当我在webdriver(浏览器)对象上激发错误时,错误消息指向量角器目录中的chromedriver.exe.我不明白为什么错误不是来自appium的chromedriver
所以tldr; 没有成功调用waitForAngular,我不能(稳定或根本)访问手机页面上的元素,所以不测试.也许我在这里误解了一些基本的配置细节,欢迎所有提示.
编辑:在这里添加了appium服务器日志:http://pastebin.com/vqBGUdXH
我想我已经确定了问题所在。Appium 和 Protractor 工作正常。
我的 angularJS 应用程序导致了这个问题。它使用 $timeout 进行轮询(我强制使用没有 $interval 的角度 1.07)。这会导致量角器期望页面仍处于加载阶段并且尚未完成。因此,函数调用waitForAngular()永远不会返回,并且测试在指定的超时时间后超时。
这种行为是预期的和已知的,也记录在http://angular.github.io/protractor/#/timeouts(最好先阅读文档;))
该文档建议进行以下连续轮询:替换$timeout为$interval:
如果您的应用程序连续轮询
$timeout或$http,它永远不会被注册为完全加载。您应该将$interval服务 (interval.js) 用于任何连续轮询的内容(在 Angular 1.2rc3 中引入)。
现在,我用另一种方式解决了这个问题:禁用内置角度同步并手动同步
this.Before(function(next){
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true; //disables waitForangular()
next();
});
Run Code Online (Sandbox Code Playgroud)
同步方法一:
//at a testcase, wait for an element to be visible with a promise/then
browser.wait(function () {
element.all(by.css('.myCssClass')).then(function (items) {
items[0].getText().then(function (text) {
console.log(text);
});
});
return true;
}
Run Code Online (Sandbox Code Playgroud)同步方法2:
// "eventually" (chai-as-promised) internally uses "promise" (and therefore acts like "then")
browser.get(url);
expect(browser.getTitle()).to.eventually.equal("connect me").and.notify(next);
Run Code Online (Sandbox Code Playgroud)