TransWikia.com

Script timeout in Protractor

Software Quality Assurance & Testing Asked by Ingridd Brito on November 21, 2021

My current scenario is: the user types the username, password, and click on the login button. Then, the next screen shows a list box with Stores to login. Protractor loads this list box but it does not find any element on it. And some times I get an error when I click on any element from this list:

Stack:
ScriptTimeoutError: script timeout
(Session info: chrome=84.0.4147.89)
(Driver info: chromedriver=84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}),platform=Windows NT 10.0.18362 x86_64)

This is my spec file

describe('Stock Take Review', function () {
it('should do user login', function () {     

    browser.get('myurl');
    browser.driver.manage().window().maximize();
    browser.sleep(1000);
    element(by.id("mat-input-0")).sendKeys('user');
    element(by.id('mat-input-1')).sendKeys('Pwd');
    element(by.css('.full-width')).click();///////click on login       
    browser.sleep(1000);       

});
////////// Here the list box lists all the store, that the user should select

it('should select a shop', async function () {  
    let EC = browser.ExpectedConditions;
    let elm =  element(by.css('.mat-list-item:nth-child(1) .center'));        
    browser.wait(EC.elementToBeClickable(element(elm)), 150000);          
    await elm.click(); // select Koge store         
    browser.sleep(2000);
    await element(by.css('.mat-fab > .mat-button-wrapper')).click(); // click on the play button
    browser.sleep(2000);        
});

here is the config file

exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    "browserName": 'chrome',
        chromeOptions: {     
          args: ['incognito'],


        mobileEmulation: {
            "device": 'Zebra TC20',
            "deviceMetrics": {
                "width": 340,
                "height": 440,
                "pixelRatio": 3.0
            }
        }
    }
},

   // Framework to use. Jasmine is recommended.
   framework: 'jasmine',
 
    specs: ['../tests/StockTake_Review.js'],
    

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 120000
  },

Any help is really appreciated!

2 Answers

I found a workaround: On the config file I added: allScriptsTimeout: 1100000, getPageTimeout: 60000,

and on the spec file, on the function that was failing I added: browser.ignoreSynchronization = true;

Answered by Ingridd Brito on November 21, 2021

In your config file you have defaultTimeoutInterval: 120000 ,

and you are waiting for 150000 sec in your explicit wait

I think ,the element was not located and the system tries to locate it for 150000 millisec but after 120000 throws timeout error

reduce explicit wait time

 browser.wait(EC.elementToBeClickable(element(elm)), 10000);

Update after reading your fix:

Also read protractor timeouts:

https://www.protractortest.org/#/timeouts

Summary:

  1. If you are using non angular webapp then use browser.waitForAngularEnabled(false); dont use ignore synchronization
  2. Add allScriptsTimeout: 1100000 to avoid script timeout if scripts are too long
  3. use getPageTimeout , if page is taking more than 10sec to load (and only if this is accepted in your case, else its a bug n your product)

Answered by PDHide on November 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP