0

After clicking on a button, a dialog for confirming should be displayed at the bottom of the page. But Protractor clicks too fast on this button, that the next page is loaded without displays the dialog on the current page. This is the code:

    it('click on the arrow and click on yes', async function () {
        await element(by.css('button')).click(); //////click on the button that should displays the msg
        browser.sleep(1000);

////////// these elements are not displayed because the click is too fast 
        await element(by.css("p")).getText().then(function(text){
            console.log(text);
            expect(text).toBe("Would you like to preserve this return?");
        })
        await element(by.css('button:nth-of-type(2)')).click(); ///// click on yes

    });

I also tried this

it('click on the arrow and click on yes',  async function () {                
        element(by.css('button')).click().then( function (){
            WaitForLoad(element(by.css("p"))).getText().then(function (){
                expect(text).toBe("Would you like to preserve this return?")
            })
        })
        browser.sleep(2000);

        // await element(by.css("p")).getText().then(function(text){
        //     console.log(text);
        //     expect(text).toBe("Would you like to preserve this return?");
        // })
        await element(by.css('button:nth-of-type(2)')).click(); //click on yes       
    });

But then I got: Failed: WaitForLoad is not defined

Any suggestion is appreciated.

2
  • We cannot control the speed of the application from protractor. – Vishal Aggarwal Jun 6 '20 at 1:27
  • Can you share the application details (URL and scenario) or same case in a website in public domain so that we can check the issue? – Aalok Jun 9 '20 at 20:19
1

In protractor everything is promise:

so you have to use await with browser.sleep also, if you want it synchronously.

 it('click on the arrow and click on yes', async function () {
        await element(by.css('button')).click(); 
        await browser.sleep(1000);
        let text = await element(by.css("p")).getText()
        console.log(text);
        expect(text).toBe("Would you like to preserve this return?");
        await element(by.css('button:nth-of-type(2)')).click();

    });

Note: use SELENIUM_PROMISE_MANAGER: false, in your config file https://www.protractortest.org/#/async-await

If you don't want to use await :

    it('click on the arrow and click on yes', function () {

            element(by.css('button')).click().then(function (){
                WaitForLoad(element(by.css("p"))).getText().then(function (){
                    expect(text).toBe("Would you like to preserve this return?")
                })
            });

            browser.sleep(2000).then( function(){

            element(by.css("p")).getText().then(function(text){
                 console.log(text);
                 expect(text).toBe("Would you like to preserve this return?");
                 element(by.css('button:nth-of-type(2)')).click();
             })

        });

    }
  );
5
  • the 1st suggestion I got: Failed: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. My page is Angular. Using the 2nd suggestion I got: WaitForLoad is not defined – Ingridd Brito Jun 5 '20 at 11:07
  • try this await browser.waitForAngularEnabled(false) as first line of code and see whats happening – PDHide Jun 5 '20 at 11:16
  • it('click on the arrow and click on yes', async function () { await browser.waitForAngularEnabled(false) ; await element(by.css('.navigation .mat-icon')).click().then(function (){ WaitForLoad(element(by.css("p"))).getText().then(function (){ expect(text).toBe("Would you like to preserve this return?") element(by.css('button:nth-of-type(2)')).click(); }) }); I got: WaitForLoad is not defined – Ingridd Brito Jun 5 '20 at 12:27
  • i don;t know what is wait for load , i thought its our function . Use the first one – PDHide Jun 5 '20 at 13:02
  • I used the first one with SELENIUM_PROMISE_MANAGER:false. But still, Protractor clicks too fast that the dialog does not appear and the next page is loaded. – Ingridd Brito Jun 5 '20 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.