SlideShare a Scribd company logo
Automation Testing
Selenium webdriver
Muhammad Bilal
Agenda
❏What is selenium and its architecture?
❏What is Mocha Framework?
❏Selenium webdriver API commands and operations.
❏Setting Up a selenium webdriver project.
❏Creating tests using selenium.
Selenium
It is for automated testing of web applications.
Browsers Support:
IE, FireFox, Opera and Chrome.
Language Support:
C#, Java, Perl, PHP, Python, Ruby, Javascript.
Components:
Selenium IDE, Selenium RC, Selenium Grid, Selenium Webdriver
Architecture
Advantages Of Automation Testing
➢Automation saves time and effort to repeating same tests over and over
again.
➢Execute test script at any time often with different data.
➢Automation is also essential for regression testing. (ensure already
implemented features are not broken)
Mocha
➢Mocha is a JavaScript test framework running on node.js.
➢Browser support
➢Asynchronous testing
➢Test coverage reports
➢Use of any assertion library (assert, chai)
Why
To make sure our test is passed or failed based on some conditions. Each
test case must have some assertions.
Selenium APIs
➢Fetching a page
driver.get('http://192.168.2.101:9092');
➢Locating UI Elements By ID
<div id="coolestWidgetEvah">...</div>
driver.findElement(By.id('coolestWidgetEvah'));
➢By className
<div class="cheese">.......</div>
driver.findElements(By.className("cheese"));
➢By tagName
var frame = driver.findElement(By.tagName('iframe'));
➢By Name
driver.findElement(By.name('cheese'));
➢By linkTesxt
<a href="http://www.google.com/search?q=cheese">cheese</a>>
driver.findElement(By.linkText('cheese'));
➢By css
<div id="food"><span class="dairy">milk</span><p> …. </p></div>
driver.findElement(By.css('#food p'));
➢By xPath
driver.findElements(By.xpath("//input"));
➢Getting Text
driver.findElement(By.id('elementID')).getText().then(text => console.log(`Text is `));
➢Submit / click
driver.findElement(By.id('elementID')).click() / .submit();
➢sendKeys
driver.findElement(webdriver.By.name('username')).sendKeys('admin');
Setting Up Selenium using Javascript
Install javascript bindings with npm, nodejs version > 4.1
➢npm install selenium-webdriver
➢npm install mocha chai -g
Goto directory where selenium-webdriver is installed
➢Make a new javascript file with any name like (selenium.js)
➢Configure selenium-webdriver
var webdriver = require('selenium-webdriver'),
By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until;
var driver = new webdriver.Builder().forBrowser('firefox') .build();
Test Case
➢Webdriver should open cbsgui and enter username admin and
password admin and press login button.
dashboard page should open and logout link should appear on
dashboard.
➢Steps:
Open cbsgui (192.168.2.101:9092)
Find element username,password and enter data.
Submit login request.
➢Expected Result:
Moved to dashboard page.
Script Using Mocha
var webdriver = require('selenium-webdriver'),
By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until;
var test = require('./node_modules/selenium-webdriver/testing');
var expect = require('chai').expect;
test.describe('se-Demo', function() { // define test suite
this.timeout(1000 * 100);
var driver;
test.before(function() {
driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
});
test.after(function() {
driver.quit();
});
test.it('Should Login Successfully', function(done) {
driver.get('http://192.168.2.101:9092').then(function () {
driver.findElement(webdriver.By.name('username')).sendKeys('admin');
element = driver.findElement({name: 'password'});
element.sendKeys('admin'); element.submit();
}) .then(function () {
driver.wait(until.elementLocated(By.className('fa-sign-out')), 1000 * 60);
expect(driver.findElement(By.className('fa-sign-out'))).not.to.be.null;
done();
});
});
});
References
1. http://www.seleniumhq.org/docs/03_webdriver.jsp
2. http://seleniumhq.github.io/selenium/docs/api/javascript/module/seleniu
m-webdriver/lib/promise.html
3. https://gist.github.com/huangzhichong/3284966
4. https://mochajs.org/
5. http://chaijs.com/api/bdd/
Thank You
Any Question ?

More Related Content

What's hot

Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
Kerry Buckley
 
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
Edureka!
 
Selenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansaliaSelenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansaliaRakesh Hansalia
 
Selenium WebDriver: Tips and Tricks
Selenium WebDriver: Tips and TricksSelenium WebDriver: Tips and Tricks
Selenium WebDriver: Tips and Tricks
Edureka!
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Yuriy Gerasimov
 
