Javascript 茉莉花规格超时。重置WebDriver控制流-重定向到新页面时

Javascript 茉莉花规格超时。重置WebDriver控制流-重定向到新页面时,javascript,angularjs,protractor,angularjs-e2e,e2e-testing,Javascript,Angularjs,Protractor,Angularjs E2e,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: Erro

我是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

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();

    setTimeout(function() {
        expect(true).toBe(true);
        done();
    }, 1000);
});
所以我猜在重定向后使用浏览器和元素时会出现问题


有什么想法吗?

你得到了超时,因为你在
回调中注入了一个参数,但从未调用过它(请阅读更多相关内容)。你应该删除该参数,或者在测试结束时调用它。基本上,你不做任何自定义异步操作,所以你不需要它

所以问题是我如何等待页面重新加载并检查url

我建议您等待
index.php
页面上的特定元素:

it('should login and redirect to overview page with CR Operators rights', function() {
    element(by.model('username')).clear().sendKeys('testuser');
    element(by.model('password')).clear().sendKeys('test');
    element(by.css('[type="submit"]')).click();
    browser.wait(protractor.until.elementLocated(by.css('Log out'));
    expect(element(by.css('body')).getText()).toContain('Hello, you are Logged In!');
});

好的,我自己解决了这个问题,但不确定元素和浏览器为什么不工作。 我变了

expect(element(by.css('body')).getText()).toContain('Welcome Test User');

所以我把元素改为browser.driver.findElement,一切正常

我不知道为什么会这样,但它是有效的:)

UPD

据我所知,browser.driver.findElement-不是有角度的方式,如果我们使用无角度的页面,我们应该使用它。虽然我使用angular,但元素和浏览器似乎不会重新初始化。我在这里找到了一些信息
Jasmine对每个规范都有超时,即Jasmine框架中的每个
都有超时。因此,如果任何规范(
it
)超过了jasmine规范的默认超时,则该规范将失败

解决方案: 要覆盖单个规范的jasmine规范超时,请向其传递第三个参数:
it(描述、测试fn、超时(单位:毫秒)

更多有关

  • 如果数组中的正文中有多次相同的文本,则

对我来说,在conf.js中包含这一点后,这一点就起作用了

Hi@Dziamid,我更新了一些问题。请看。也许你有什么想法?正确的格式会增加你建议的可读性。我花了一整天的时间来尝试简单的登录工作,但没能做到。只是我只有在看到你的帖子后才能让它工作。谢谢你,朋友。
expect(element(by.css('body')).getText()).toContain('Welcome Test User');
expect(browser.driver.findElement(by.css('body')).getText()).toContain('Welcome Test User');
it('description of test case', function() {
   /*your test 
               steps
                    here*/
},120000);//120 seconds timeout for this spec
expect(element(by.cssContainingText('body', 'Hello, you are Logged In!')).isPresent()).toBeTruthy();

expect(element.all(by.cssContainingText('body', 'Hello, you are Logged In!')).get(2).isPresent()).toBeTruthy();
 jasmineNodeOpts: { defaultTimeoutInterval: 260000 }