2015-12-16 35 views
1

我有用Jasmine寫的量角器代碼應該登錄用戶。不幸的是,在轉到根網址後需要一段時間(大約5秒)後發生重定向,我無法使量角器等待它。我已經嘗試browser.wait,我試過使用承諾,我試過this blogpost,但沒有做到。它仍然不會等待。登錄頁面是Keycloak服務器的頁面,這就是爲什麼我使用driver.findElement而不是element。這是我目前的代碼:量角器不會等待重定向

describe('my app', function() { 
    it('login', function() { 
    var driver = browser.driver; 
    browser.get('/'); 
    console.log('get'); 
    driver.findElement(by.id('username')).isPresent().then(function() { 
     console.log('waited'); 
     driver.findElement(by.id('username')).sendKeys("test"); 
     driver.findElement(by.id('password')).sendKeys("test"); 
     driver.findElement(by.id('kc-login')).click(); 
     driver.findElement(by.css('.page-header')).isPresent().then(function() { 
     console.log('ok'); 
     expect(browser.getLocationAbsUrl()).toMatch("/test"); 
     }); 
    }); 
    }); 
}); 

你知道我能做些什麼來使它工作嗎?我已經開始量角器項目,這個種子:https://github.com/angular/angular-seed

回答

3

您需要關閉同步

var EC = protractor.ExpectedConditions; 

describe('my app', function() { 

    beforeEach(function() { 
     browser.ignoreSynchronization = true; 
     browser.get('/'); 
    }); 

    it('login', function() { 
    var username = element(by.id('username')); 
    browser.wait(EC.visibilityOf(username), 10000); 

    username.sendKeys("test"); 
    element(by.id('password')).sendKeys("test"); 
    element(by.id('kc-login')).click(); 

    var header = element(by.css('.page-header')); 

    browser.wait(EC.visibilityOf(header), 10000).then(function() { 
     console.log('logged in'); 
    }); 
    }); 
}); 

請注意,我還更新了測試:切換回elementbrowser,加browser.wait()內置預計條件