2014-10-10 63 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

相關問題