Skip to main content
added 116 characters in body
Source Link
PDHide
  • 11.1k
  • 2
  • 16
  • 43

In protractor everything is promise:

so you have to sueuse await with browser sleep.sleep also, if you wnatwant 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();
             })
            
        });
        
    }
  );

In protractor everything is promise:

so you have to sue await with browser sleep also if you wnat 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();

    });

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

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();
             })
            
        });
        
    }
  );
added 829 characters in body
Source Link
PDHide
  • 11.1k
  • 2
  • 16
  • 43

In protractor everything is promise:

so you have to sue await with browser sleep also if you wnat 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(); 

 /////   });

If you don't want to use await :

    it('click on the arrow and click on yesyes', 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();
             })
            
        });
        
    }
  );

In protractor everything is promise:

so you have to sue await with browser sleep also if you wnat 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(); ///// click on yes

    });

In protractor everything is promise:

so you have to sue await with browser sleep also if you wnat 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(); 

    });

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();
             })
            
        });
        
    }
  );
Source Link
PDHide
  • 11.1k
  • 2
  • 16
  • 43

In protractor everything is promise:

so you have to sue await with browser sleep also if you wnat 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(); ///// click on yes

    });