2015-12-16 50 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()内置预计条件