A Jasmine spec timed out. Resetting the WebDriver Control Flow - when redirect to new page
Asked Answered
M

5

10

I'm beginner in the e2e testing and have a problem. When I do login - I make redirect from login.php to index.php page. But my test is fails with following errors:

..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

My code:

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');
});

So the question is how i can wait when my page will reload and check url?

UPD

I make an Ajax POST request and if login/pass are correct I do redirect to /index.php

UPD 2

I have tried several constructions with browser.wait (browser.driver.wait) but without any success:

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

and

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

everything of these don't work :( BUT when I don't use browser or element - it works. E.g.:

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

So I guess that here is a problem when use browser and element after redirect.

Any thoughts?

Mossberg answered 11/6, 2015 at 17:42 Comment(0)
M
11

OK, I have resolved this issue by myself, but not sure why element and browser don't work. I have changed

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

to

expect(browser.driver.findElement(by.css('body')).getText()).toContain('Welcome Test User');

So I have changed element to browser.driver.findElement and everything works.

I don't know why it happens, but it works :)

UPD

As I understand, browser.driver.findElement - is not angular way and we should use it if we use non-angular pages. Although I use angular it seems that element and browser doesn't re-initialize. Some info I found here http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/#test-both-angularjs-and-non-angularjs-based-pages

Mossberg answered 15/6, 2015 at 11:37 Comment(1)
I invested my whole day in trying to get simple login work and couldn't. It's just that I am able to get it to work only after seeing your post. Thanks a ton mate.Alunite
R
7

Jasmine has timeout for each spec i.e. each it in jasmine framework. so if any spec (it) exceeds jasmine spec's default timeout then it fails that spec.

Solution: To override jasmine spec timeout for one individual spec, pass a third parameter to it: it(description, testFn, timeout_in_millis)

it('description of test case', function() {
   /*your test 
               steps
                    here*/
},120000);//120 seconds timeout for this spec

more information on timeouts is here

Rationale answered 27/10, 2016 at 11:21 Comment(0)
W
4

You are getting timeout because you've injected a param into it callback and never called that (read more on that here). You should remove the param, or call it when the test is over. Basically, you don't do any custom async stuff, so you don't need it.

So the question is how I can wait when my page will reload and check url?

I'd suggest that you waited for a specific element on index.php page:

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!');
});
Wolfe answered 12/6, 2015 at 10:41 Comment(1)
Hi @Dziamid, I have updated questions. Please, look. Maybe you have any thoughts?Mossberg
G
1
 jasmineNodeOpts: { defaultTimeoutInterval: 260000 } 

for me this works after including this in conf.js

Gesticulate answered 23/10, 2018 at 10:44 Comment(0)
T
0
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();
  • If you have more than one time the same text in body in array then
Terrieterrier answered 21/9, 2017 at 23:16 Comment(1)
Proper formatting would increase the readability of your suggestions.Stank

© 2022 - 2024 — McMap. All rights reserved.