2014-10-10 24 views
5

我(新近)使用量角器来运行e2e黄瓜测试。 我有一个基于angularJS的web应用程序。我正在使用appium在真实的Android设备上远程运行测试。下面是我使用的版本:量角器的waitForAngular()在angular-webapp(真实设备上的appium/chrome)上失败

windows8.1 
[email protected] (with submodule [email protected]) 
[email protected] 
android device with 4.4.4 

我量角器配置(提取物),对应于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 
}; 

正如你所看到的,我已经取代量角器的webdriver的网址与appium webdriver。我使用“appium &”从命令行启动appium,然后用“protactor cucumbertest.conf”运行测试。

手机打开Chrome浏览器并导航到我用“browser.get(url)”给它的url

的问题如下: 通话waitForAngular(),这是异步等待网页加载,并在所有开放的HTTP请求(据我了解),是不是在手机上成功地执行。手机没有反应的号召,与代理的webdriver返回一个500

对应https://github.com/angular/protractor/issues/1358,我理解的是,waitForAngular()函数混合量角器到呼叫

['getCurrentUrl', 'getPageSource', 'getTitle']; 

waitForAngular背后( )在文件protractor.js低于函数,其被代理到电话:

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); 
    } 
}; 

附加信息:当我STIM在webdriver(浏览器)对象上产生错误,错误消息指向量角器目录内的chromedriver.exe。我不明白为什么错误不是来自appium的chromedriver


so tldr; 没有成功的调用waitForAngular,我不能(稳定或完全)访问手机页面上的元素,所以没有测试。也许我误解了一些基本配置细节,欢迎提供所有提示。

编辑:添加appium服务器日志的位置:http://pastebin.com/vqBGUdXH

+1

您的能力都是正确的,并且appium服务器工作正常。在处理完所有命令之后返回500。尝试张贴在discuss.appium.io你会得到最好的回应那里 – sheeptest 2014-10-10 16:44:43

回答

4

我想我已经确定问题。 Appium和量角器工作正常。

我的angularJS应用程序导致该问题。它使用$超时进行轮询(im强制在角度1.07,没有$间隔)。这会导致量角器期望页面仍处于加载阶段,但尚未完成。因此函数调用waitForAngular()永远不会返回,测试在指定的超时时间之后超时。

此行为是正常的和已知的,还记载(更好地阅读文档第一;))在http://angular.github.io/protractor/#/timeouts

的文档表明连续轮询如下:与$interval替换$timeout

如果您的应用程序不断民意调查$timeout$http,它永远不会被注册为完全加载。您应该使用$interval服务(interval.js)来连续轮询(在Angular 1.2rc3中引入)。

现在,我解决了该问题的另一种方式:禁用内置角度同步和手动同步

this.Before(function(next){ 
    ptor = protractor.getInstance(); 
    ptor.ignoreSynchronization = true; //disables waitForangular() 
    next(); 
}); 
  1. Sync方法1:

    //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; 
    } 
    
  2. Sync方法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); 
    
+1

我必须在这里添加,你可以使用$超时,只要你在$超时正确运行.cancel函数。用$ interval替换$ timeout并不是那么明显,因为它们没有确切的行为。检查我的帖子http://stackoverflow.com/questions/40832962/angular-1-5-timeout-using-a-httpinterceptor和如何取消$超时的评论,之后,你仍然可以继续使用waitForAngular – 2016-12-19 10:56:10

相关问题