2014-03-29 20 views
1

測試目前看起來像如何在使用chromedriver的量角器e2e測試的beforeEach中正確注入登錄服務?

describe('if authenticated', function() { 
    beforeEach(function() { 
    var ptor = protractor.getInstance(); 
    ptor.waitForAngular(); 
    browser.executeAsyncScript(function() { 
     var callback = arguments[arguments.length - 1]; 
     var loginService = angular.injector(['ng', 'firebase', 'myApp.config', 'myApp.service.firebase', 'myApp.service.login']).get('loginService'); 
     loginService.init(); 
     loginService.login(browser.params.login.user, browser.params.login.password, callback); 
     callback(null, true); 
    }); 
    }); 

    it('should stay on account screen if authenticated', function() { 
    browser.get('/app/index.html#/account'); 

    // expect(browser.window().hash()).toBe('/account'); 
    expect(browser.getCurrentUrl()).toMatch(/\/account/); 
    }); 
}); 

有,我不能避開兩大誤區,無論是「錯誤在等待量角器與頁同步:{}」或「未知錯誤:角不定義',這取決於waitForAngular調用。

我該如何做到這一點,使測試通過?

編輯:

我也看到了「不明錯誤:JavaScript錯誤:瀏覽器沒有定義」,如果我運行試驗,測試套件(所有其他測試通過)的一部分。

這是嘗試在beforeEach中爲已驗證頁面注入loginService的唯一測試。在afterEach中訪問角度似乎按預期工作。

文件配置/ protractor.conf.js

exports.config = { 
    // The address of a running selenium server. 
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub', 
    baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), 

    // Capabilities to be passed to the webdriver instance. 
    capabilities: { 
    'browserName': 'chrome' 
    }, 
... 
+0

'不明錯誤:JavaScript錯誤:瀏覽器沒有定義':您必須將Chrome添加到您的配置文件[鏈接](https://github.com/angular/protractor/blob/ master/example/chromeOnlyConf.js) And'等待量角器與頁面同步時出錯:{}':selenium/webdriver-manager正在運行? – nilsK

+0

感謝您試圖幫助 - 請參閱上面的配置文件摘錄 - 不想做'僅鉻' - 我需要嗎? - 是的硒/網絡驅動器經理正在運行 - 任何其他的想法? – Andreas

+0

剛發現,有一個關於此[鏈接]的公開問題(https://github.com/angular/protractor/issues/49) 嘗試添加「ptor.ignoreSynchronization = true;」在運行第一次測試之前。忘了:不,你不需要配置'chrome only',但是如果你不使用phantom.js(或類似的工具),你將需要配置一個瀏覽器(如果我沒有遺漏任何東西; o) – nilsK

回答

1

您可以登錄移動到配置文件的onPrepare塊。

onPrepare: function() { 
    // The require statement must be down here, since jasmine-reporters 
    // needs jasmine to be in the global and protractor does not guarantee 
    // this until inside the onPrepare function. 
    require('jasmine-reporters'); 
    browser.ignoreSynchronization = true; 
    browser.driver.get("https://xyz.com"); 
    browser.driver.findElement(by.id('loginPageUsername')).sendKeys('[email protected]'); 
    browser.driver.findElement(by.id('loginPagePassword')).sendKeys('mypass'); 
    browser.driver.findElement(by.css('.login')).click(); 

    jasmine.getEnv().addReporter(
     new jasmine.JUnitXmlReporter('functional_results/', true, true)); 
    } 

相關問題