0
votes

Testing an angular app, the test are sometimes passing and sometimes failing...

My test cases look like:

it('test-1: should has main button', function () {
    expect(page.demoButton).not.toBeUndefined();
});

it('test-2: should open modal on click secondary button', function () {
    page.demoButton.click().then(function () {
        page.SecondaryButton.click().then(function() {
            expect(page.Modal).not.toBeUndefined();
        });
    });
});

it('test-3: should open modal with correct text', function () {
    page.demoButton.click().then(function () {
        page.SecondaryButton.click().then(function() {
            expect(page.Modal.text.getText()).toEqual('Are you sure to cancel 
this?');
        });
    });
});

If I run the test, sometimes the tests are passed sometimes some of them get failed.. Most of the time error is like: No element found using locator: By.cssSelector(".myButton"). or Cannot read property 'getText' of undefined

Thank you in advance!

1

1 Answers

0
votes

I fixed that issue with using:

browser.waitForAngular(); 

As I see that issue occurs with getText and click events, So:

it('test-2: should open modal on click secondary button', function () {
    page.demoButton.click().then(function () {
        browser.waitForAngular();
        page.SecondaryButton.click().then(function() {
            browser.waitForAngular();
            expect(page.Modal.text.getText()).toEqual('Are you sure to cancel 
            this?');
        });
    });
});

was the solution.