Python selenium
Python seleniumPython selenium
Python selenium
Ducat
 
An Overview of Selenium
An Overview of SeleniumAn Overview of Selenium
An Overview of Selenium
adamcarmi
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
Sachin-QA
 
Selenium By Pravin Mishra
Selenium By Pravin MishraSelenium By Pravin Mishra
Selenium By Pravin Mishra
Pravin Mishra
 
Selenium
SeleniumSelenium
Selenium
Andrew Krug
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Taras Lytvyn
 
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Atirek Gupta
 
Get Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 GridGet Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 Grid
Daniel Herken
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiew
Disha Srivastava
 
Selenium Ide Tutorial
Selenium Ide TutorialSelenium Ide Tutorial
Selenium Ide Tutorial
metapix
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introduction
Deepak Kumar Digar
 
Automated UI testing with Selenium
Automated UI testing with SeleniumAutomated UI testing with Selenium
Automated UI testing with Selenium
Yuriy Gerasimov
 

What's hot (20)

Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
Selenium Framework using Java | Selenium Tutorial | Selenium Training Online ...
 
Selenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansaliaSelenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansalia
 
Selenium WebDriver: Tips and Tricks
Selenium WebDriver: Tips and TricksSelenium WebDriver: Tips and Tricks
Selenium WebDriver: Tips and Tricks
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
 
Selenium Demo
Selenium DemoSelenium Demo
Selenium Demo
 
Python selenium
Python seleniumPython selenium
Python selenium
 
An Overview of Selenium
An Overview of SeleniumAn Overview of Selenium
An Overview of Selenium
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
 
Selenium By Pravin Mishra
Selenium By Pravin MishraSelenium By Pravin Mishra
Selenium By Pravin Mishra
 
Selenium
SeleniumSelenium
Selenium
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
 
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
 
Get Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 GridGet Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 Grid
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiew
 
Selenium Ide Tutorial
Selenium Ide TutorialSelenium Ide Tutorial
Selenium Ide Tutorial
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introduction
 
Automated UI testing with Selenium
Automated UI testing with SeleniumAutomated UI testing with Selenium
Automated UI testing with Selenium
 

Viewers also liked

Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
Naresh Chintalcheru
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
Watir web automated tests
Watir web automated testsWatir web automated tests
Watir web automated tests
Nexle Corporation
 
Watir
WatirWatir
Watir
Sai Venkat
 
Keyword Driven Framework using WATIR
Keyword Driven Framework using WATIRKeyword Driven Framework using WATIR
Keyword Driven Framework using WATIR
Nivetha Padmanaban
 
Fast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender SystemsFast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender Systems
David Zibriczky
 
Test Automation
Test AutomationTest Automation
Test Automation
Tomas Riha
 
API Test Automation Tips and Tricks
API Test Automation Tips and TricksAPI Test Automation Tips and Tricks
API Test Automation Tips and Tricks
testhive
 
Introduction to the INTEGRAL FRAMEWORK
Introduction to the INTEGRAL FRAMEWORKIntroduction to the INTEGRAL FRAMEWORK
Introduction to the INTEGRAL FRAMEWORKKarthik Subramanian
 
Introduction to the integral framework
Introduction to the integral frameworkIntroduction to the integral framework
Introduction to the integral framework
Karthik Subramanian
 
2 selenium-aakar gupte
2 selenium-aakar gupte2 selenium-aakar gupte
2 selenium-aakar gupte
aakar gupte
 
Frisby Api automation
Frisby Api automationFrisby Api automation
Frisby Api automation
Dineesha Suraweera
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation framework
vodqancr
 
Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_ugly
John Ferguson Smart Limited
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
Sam Brannen
 
Selenium Ide Tutorials
Selenium Ide TutorialsSelenium Ide Tutorials
Selenium Ide Tutorialsgueste1e4db
 
Hybrid framework for test automation
Hybrid framework for test automationHybrid framework for test automation
Hybrid framework for test automationsrivinayak
 
Web API Test Automation using Frisby & Node.js
Web API Test Automation using Frisby  & Node.jsWeb API Test Automation using Frisby  & Node.js
Web API Test Automation using Frisby & Node.js
Chi Lang Le Vu Tran
 
Functional and Non-functional Test automation
Functional and Non-functional Test automationFunctional and Non-functional Test automation
Functional and Non-functional Test automation
Dr Ganesh Iyer
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
Michael Palotas
 

