Gle*_*leb 7 javascript angularjs angularjs-e2e protractor e2e-testing
我是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');
});
所以问题是当我的页面重新加载并检查网址时我怎么能等待?
UPD
我发出一个Ajax POST请求,如果login/pass是正确的,我会重定向到/index.php
UPD 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);
});
所以我想在重定向后使用浏览器和元素时出现问题.
有什么想法吗?
Gle*_*leb 10
好的,我已经自己解决了这个问题,但不确定为什么元素和浏览器不起作用.我改变了
expect(element(by.css('body')).getText()).toContain('Welcome Test User');
至
expect(browser.driver.findElement(by.css('body')).getText()).toContain('Welcome Test User');
所以我将元素更改为browser.driver.findElement,一切正常.
我不知道它为什么会发生,但它的工作原理:)
UPD
据我所知,browser.driver.findElement - 不是有角度的方式,如果我们使用非角度页面我们应该使用它.虽然我使用angular似乎元素和浏览器不会重新初始化.我在这里找到的一些信息 http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/#test-both-angularjs-and-non-angularjs-based-pages
Jasmine 对每个规范都有超时,即每个it在 jasmine 框架中。因此,如果任何规范 ( it) 超过 jasmine 规范的默认超时,则该规范失败。
解决方案:要覆盖单个规范的 jasmine 规范超时,请将第三个参数传递给它: 
it(description, testFn, timeout_in_millis)
it('description of test case', function() {
   /*your test 
               steps
                    here*/
},120000);//120 seconds timeout for this spec
| 归档时间: | 
 | 
| 查看次数: | 10199 次 | 
| 最近记录: |