LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

What are the ways to toggle the waiting feature in Protractor?

Can anyone please suggest me some ways to toggle the waiting feature in Protractor.

Up Vote Down Vote 0 Votes
Posted 3 months ago

Answers


Whenever you want navigation or open a page in the browser that does not use Angular, we can disable this feature of waiting for timeout by passing the argument as false when calling the function i.e. browser.waitForAngularEnabled(false).

browser.waitForAngularEnabled(false);
browser.get('/my_non_angular_page.html');
element(by.id('username')).sendKeys('myusername');
element(by.id('password')).sendKeys('mypassword');
element(by.id('clickButton')).click();
browser.waitForAngularEnabled(true);
browser.get('/my_page-containing-angular.html');

But it might happen that we can get the Asynchronous Script TimeOut Exception from the WaitForAngular method. In such a case the first important thing would be to check on the timeout of our webdriver for scripts that have been set to something around 5 seconds for heavy and slowly loading websites.

Below is the complete code that demonstrates the behavior of handling timeouts in protractor.

// setting required config parameters //
exports.config = {
 directConnect: true,
 // Desired Capabilities that are passed as an argument to the web driver instance.
 capabilities: {
 'browserName': 'chrome' // name of the browser used to test //
 },
 // Flavor of the framework to be used for our test case //
 framework: 'jasmine',
 // The patterns which are relative to the current working directory when 
protractor methods are invoked //
 specs: ['test_timeout.js'],
// overriding default value of getPageTimeout parameter //
 getPageTimeout: 10000,
// overriding default value of allScriptsTimeout parameter //
 allScriptsTimeout: 10000,
 jasmineNodeOpts: {
// overriding default value of defaultTimeoutInterval parameter //
 defaultTimeoutInterval: 30000
 },
 onPrepare: function () {
 browser.manage().window().maximize();
 browser.manage().timeouts().implicitlyWait(5000);
 }
};

test_timeout.js

// import all the required modules from selenium web driver and protractor
import 'selenium-webdriver';
import { browser, element, by, ExpectedConditions, protractor} from 'protractor'
 // describing the test for the timeout demonstration //
 describe('Timeout Demonstration in Protractor', function() {
browser.ignoreSynchronization = true; // disable synchronization for non angular websites //
 // tests to handle timeouts in protractor //
 it('Tests to handle timeouts in protractor', function() {
	// launch the url in the browser // 
 browser.get(http://the-internet.herokuapp.com , 10000);
 browser.manage().timeouts().implicitlyWait(5000)
;
 // locate the element // 
 element(by.xpath(" // label/ span ")).getAttribute("innerTextValue").then(function(textValue){
 // the value saved is assigned to the value of the text box
 element(by.xpath("//input[@type='text']")).sendKeys(textValue);
 })
 },30000);
});
Up Vote Down Vote 0 Votes
Posted 3 months ago
160 Views
1 Answer
3 months ago