Viewers also liked (20)

Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 
Watir web automated tests
Watir web automated testsWatir web automated tests
Watir web automated tests
 
Watir
WatirWatir
Watir
 
Keyword Driven Framework using WATIR
Keyword Driven Framework using WATIRKeyword Driven Framework using WATIR
Keyword Driven Framework using WATIR
 
Fast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender SystemsFast ALS-Based Matrix Factorization for Recommender Systems
Fast ALS-Based Matrix Factorization for Recommender Systems
 
Test Automation
Test AutomationTest Automation
Test Automation
 
API Test Automation Tips and Tricks
API Test Automation Tips and TricksAPI Test Automation Tips and Tricks
API Test Automation Tips and Tricks
 
Introduction to the INTEGRAL FRAMEWORK
Introduction to the INTEGRAL FRAMEWORKIntroduction to the INTEGRAL FRAMEWORK
Introduction to the INTEGRAL FRAMEWORK
 
Introduction to the integral framework
Introduction to the integral frameworkIntroduction to the integral framework
Introduction to the integral framework
 
2 selenium-aakar gupte
2 selenium-aakar gupte2 selenium-aakar gupte
2 selenium-aakar gupte
 
Frisby Api automation
Frisby Api automationFrisby Api automation
Frisby Api automation
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation framework
 
Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_ugly
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
Selenium Ide Tutorials
Selenium Ide TutorialsSelenium Ide Tutorials
Selenium Ide Tutorials
 
Hybrid framework for test automation
Hybrid framework for test automationHybrid framework for test automation
Hybrid framework for test automation
 
Web API Test Automation using Frisby & Node.js
Web API Test Automation using Frisby  & Node.jsWeb API Test Automation using Frisby  & Node.js
Web API Test Automation using Frisby & Node.js
 
Functional and Non-functional Test automation
Functional and Non-functional Test automationFunctional and Non-functional Test automation
Functional and Non-functional Test automation
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
 

Similar to Selenium Webdriver

Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with Drupal
Promet Source
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsNick Belhomme
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousa
Emma Armstrong
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
Gousalya Ramachandran
 
Introduction to Selenium and WebDriver
Introduction to Selenium and WebDriverIntroduction to Selenium and WebDriver
Introduction to Selenium and WebDriver
TechWell
 
Selenium Testing with TestingBot.com
Selenium Testing with TestingBot.comSelenium Testing with TestingBot.com
Selenium Testing with TestingBot.com
testingbot
 
前端網頁自動測試
前端網頁自動測試 前端網頁自動測試
前端網頁自動測試
政億 林
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
RomSoft SRL
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaEr. Sndp Srda
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
Artem Nagornyi
 
Cross platform browser automation tests sdp
Cross platform browser automation tests   sdpCross platform browser automation tests   sdp
Cross platform browser automation tests sdp
Oren Ashkenazy
 
Selenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB AcademySelenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB Academy
TIB Academy
 
Selenium + Specflow
Selenium + SpecflowSelenium + Specflow
Selenium + Specflow
cromwellryan
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
Roman Savitskiy
 
Automated UI testing.Selenium.DrupalCamp Kyiv 2011
Automated UI testing.Selenium.DrupalCamp Kyiv 2011Automated UI testing.Selenium.DrupalCamp Kyiv 2011
Automated UI testing.Selenium.DrupalCamp Kyiv 2011camp_drupal_ua
 
Interview Questions of Python selenium.pptx
Interview Questions of Python selenium.pptxInterview Questions of Python selenium.pptx
Interview Questions of Python selenium.pptx
DucatIndia4
 
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
Scrum Breakfast Vietnam
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch
Haitham Refaat
 

Similar to Selenium Webdriver (20)

Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with Drupal
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousa
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Introduction to Selenium and WebDriver
Introduction to Selenium and WebDriverIntroduction to Selenium and WebDriver
Introduction to Selenium and WebDriver
 
Selenium Testing with TestingBot.com
Selenium Testing with TestingBot.comSelenium Testing with TestingBot.com
Selenium Testing with TestingBot.com
 
前端網頁自動測試
前端網頁自動測試 前端網頁自動測試
前端網頁自動測試
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Sel
SelSel
Sel
 
Cross platform browser automation tests sdp
Cross platform browser automation tests   sdpCross platform browser automation tests   sdp
Cross platform browser automation tests sdp
 
Selenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB AcademySelenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB Academy
 
