Selenium + Node
Introduction to Selenium Webdriver Introduction to Node.js Installation and Environment set up NPM – Package Manage for Node.js Directory layout of Selenium Webdriver Node.js package Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methodsAssertions in Selenium in Node.js Interacting with elements in Selenium in Node.js Basic Browser window automation Sending keys in Selenium in Node.js Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in Node.js Executing JavaScript in Selenium in Node.js Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Common exceptions in Selenium Taking a screenshot in selenium Mocha – Unit testing framework Selenium gridSynchronization Selenium in node
We can have 3 types of timeouts. pageLoadTimeout implicitlyWait explicit wait Below line of code shows how to set page load timeout driver.manage().timeouts().pageLoadTimeout(50,TimeUnit.SECONDS); Below line of code shows how to set implicit wait timeout driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); Below line of code shows explicit wait timeout syntax. driver.wait(condition, optional_timeout, optional_message) For example – If you want to wait until title of the page becomes say “Selenium Test Page”, you can use below syntax. driver.wait(until.titleIs(‘Selenium Test Page’), 1000); Here are all of the wait conditions that you can use in your scripts.- ableToSwitchToFrame(frame)
- attemptToSwitchFrames(driver, frame)
- alertIsPresent()
- titleIs(title)
- titleContains(substr)
- titleMatches(regex)
- urlIs(url)
- urlContains(substrUrl)
- function urlMatches(regex)
- elementLocated(locator)
- elementsLocated(locator)
- stalenessOf(element)
- elementIsVisible(element)
- elementIsNotVisible(element)
- elementIsEnabled(element)
- elementIsDisabled(element)
- elementIsSelected(element)
- elementIsNotSelected(element)
- elementTextIs(element, text)
- elementTextContains(element, substr)
- elementTextMatches(element, regex)
var assert = require(‘assert’);
var webdriver = require(‘selenium-webdriver’),
By = webdriver.By,
until = webdriver.until;
var chrome = require(“selenium-webdriver/chrome”);
var options = new chrome.Options();
options.addArguments(“start-maximized”);
options.addArguments(“test-type”);
var driver = new webdriver.Builder().
withCapabilities(options.toCapabilities()).build();
//Pageload time out of 50 seconds
driver.manage().timeouts().pageLoadTimeout(1000*50);
//Implicit wait of 20 seconds
driver.manage().timeouts().implicitlyWait(1000*20);
driver.get(‘https://www.softpost.org/selenium-test-page/’);
//For example – If you want to wait until title of the page becomes say “Selenium Test Page”, you can use below syntax.
//Wait for 4 seconds for title to become “Selenium Test Page | Free Software Tutorials”
driver.wait(until.titleIs(‘Selenium Test Page | Free Software Tutorials’), 1000*4);
driver.getTitle().then(function(title) {
console.log(“title is ” + title);
assert(title===”Selenium Test Page | Free Software Tutorials”);
});
driver.quit();
Web development and Automation testing
solutions delivered!!