Running Your First WebDriver Recipe
Follow step-by-step instructions to execute your first Selenium recipe.
We'll cover the following...
We'll cover the following...
First Selenium recipe
Having learned all the basics, let’s move to the practical working of Selenium. Take a look at the following piece of code:
const webdriver = require('selenium-webdriver');var test = require('selenium-webdriver/testing');var assert = require('assert');const chromeDriver = require('chromedriver');const chromeCapabilities = webdriver.Capabilities.chrome();chromeCapabilities.set('chromeOptions', {args: ['--headless', '--disable-gpu','--no-sandbox','--disable-dev-shm-usage']});var driver;const timeOut = 15000;test.describe('User Authentication', function () {test.before(function() {this.timeout(timeOut);driver = new webdriver.Builder().forBrowser('chrome').withCapabilities(chromeCapabilities).build();});test.beforeEach(function() {this.timeout(timeOut);driver.get('http://travel.agileway.net');});test.after(function() {driver.quit();});test.it('Invalid user', function() {driver.findElement(webdriver.By.name('username')).sendKeys('agileway');driver.findElement(webdriver.By.name('password')).sendKeys('badpass');driver.findElement(webdriver.By.name('commit')).click();});test.it('User can login successfully', function() {driver.findElement(webdriver.By.name('username')).sendKeys('agileway');driver.findElement(webdriver.By.name('password')).sendKeys('testwise');driver.findElement(webdriver.By.name('commit')).click();driver.getTitle().then( function(the_title){assert.equal("Agile Travel", the_title);});});});
Selenium script for user authentication
Here, lines 1 to 3 imports Selenium for executing the 'User Authentication'
test, and lines 5 to 7 tells Selenium to acquire the chromedriver. This is an example of a helping driver, which is necessary for enabling Selenium to work with the ...