protractor icon indicating copy to clipboard operation
protractor copied to clipboard

ScriptTimeoutError with Angular/Protractor test suite

Open Subasinghe opened this issue 4 years ago • 5 comments

I am using Protractor to test automate with Angular web application. My test suite has around 37 test cases. Each test case runs successfully when it runs individually.When I run the whole test suite, I get

ScriptTimeoutError: script timeout ....................................... From: Task: Protractor.waitForAngular() - Locator: By(xpath, /html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[1]/div/app-files/div/div[2]/ag-grid-angular/div/div[2]/div[1]/div[3]/div[2]/div/div/div[12]/div[1]])

most of the time.

I have followed few solutions, but they didn't work.

  1. browser.ignoreSynchronization = true
  2. browser.wait(EC.visibilityOf(element), 10000)

I have posted relevant code snippets to understand the issue. Is there any wrong?

  • Angular version - 7.2.16
  • Protractor version - 5.4.4

Component_spec.js

var LoginModule = require("./LoginModule.js");
var ComponentModule = require("./ComponentModule.js");

describe('Component Spec', function () {
var componentModule = new ComponentModule();

beforeAll(async function () {
	console.log("===Loading home page");
	browser.driver.sleep(8000);
});

beforeEach(async function () {
	browser.get(LoginModule.homeUrl);
	browser.driver.sleep(8000);
});

it('editinput', async function () {
	var AlertMessage = element(by.cssContainingText('.col-sm-11', 'underline'));
	componentModule.editinput("value");
	expect(AlertMessage.isPresent()).toBe(false);
	browser.driver.sleep(5000);
});
});

ComponentModule.js

this.editinput = async function (value) {
	let selectCheckbox2 = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[1]/div/app-files/div/div[2]/ag-grid-angular/div/div[2]/div[1]/div[3]/div[2]/div/div/div[12]/div[1]'));
	await selectCheckbox2.click();
	await browser.driver.sleep(5000);
	browser.ignoreSynchronization = true;
	let selectNext = element(by.xpath('//*[@id="next"]'));
	await selectNext.click();
	await browser.driver.sleep(5000);
	browser.ignoreSynchronization = true;

	let input = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[2]/div/div[2]/div[1]/button[2]'))
	await input.click();

	let right = element(by.className("right_button"));
	await right.click();
	await browser.driver.sleep(2000);

	let edit = element(by.className("edit_box"));
	await edit.sendKeys(value);
	await browser.driver.sleep(5000);

	let saveBtn = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[2]/div/app-procedure/div/div[2]/div[1]/button[3]/i'));
	await saveBtn.click();
	await browser.driver.sleep(8000);
	browser.ignoreSynchronization = false;
};

conf.js

exports.config = {
   framework: 'jasmine',
   seleniumAddress: 'http://localhost:4444/wd/hub',

   capabilities: {
      browserName: 'chrome',
      acceptSslCerts: true,
      shardTestFiles: false,
      maxInstances: 1
   },
   jasmineNodeOpts: {
      showColors: true,
      defaultTimeoutInterval: 100000,
   },
   onPrepare: () => {
      browser.manage().window().maximize();
      browser.manage().timeouts().implicitlyWait(10000);
      browser.ignoreSynchronization = true;
   }
}

Subasinghe avatar May 10 '20 14:05 Subasinghe

@Subasinghe Try adding the following two properties in conf.js to fix the page timeout issue: allScriptsTimeout: 1100000, getPageTimeout: 60000,

Add the following to *spec.js

var originalTimeout;

beforeEach(function () { originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; });

afterEach(function () { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; });

singhrajkr avatar May 10 '20 17:05 singhrajkr

@SinghRajKr I could increase the probability of running successfully using your solution. But again test suite has failed few times with following errors.

NoSuchElementError: No element found using locator: By(css selector, .element1)

UnhandledPromiseRejectionWarning: ScriptTimeoutError: script timeout

UnhandledPromiseRejectionWarning: WebDriverError: No active session with ID cc32c3ab609bfb9e9861d5167fc44175

Those errors occurred one after another, when I ran the test suite.

Subasinghe avatar May 11 '20 15:05 Subasinghe

@Subasinghe Could you share your tests screen over skype if you are comfortable.

singhrajkr avatar May 11 '20 15:05 singhrajkr

Encountering the same. Can anyone enlighten to a fix / workaround?

sittingbool avatar Jun 16 '21 14:06 sittingbool

It seems as if the the methods (any) that are trying to locate html elements are stuck. the promises are not resolved.

sittingbool avatar Jun 16 '21 14:06 sittingbool