Selenium + Specflow
Selenium + SpecflowSelenium + Specflow
Selenium + Specflow
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Automated UI testing.Selenium.DrupalCamp Kyiv 2011
Automated UI testing.Selenium.DrupalCamp Kyiv 2011Automated UI testing.Selenium.DrupalCamp Kyiv 2011
Automated UI testing.Selenium.DrupalCamp Kyiv 2011
 
Interview Questions of Python selenium.pptx
Interview Questions of Python selenium.pptxInterview Questions of Python selenium.pptx
Interview Questions of Python selenium.pptx
 
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
[DN Scrum Breakfast] Protractor: E2E Testing for AngularJS (by Thuy Nguyen)
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch
 

Selenium Webdriver

  • 2. Agenda ❏What is selenium and its architecture? ❏What is Mocha Framework? ❏Selenium webdriver API commands and operations. ❏Setting Up a selenium webdriver project. ❏Creating tests using selenium.
  • 3. Selenium It is for automated testing of web applications. Browsers Support: IE, FireFox, Opera and Chrome. Language Support: C#, Java, Perl, PHP, Python, Ruby, Javascript. Components: Selenium IDE, Selenium RC, Selenium Grid, Selenium Webdriver
  • 5. Advantages Of Automation Testing ➢Automation saves time and effort to repeating same tests over and over again. ➢Execute test script at any time often with different data. ➢Automation is also essential for regression testing. (ensure already implemented features are not broken)
  • 6. Mocha ➢Mocha is a JavaScript test framework running on node.js. ➢Browser support ➢Asynchronous testing ➢Test coverage reports ➢Use of any assertion library (assert, chai) Why To make sure our test is passed or failed based on some conditions. Each test case must have some assertions.
  • 7. Selenium APIs ➢Fetching a page driver.get('http://192.168.2.101:9092'); ➢Locating UI Elements By ID <div id="coolestWidgetEvah">...</div> driver.findElement(By.id('coolestWidgetEvah')); ➢By className <div class="cheese">.......</div> driver.findElements(By.className("cheese")); ➢By tagName var frame = driver.findElement(By.tagName('iframe')); ➢By Name driver.findElement(By.name('cheese'));
  • 8. ➢By linkTesxt <a href="http://www.google.com/search?q=cheese">cheese</a>> driver.findElement(By.linkText('cheese')); ➢By css <div id="food"><span class="dairy">milk</span><p> …. </p></div> driver.findElement(By.css('#food p')); ➢By xPath driver.findElements(By.xpath("//input")); ➢Getting Text driver.findElement(By.id('elementID')).getText().then(text => console.log(`Text is `)); ➢Submit / click driver.findElement(By.id('elementID')).click() / .submit(); ➢sendKeys driver.findElement(webdriver.By.name('username')).sendKeys('admin');
  • 9. Setting Up Selenium using Javascript Install javascript bindings with npm, nodejs version > 4.1 ➢npm install selenium-webdriver ➢npm install mocha chai -g Goto directory where selenium-webdriver is installed ➢Make a new javascript file with any name like (selenium.js) ➢Configure selenium-webdriver var webdriver = require('selenium-webdriver'), By = require('selenium-webdriver').By, until = require('selenium-webdriver').until; var driver = new webdriver.Builder().forBrowser('firefox') .build();
  • 10. Test Case ➢Webdriver should open cbsgui and enter username admin and password admin and press login button. dashboard page should open and logout link should appear on dashboard. ➢Steps: Open cbsgui (192.168.2.101:9092) Find element username,password and enter data. Submit login request. ➢Expected Result: Moved to dashboard page.
  • 11. Script Using Mocha var webdriver = require('selenium-webdriver'), By = require('selenium-webdriver').By, until = require('selenium-webdriver').until; var test = require('./node_modules/selenium-webdriver/testing'); var expect = require('chai').expect; test.describe('se-Demo', function() { // define test suite this.timeout(1000 * 100); var driver;
  • 12. test.before(function() { driver = new webdriver.Builder() .forBrowser('firefox') .build(); }); test.after(function() { driver.quit(); });
  • 13. test.it('Should Login Successfully', function(done) { driver.get('http://192.168.2.101:9092').then(function () { driver.findElement(webdriver.By.name('username')).sendKeys('admin'); element = driver.findElement({name: 'password'}); element.sendKeys('admin'); element.submit(); }) .then(function () { driver.wait(until.elementLocated(By.className('fa-sign-out')), 1000 * 60); expect(driver.findElement(By.className('fa-sign-out'))).not.to.be.null; done(); }); }); });