Javascript 量角器不';不要等待重定向
我有一个用Jasmine编写的量角器代码,应该登录用户。不幸的是,在转到根url之后,有一个重定向正在进行,这需要相当长的时间(大约5秒),我不能让量角器等待它。我已经尝试了Javascript 量角器不';不要等待重定向,javascript,angularjs,protractor,angularjs-e2e,e2e-testing,Javascript,Angularjs,Protractor,Angularjs E2e,E2e Testing,我有一个用Jasmine编写的量角器代码,应该登录用户。不幸的是,在转到根url之后,有一个重定向正在进行,这需要相当长的时间(大约5秒),我不能让量角器等待它。我已经尝试了浏览器。等等,,我尝试过使用承诺,我尝试过使用,但没有任何效果。它仍然没有等待。登录页面是来自Keyclope服务器的页面,这就是为什么我使用driver.findElement而不是element。以下是我当前的代码: describe('my app', function() { it('login', functi
浏览器。等等,
,我尝试过使用承诺,我尝试过使用,但没有任何效果。它仍然没有等待。登录页面是来自Keyclope服务器的页面,这就是为什么我使用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");
});
});
});
});
你知道我能做些什么让它工作吗?我已使用此种子启动了量角器项目:您需要关闭同步:
注意,我还更新了测试:切换回
元素
和浏览器
,添加了内置预期条件的浏览器.wait()
。上述代码对我不起作用。我收到一个等待超时错误
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');
});
});
});