我是 e2e 测试的初学者并且遇到了问题。当我登录时 - 我从 login.php 重定向到 index.php 页面。但我的测试失败并出现以下错误:
..A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
Failures:
1) Login Page should login and redirect to overview page with CR Operators rights.
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
3 specs, 1 failure
我的代码:
it('should login and redirect to overview page with CR Operators rights', function(sync) {
element(by.model('username')).clear().sendKeys('testuser');
element(by.model('password')).clear().sendKeys('test');
element(by.css('[type="submit"]')).click();
expect(browser.getLocationAbsUrl()).toMatch('/overview');
});
所以问题是我如何等待我的页面重新加载并检查 url?
UPD
我发出 Ajax POST 请求,如果登录/密码正确,我会重定向到 /index.php
更新 2
我用 browser.wait (browser.driver.wait) 尝试了几种结构,但没有任何成功:
it('should login and redirect to overview page with CR Operators rights', function(done) {
element(by.model('username')).clear().sendKeys('testuser');
element(by.model('password')).clear().sendKeys('test');
element(by.css('[type="submit"]')).click();
setTimeout(function() {
expect(element(by.css('body')).getText()).toContain('Welcome Test User');
done();
}, 1000);
});
和
it('should login and redirect to overview page with CR Operators rights', function(done) {
element(by.model('username')).clear().sendKeys('testuser');
element(by.model('password')).clear().sendKeys('test');
element(by.css('[type="submit"]')).click();
browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
console.log(url);
return (/overview/).test(url);
});
}, 5000);
expect(browser.getLocationAbsUrl()).toMatch('/overview');
done();
});
所有这些都不起作用:(但是当我不使用浏览器或元素时-它起作用了。例如:
it('should login and redirect to overview page with CR Operators rights', function(done) {
element(by.model('username')).clear().sendKeys('testuser');
element(by.model('password')).clear().sendKeys('test');
element(by.css('[type="submit"]')).click();
setTimeout(function() {
expect(true).toBe(true);
done();
}, 1000);
});
所以我想这是重定向后使用浏览器和元素时的问题。
有什么想法吗?