Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Element.isPresent() script timeout #5151

Open
glemiere opened this issue Feb 13, 2019 · 9 comments
Open

Element.isPresent() script timeout #5151

glemiere opened this issue Feb 13, 2019 · 9 comments

Comments

@glemiere
Copy link

glemiere commented Feb 13, 2019

Hi!

I have an issue using protractor with jasmine, and I wonder if there is an issue with the framework, or if my limited knowledge of the framework plays against me. I found a fairly recent StackOverflow question with four upvotes but no answer so far, which leads me to think that something may be going wrong with the latest version of protractor.

Here is my test:

import {
	browser,
	ExpectedConditions,
	$
} from 'protractor';

describe('When user click \"Test\" button', async () => {
  beforeAll(async () => {
    await browser.get('http://local.myawesomewebsite.com:4200');
    expect(await browser.getCurrentUrl())
		.toContain('myawesomewebsite');
		browser.waitForAngularEnabled(true);
  });

  it ("should navigate to next page", async () => {
		var testButton = $(".wrapper button");
		browser.wait(
			ExpectedConditions.presenceOf(testButton),
			5000,
			'Element taking too long to appear in the DOM'
		);
		expect(await testButton.isPresent())
		.toBe(true);
		await testButton.click();
  });

	describe("When user click button to open modal", async () => {
		beforeAll(() => {
			expect(browser.getCurrentUrl())
			.toContain('next/page');
		});

		it("should make modal appear", async () => {
			var popModalButton 	= await $(".wrapper button");
			var overlay			= await $('.overlay.active');

			browser.wait(
				ExpectedConditions.presenceOf(popModalButton),
				5000,
				'Element taking too long to appear in the DOM'
			);

			expect(await popModalButton.isPresent())
			.toBe(true);
			await popModalButton.click();
		});

		describe("When user clicks modal button", async () => {
			it("should proceed to final page", async () => {
				var proceedToFinalPageButton = await $(".cta.modal-not-empty button.continue-to-final-page");

				await browser.wait(
					ExpectedConditions.presenceOf(proceedToFinalPageButton),
					5000,
					'Element taking too long to appear in the DOM'
				);
				expect(await proceedToFinalPageButton.isPresent())
				.toBe(true);
			});
		});
	});
});

It all works great until the test reach the last attempt to detect if the modal popped out:

await browser.wait(
    ExpectedConditions.presenceOf(proceedToFinalPageButton),
    5000,
    'Element taking too long to appear in the DOM'
);
expect(await proceedToFinalPageButton.isPresent())
.toBe(true);

This isPresent() doesn't return true or false, instead nothing happens and protractor stops and outputs the following error:

Failed: script timeout: result was not received in 11 seconds

Any idea what could be going wrong?
Thanks!

@a-stangl
Copy link

a-stangl commented Feb 15, 2019

I experience more or less the same, I think it's related to browser.waitForAngularEnabled

  • I need to login on a separate angular 7 app
  • once I logged in there I want to test the "main app" that's also using angular 7

If I globally do browser.waitForAngularEnabled(false) I can test both apps, but then I always have to "manually" wait until angular was fully loaded.

So I tried to browser.waitForAngularEnabled(false) while I login in App 1 and browser.waitForAngularEnabled(true) after I logged in there, then I want to redirect to the main app and do my testing. The result is the issue OP reported above.

Looks like toggling browser.waitForAngularEnabled does not really work.

@glemiere
Copy link
Author

@stan187 interesting, I solved another error I had by adding waitForAngularEnabled:false to my protractor config file to be able to use async/await (as an attempt to fix the issue above), but then I had to add browser.waitForAngularEnabled(true) in my test to be able to detect the first elements of my tests.

Unfortunately this did not resolve the issue described above.

I see that you're mentioning Angular 7 specifically, did you try to downgrade Angular to make this work?

@a-stangl
Copy link

@glemiere, no I haven't downgraded. It's a huge customer project. I cannot downgrade because protractor cannot handle tests that involve two separate Angular 7 apps :-D

@gabriellegulczynski
Copy link

gabriellegulczynski commented May 24, 2019

This just started happening for me. It's very inconsistent. Sometimes it works for a decent amount of time and then sometimes it just keeps failing over and over. Are there any plans to fix this?

@glemiere
Copy link
Author

I had to switch to Cypress as I didn’t find a solution. However you will only be able to test on Chrome, but Cypress is really cool!

You can see how to use it with Angular one my StackOverflow answer: https://stackoverflow.com/a/54777134/2196157

@sngvahmed
Copy link

i have the same problem

my code snippets

    async dismissVerificationIfExist() {
        let isElementShowInPage;
        try {
            console.log('is element displayed');            
            await this.verifyLaterButton.isPresent();

            isElementShowInPage = true;
        } catch (err) {
            console.log(err);
            isElementShowInPage = false;
        }

        console.log('verification pop shown value is ', isElementShowInPage);
        if (isElementShowInPage) {
            await this.verifyLaterButton.click();
        }
    }

the error

ScriptTimeoutError: script timeout
  (Session info: chrome=78.0.3904.70)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'sngv', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.0.0-32-generic', java.version: '11.0.4'
Driver info: driver.version: unknown
    at Object.checkLegacyResponse (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/http.js:509:13)
    at /home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/http.js:441:30
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
From: Task: Protractor.waitForAngular() - Locator: By(css selector, *[id="recipientVerificationLaterId"])
    at thenableWebDriverProxy.schedule (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
    at ProtractorBrowser.executeAsyncScript_ (/home/sngv/work/mdp-testing/node_modules/protractor/built/browser.js:425:28)
    at /home/sngv/work/mdp-testing/node_modules/protractor/built/browser.js:456:33
    at ManagedPromise.invokeCallback_ (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/promise.js:1376:14)
    at TaskQueue.execute_ (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/promise.js:3084:14)
    at TaskQueue.executeNext_ (/home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/promise.js:3067:27)
    at /home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/promise.js:2927:27
    at /home/sngv/work/mdp-testing/node_modules/selenium-webdriver/lib/promise.js:668:7
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  name: 'ScriptTimeoutError',
  remoteStacktrace: ''
}

@lsoaresesilva
Copy link

Same problems here.

@linkgreen-erica-borges
Copy link

Same problems here

@von-court
Copy link

Had this issue as well and had thought this was really a protractor bug.
In the meantime I figured out that not only isPresent() is causing timeouts but also other async protractor tasks such as getAttribute etc.
In my case this was caused by a long-running background task in the app I'm testing against: this task keeps the "Angular Zone" at work forever, which makes protractor wait forever, thus the timeout.
Btw: that background async task updates a cookie every few seconds too keep track of "when to show a cookie warning layer again".

After setting browser.waitForAngularEnabled(false) at the beginning of my tests, the issue didn't come up again BUT it required a lot of additional handling with sleeps and waits in order for my tests to run smoothly...

This MIGHT be the reason for your issues as well.

Where I got the idea of the long-running background task from: https://jarifibrahim.github.io/blog/protractor-and-page-synchronization/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants