angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

sporadically, test can't click on the Element that is displayed on the page. #5450

Open susmifun opened 4 years ago

susmifun commented 4 years ago

My E2E test is loading a web page and trying to click on element and then enter a value in the text box.

The test passes only 50% of the time. Other times, test complains that the element click is intercepted. Basically the test times out without performing the clicks. Unless user interacts with the web page, then test executes line by line. The code works, but i want to know what should I be doing to get all lines of code executed (100% of the time) without any user interaction.


describe('Enter value test suite', () => { using(SCENARIOS.DEVICE_SCENARIOS, ({device}) => { describe('signedInuser',() => { beforeAll(() => { /// setWindowSize(device); } afterEach(() => { page = null; id = null; browser.executeScript('window.sessionStorage.clear(); window.localStorage.clear();'); }); beforeEach(() => { form= {//test data name: 'User'; lname: 'lname'; } } it(Should load page for users with ${scenario.params} vt on a ${device} device,() =>{ loadmyPage(0,scenario.params); expect( myElement.isPresent()).toBe(true); expect(myElement.link.isDisplayed).toBe(true); myElement.link.click(); myElement.Input.sendKeys('UserName'); } } }


Fuun347 commented 4 years ago

This can be caused by a number of issues in my experience:

  1. The page has not loaded completely at the time the click was executed. The solution is to wait for the slowest element on the page to load before clicking, or just putting a manual browser.sleep(2000) before the click.
  2. There are animations running on the page while the click is performed. Solution is to use a browser.sleep to wait for the animation to end.
  3. Selenium, and with that protractor, wait for all requests to resolve before it starts interacting with the website. So if a request hangs and never returns a response, selenium will eventually timeout. This is a place where the only solution is for the request to be fixed so it does not timeout.
susmifun commented 4 years ago

Thanks Lyubomir Aleksiev for looking into this.

when I used .then() with my Browser.get (), shouldn't this mean that the page is completely loaded and then executes the code block?

browser.get("myURL").then(() => { console.log('begin code block'); expect( myElement.isPresent()).toBe(true); expect(myElement.link.isDisplayed).toBe(true); myElement.link.click(); myElement.Input.sendKeys('UserName'); console.log('End code block'); } Expected Output: Element will be clicked and .sendKeys will be executed.

Actual Output: code block is not getting executed 50% of the times. Only the console statements are being executed.