SlideShare a Scribd company logo
Test Automation Using
Selenium
Swati
Email- swati@knoldus.com
History of The Selenium
●

●

Selenium is invent by Jason Huggins
He developed a Javascript library that could drive interactions
with the page, allowing him to automatically rerun tests against
multiple browsers.
Test Automation
●

Test automation is the use of software
To set test preconditions.
To control the execution of tests.
To compare the actual outcomes to predicted outcomes.
To report the Execution Status.

●

Commonly, test automation involves automating
a manual process already in place that uses a
formalized testing process.
Why and When To Automate?
Frequent regression testing
● Repeated test case Execution is required
● User Acceptance Tests
● Faster Feedback to the developers
● Reduce the Human Effort
● Test same application on multiple environments
●
Selenium
●

●

●

Selenium is a robust set of tools that supports rapid
development of test automation for web-based
applications.
Selenium provides a rich set of testing functions
specifically geared to the needs of testing of a web
application.
Selenium operations are highly flexible, allowing many
options for locating UI elements and comparing
expected test results against actual application
behavior.
Selenium Features
●

●

●
●

●
●

Supports Cross Browser Testing. The Selenium
tests can be run on multiple browsers.
Allows scripting in several languages like Java,
C#, PHP and Python.
Ajax/CSS support.
Assertion statements provide an efficient way of
comparing expected and actual results.
Inbuilt reporting mechanism.
Selenium is an open source tool
Selenium Components
●

Selenium IDE

●

Selenium Remote Control

●

Selenium Grid
Selenium IDE
●
●

●

●

●

●

Previously known as Selenium Recorder
Selenium IDE is an integrated development environment
for Selenium tests.
It is implemented as a Firefox extension, and allows you
to record, edit, and replay the test in firefox
Selenium IDE allows you to save tests as HTML, Java,
Ruby scripts, or any other format
It allows you to automatically add assertions to all the
pages.
Allows you to add selenese commands as and when
required
Selence
●

●

Selence special test scripting language for
Selenium.
Selenese provides commands for performing
actions in a browser (click a link, select an
option), and for retrieving data from the
resulting pages.
Selenium IDE Installation
●

First download Mozilla Firefox browser.

●

Click on the Firefox tab present at the top the browser window.

●

In drop down menu click on Add-on.

●

Go to add on page of Mozilla Firefox browser

●

In the search box of Add on page search the term "Selenium IDE" and
press enter

●

Click on more link to the Selenium IDE add-on

●

Go to http://docs.seleniumhq.org/download/

●

Once installation is done the Mozilla Firefox browser will ask you to
restart the browser.Just Restart it.
Selenium IDE - UI
Start and Stop
Recording

Replay
Toolbar

Editor

Accessor
Area

Selenese
Script
Editor

Selenium Log
Recoding a Selenium Test Case
●
●
●
●

●

●

Open Firefox that has the IDE installed
Open the base URL of the application to record.
Keep the application in a common base state.
Go To Tools  Selenium IDE and the IDE will be
opened
Now perform the operations on the application as you
are testing the application.
Once you are done with the recording click on the stop
recording button and save the test case through the file
menu. By default it will be saved as a selenese script
(HTML format)
Creating a Test Suite
●

●

In the Selenium IDE you can
create any number of test
cases and save them as test
suite.
To Run the test Suite click on
the “Play entire test suite”
button as shown below.

Test Suite with
Test1 & test2
Running Options
Run a Test Case
Click the Run button to run the currently displayed test case.

Run a Test Suite
Click the Run All button to run all the test cases in the currently loaded test
suite.

Stop and Start
The Pause button can be used to stop the test case while it is running. The
icon of this button then changes to indicate the Resume button. To
continue click Resume.
Adding Assertions to the Script
●

Selenese allows multiple ways of checking for UI
elements.

●

Verifications and assertions are used to check if

●

an element is present somewhere on the page?

●

specific text is somewhere on the page?

●

specific text is at a specific location on the page?

●

Verifications and assertions are not one and the same.

●

If an assertion fails, the script will be aborted but if a
verification fails the script will continue.
Assertion Statements
●

●

●

●

●

assertTextPresent
This will assert if the text is present in the page.
assertText
This will assert if a particular element is having the particular text.
assertTitle
This will assert if the page is having a proper title.
assertValue
This will assert if a Text box or check box has a particular value
assertElementPresent
This will assert if a particular UI Element is present in the page.
User Acceptance Testing (UAT)
●

●

●

User Acceptance Testing (UAT) is the last phase of the software
testing process. During UAT, actual software users test the
software to make sure it can handle required tasks in real world
scenarios, according to specifications.
UAT is one of the final and critical software project procedures
that must occur before newly developed software is rolled out to
the market.
UAT is also known as beta testing, application testing or end
user testing.
Steps Involved in In-House UAT
●

●

●

●

●

Planning: The UAT strategy is outlined during the planning step.
Designing test cases: Test cases are designed to cover all the
functional scenarios of the software in real-world usage.
Executing test cases and documenting: The testing team executes the
designed test cases. All bugs are logged in a testing document with
relevant comments.
Bug fixing: Responding to the bugs found by the testing team, the
software development team makes final adjustments to the code to
make the software bug-free.
Sign-off: When all bugs have been fixed, the testing team indicates
acceptance of the software application. This shows that the application
meets user requirements and is ready to be rolled out in the market.
Importance of UAT
●

●

UAT is important because it helps demonstrate that required
business functions are operating in a manner suited to realworld circumstances and usage.
UAT is an effective process with a high rate of return for those
who take the time to implement and follow its discipline.
How Selenium Work
Common Problem in Web Testing
●

Record/replay is not reusable, is fragile.

●

Managing test cases.

●

UI changesmake tests brittle.
ScalaTest Using Selenium
●

●

ScalaTest 2.0 includes a domain specific language (DSL) for writing
browser-based tests using Selenium.
To use ScalaTest's Selenium DSL, you'll first need to add Selenium to
your project dependencies. For example, in your sbt build you might
add:
libraryDependencies += "org.seleniumhq.selenium" % "seleniumjava" % "2.23.1" % "test->default"

●

Mix trait WebBrowser into your test class.This trait provides the DSL
in its entirety except for one missing piece : an implicit
org.openqa.selenium.WebDriver
Element Locator
●

ID: id=foo

●

Name: name=foo

●

First ID, then name: identifier=foo

●

DOM: document.forms[‘myform’].myDropdown

●

XPath: xpath=//table[@id='table1']//tr[4]/td[2]

●

Link Text: link=sometext

●

CSS Selector: css=a[href=“#id3”]

●

Sensible defaults, e.g. xpath if starts with //
Example of UAT
class BlogSpec extends FlatSpec with ShouldMatchers with
WebBrowser {
implicit val webDriver: WebDriver = new HtmlUnitDriver
val host = "http://localhost:9000/"
"The blog app home page" should "have the correct title" in {
go to (host + "index.html")
pageTitle should be ("Awesome Blog")
}
}
Terms of Test Cases
●

Navigation:
You can ask the browser to retrieve a page (go to a URL) like this:
go to "http://www.artima.com"

●

Checking input element values:
textField("q").value should be ("Cheese!")
textArea("body").value should be ("I saw something cool today!")

●

Implicit wait :
implicitlyWait(Span(10, Seconds))

●

Cleaning up:
To close all windows, and exit the driver, use quit:
quit()
Test Code of Autocomplete
Functionality
●

Define the autocomplete test code in a trait so that it will be use by all the test class which extends this trait :
trait Reattempt {
def attemptOrReattempAutoComplete(func: By => WebElement, selector: String, searchText: String,Text: String, startWithCount:
Int, maxNumberOfRetries: Int = 5): Unit = {
if (startWithCount <= maxNumberOfRetries && searchText.length > 0) {
func(By.cssSelector(selector)).clear
func(By.cssSelector(selector)).sendKeys(searchText)
try {
if(searchText == Text) {
func(By.cssSelector(“refrence of div where this search text element present")).click
} else {
func(By.cssSelector("refrence of div where this search text element presen")).sendKeys(Keys.ARROW_UP)
}
} catch {
case e: TimeoutException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0, searchText.length 1),Text: String, startWithCount + 1, maxNumberOfRetries)
case e: ElementNotVisibleException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0,
searchText.length - 1), Text: String, startWithCount + 1, maxNumberOfRetries)
}
}
}
}
Sequentially Running Test
To run the whole test cases sequentially we
have to put this line in build.sbt
“parallelExecution in Test := false
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
parallelExecution in ScctPlugin.ScctTest := false”
Command For Run Acceptace Test
●

To run single test
sbt “test-only packageName.className”

●

To run whole test
sbt test

●

To check the coverage report
sbt scct:test
Selenium Test in Headless Mode
with Xvfb
●

➢

Follow the following steps to configure Xvfb
(Virtual Framebuffer) to run test cases:
install Xvfb on ubuntu using following
command :
sudo apt-get install xvfb

➢

Create .sh file in root /etc/init.d/ folder and
paste the following script code in the script (.sh)
file:
XVFB=/usr/bin/Xvfb
XVFBARGS=":1 -screen 0 1024x768x24 +extension GLX +render -noreset -nolisten tcp"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac

exit 0
Selenium Test in Headless Mode
with Xvfb
●

Now,open the terminal and go to your project
and run :
Xvfb :1 -screen 0 1920x1080x24 +extension
GLX +render -noreset -nolisten tcp

●

and open another tab of terminal and go to your
project and run :
export DISPLAY=:1
sbt test
Thank You

More Related Content

What's hot (20)

PDF
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PPTX
Selenium ppt
Aneesh Rangarajan
 
PDF
Selenium presentation
P.V.G'S COET, PUNE - 09
 
PPTX
Automation - web testing with selenium
Tzirla Rozental
 
PPTX
Automated UI testing done right (DDDSydney)
Mehdi Khalili
 
PPTX
Selenium web driver
Roman Savitskiy
 
DOCX
Selenium WebDriver FAQ's
Praveen Gorantla
 
PDF
Selenium - Introduction
Amr E. Mohamed
 
PDF
Selenium Tutorial
prad_123
 
PPTX
Protractor Testing Automation Tool Framework / Jasmine Reporters
Haitham Refaat
 
PDF
Test automation - Building effective solutions
Artem Nagornyi
 
PPTX
Selenium web driver
Sun Technlogies
 
PDF
Automation Testing using Selenium
Naresh Chintalcheru
 
PPT
Selenium ide material (1)
Sriram Angajala
 
PPT
Selenium
Kalyan ch
 
PDF
Selenium IDE LOCATORS
Mindfire Solutions
 
PDF
Automation Testing using Selenium Webdriver
Pankaj Biswas
 
PPTX
Selenium Automation
Anuradha Malalasena
 
PPT
selenium training | selenium course | selenium video tutorial | selenium for ...
Nancy Thomas
 
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs
 
Test Automation and Selenium
Karapet Sarkisyan
 
Selenium ppt
Aneesh Rangarajan
 
Selenium presentation
P.V.G'S COET, PUNE - 09
 
Automation - web testing with selenium
Tzirla Rozental
 
Automated UI testing done right (DDDSydney)
Mehdi Khalili
 
Selenium web driver
Roman Savitskiy
 
Selenium WebDriver FAQ's
Praveen Gorantla
 
Selenium - Introduction
Amr E. Mohamed
 
Selenium Tutorial
prad_123
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Haitham Refaat
 
Test automation - Building effective solutions
Artem Nagornyi
 
Selenium web driver
Sun Technlogies
 
Automation Testing using Selenium
Naresh Chintalcheru
 
Selenium ide material (1)
Sriram Angajala
 
Selenium
Kalyan ch
 
Selenium IDE LOCATORS
Mindfire Solutions
 
Automation Testing using Selenium Webdriver
Pankaj Biswas
 
Selenium Automation
Anuradha Malalasena
 
selenium training | selenium course | selenium video tutorial | selenium for ...
Nancy Thomas
 

Viewers also liked (15)

PPTX
Scaladays 2014 introduction to scalatest selenium dsl
Matthew Farwell
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PPT
Selenium
conect2krish
 
PPT
Selenium
tanvir afzal
 
PDF
Monitoring web application behaviour with cucumber-nagios
Lindsay Holmwood
 
PPT
Test automation using selenium presented by Quontra Solutions
QUONTRASOLUTIONS
 
PPT
Test automation using selenium
shreyas JC
 
PPTX
Selenium and Appium Training from Sauce Labs
Sauce Labs
 
PDF
Fullstack End-to-end test automation with Node.js, one year later
Mek Srunyu Stittri
 
PDF
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
PPT
Selenium
Sun Technlogies
 
PDF
Selenium Basics Tutorial
Clever Moe
 
PPT
Selenium Concepts
Swati Bansal
 
PPT
Selenium ppt
Pavan Kumar
 
Scaladays 2014 introduction to scalatest selenium dsl
Matthew Farwell
 
Introduction to Selenium Web Driver
Return on Intelligence
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Selenium
conect2krish
 
Selenium
tanvir afzal
 
Monitoring web application behaviour with cucumber-nagios
Lindsay Holmwood
 
Test automation using selenium presented by Quontra Solutions
QUONTRASOLUTIONS
 
Test automation using selenium
shreyas JC
 
Selenium and Appium Training from Sauce Labs
Sauce Labs
 
Fullstack End-to-end test automation with Node.js, one year later
Mek Srunyu Stittri
 
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
Selenium
Sun Technlogies
 
Selenium Basics Tutorial
Clever Moe
 
Selenium Concepts
Swati Bansal
 
Selenium ppt
Pavan Kumar
 
Ad

Similar to Integrating Selenium testing infrastructure into Scala Project (20)

PPT
Selenium ide material (2)
Sriram Angajala
 
DOCX
What is selenium
Pesara Swamy
 
PPTX
Selenium
nil65
 
PPT
Selenium
Daksh Sharma
 
PPTX
Selenium
Rakshitha Raviprakash
 
PPTX
Selenium
Batch2016
 
PPTX
Selenium
Batch2016
 
PPTX
Selenium
Batch2016
 
PPT
Selenium (1) (1)
Vishwan Aranha
 
PPTX
Selenium
Ivan Aranha
 
PPT
Selenium Primer
gueste1e4db
 
PPTX
Selenium ui paradigm - DDD North 2
Nathan Gloyn
 
PPTX
Selenium Testing
Shreshtt Bhatt
 
PPTX
Automated Web Testing With Selenium
Jodie Miners
 
PPTX
Learn SELENIUM at ASIT
ASIT
 
ODP
Selenium ppt
Anirudh Raja
 
PPT
Selenium Introduction
Mayur Khairnar
 
PPT
Selenium
BugRaptors
 
PPTX
Selenium- A Software Testing Tool
Zeba Tahseen
 
PPTX
Selenium training
Suresh Arora
 
Selenium ide material (2)
Sriram Angajala
 
What is selenium
Pesara Swamy
 
Selenium
nil65
 
Selenium
Daksh Sharma
 
Selenium
Batch2016
 
Selenium
Batch2016
 
Selenium
Batch2016
 
Selenium (1) (1)
Vishwan Aranha
 
Selenium
Ivan Aranha
 
Selenium Primer
gueste1e4db
 
Selenium ui paradigm - DDD North 2
Nathan Gloyn
 
Selenium Testing
Shreshtt Bhatt
 
Automated Web Testing With Selenium
Jodie Miners
 
Learn SELENIUM at ASIT
ASIT
 
Selenium ppt
Anirudh Raja
 
Selenium Introduction
Mayur Khairnar
 
Selenium
BugRaptors
 
Selenium- A Software Testing Tool
Zeba Tahseen
 
Selenium training
Suresh Arora
 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 

Recently uploaded (20)

PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Python basic programing language for automation
DanialHabibi2
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
July Patch Tuesday
Ivanti
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 

Integrating Selenium testing infrastructure into Scala Project

  • 2. History of The Selenium ● ● Selenium is invent by Jason Huggins He developed a Javascript library that could drive interactions with the page, allowing him to automatically rerun tests against multiple browsers.
  • 3. Test Automation ● Test automation is the use of software To set test preconditions. To control the execution of tests. To compare the actual outcomes to predicted outcomes. To report the Execution Status. ● Commonly, test automation involves automating a manual process already in place that uses a formalized testing process.
  • 4. Why and When To Automate? Frequent regression testing ● Repeated test case Execution is required ● User Acceptance Tests ● Faster Feedback to the developers ● Reduce the Human Effort ● Test same application on multiple environments ●
  • 5. Selenium ● ● ● Selenium is a robust set of tools that supports rapid development of test automation for web-based applications. Selenium provides a rich set of testing functions specifically geared to the needs of testing of a web application. Selenium operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior.
  • 6. Selenium Features ● ● ● ● ● ● Supports Cross Browser Testing. The Selenium tests can be run on multiple browsers. Allows scripting in several languages like Java, C#, PHP and Python. Ajax/CSS support. Assertion statements provide an efficient way of comparing expected and actual results. Inbuilt reporting mechanism. Selenium is an open source tool
  • 7. Selenium Components ● Selenium IDE ● Selenium Remote Control ● Selenium Grid
  • 8. Selenium IDE ● ● ● ● ● ● Previously known as Selenium Recorder Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and replay the test in firefox Selenium IDE allows you to save tests as HTML, Java, Ruby scripts, or any other format It allows you to automatically add assertions to all the pages. Allows you to add selenese commands as and when required
  • 9. Selence ● ● Selence special test scripting language for Selenium. Selenese provides commands for performing actions in a browser (click a link, select an option), and for retrieving data from the resulting pages.
  • 10. Selenium IDE Installation ● First download Mozilla Firefox browser. ● Click on the Firefox tab present at the top the browser window. ● In drop down menu click on Add-on. ● Go to add on page of Mozilla Firefox browser ● In the search box of Add on page search the term "Selenium IDE" and press enter ● Click on more link to the Selenium IDE add-on ● Go to http://docs.seleniumhq.org/download/ ● Once installation is done the Mozilla Firefox browser will ask you to restart the browser.Just Restart it.
  • 11. Selenium IDE - UI Start and Stop Recording Replay Toolbar Editor Accessor Area Selenese Script Editor Selenium Log
  • 12. Recoding a Selenium Test Case ● ● ● ● ● ● Open Firefox that has the IDE installed Open the base URL of the application to record. Keep the application in a common base state. Go To Tools  Selenium IDE and the IDE will be opened Now perform the operations on the application as you are testing the application. Once you are done with the recording click on the stop recording button and save the test case through the file menu. By default it will be saved as a selenese script (HTML format)
  • 13. Creating a Test Suite ● ● In the Selenium IDE you can create any number of test cases and save them as test suite. To Run the test Suite click on the “Play entire test suite” button as shown below. Test Suite with Test1 & test2
  • 14. Running Options Run a Test Case Click the Run button to run the currently displayed test case. Run a Test Suite Click the Run All button to run all the test cases in the currently loaded test suite. Stop and Start The Pause button can be used to stop the test case while it is running. The icon of this button then changes to indicate the Resume button. To continue click Resume.
  • 15. Adding Assertions to the Script ● Selenese allows multiple ways of checking for UI elements. ● Verifications and assertions are used to check if ● an element is present somewhere on the page? ● specific text is somewhere on the page? ● specific text is at a specific location on the page? ● Verifications and assertions are not one and the same. ● If an assertion fails, the script will be aborted but if a verification fails the script will continue.
  • 16. Assertion Statements ● ● ● ● ● assertTextPresent This will assert if the text is present in the page. assertText This will assert if a particular element is having the particular text. assertTitle This will assert if the page is having a proper title. assertValue This will assert if a Text box or check box has a particular value assertElementPresent This will assert if a particular UI Element is present in the page.
  • 17. User Acceptance Testing (UAT) ● ● ● User Acceptance Testing (UAT) is the last phase of the software testing process. During UAT, actual software users test the software to make sure it can handle required tasks in real world scenarios, according to specifications. UAT is one of the final and critical software project procedures that must occur before newly developed software is rolled out to the market. UAT is also known as beta testing, application testing or end user testing.
  • 18. Steps Involved in In-House UAT ● ● ● ● ● Planning: The UAT strategy is outlined during the planning step. Designing test cases: Test cases are designed to cover all the functional scenarios of the software in real-world usage. Executing test cases and documenting: The testing team executes the designed test cases. All bugs are logged in a testing document with relevant comments. Bug fixing: Responding to the bugs found by the testing team, the software development team makes final adjustments to the code to make the software bug-free. Sign-off: When all bugs have been fixed, the testing team indicates acceptance of the software application. This shows that the application meets user requirements and is ready to be rolled out in the market.
  • 19. Importance of UAT ● ● UAT is important because it helps demonstrate that required business functions are operating in a manner suited to realworld circumstances and usage. UAT is an effective process with a high rate of return for those who take the time to implement and follow its discipline.
  • 21. Common Problem in Web Testing ● Record/replay is not reusable, is fragile. ● Managing test cases. ● UI changesmake tests brittle.
  • 22. ScalaTest Using Selenium ● ● ScalaTest 2.0 includes a domain specific language (DSL) for writing browser-based tests using Selenium. To use ScalaTest's Selenium DSL, you'll first need to add Selenium to your project dependencies. For example, in your sbt build you might add: libraryDependencies += "org.seleniumhq.selenium" % "seleniumjava" % "2.23.1" % "test->default" ● Mix trait WebBrowser into your test class.This trait provides the DSL in its entirety except for one missing piece : an implicit org.openqa.selenium.WebDriver
  • 23. Element Locator ● ID: id=foo ● Name: name=foo ● First ID, then name: identifier=foo ● DOM: document.forms[‘myform’].myDropdown ● XPath: xpath=//table[@id='table1']//tr[4]/td[2] ● Link Text: link=sometext ● CSS Selector: css=a[href=“#id3”] ● Sensible defaults, e.g. xpath if starts with //
  • 24. Example of UAT class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser { implicit val webDriver: WebDriver = new HtmlUnitDriver val host = "http://localhost:9000/" "The blog app home page" should "have the correct title" in { go to (host + "index.html") pageTitle should be ("Awesome Blog") } }
  • 25. Terms of Test Cases ● Navigation: You can ask the browser to retrieve a page (go to a URL) like this: go to "http://www.artima.com" ● Checking input element values: textField("q").value should be ("Cheese!") textArea("body").value should be ("I saw something cool today!") ● Implicit wait : implicitlyWait(Span(10, Seconds)) ● Cleaning up: To close all windows, and exit the driver, use quit: quit()
  • 26. Test Code of Autocomplete Functionality ● Define the autocomplete test code in a trait so that it will be use by all the test class which extends this trait : trait Reattempt { def attemptOrReattempAutoComplete(func: By => WebElement, selector: String, searchText: String,Text: String, startWithCount: Int, maxNumberOfRetries: Int = 5): Unit = { if (startWithCount <= maxNumberOfRetries && searchText.length > 0) { func(By.cssSelector(selector)).clear func(By.cssSelector(selector)).sendKeys(searchText) try { if(searchText == Text) { func(By.cssSelector(“refrence of div where this search text element present")).click } else { func(By.cssSelector("refrence of div where this search text element presen")).sendKeys(Keys.ARROW_UP) } } catch { case e: TimeoutException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0, searchText.length 1),Text: String, startWithCount + 1, maxNumberOfRetries) case e: ElementNotVisibleException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0, searchText.length - 1), Text: String, startWithCount + 1, maxNumberOfRetries) } } } }
  • 27. Sequentially Running Test To run the whole test cases sequentially we have to put this line in build.sbt “parallelExecution in Test := false concurrentRestrictions in Global += Tags.limit(Tags.Test, 1) parallelExecution in ScctPlugin.ScctTest := false”
  • 28. Command For Run Acceptace Test ● To run single test sbt “test-only packageName.className” ● To run whole test sbt test ● To check the coverage report sbt scct:test
  • 29. Selenium Test in Headless Mode with Xvfb ● ➢ Follow the following steps to configure Xvfb (Virtual Framebuffer) to run test cases: install Xvfb on ubuntu using following command : sudo apt-get install xvfb ➢ Create .sh file in root /etc/init.d/ folder and paste the following script code in the script (.sh) file:
  • 30. XVFB=/usr/bin/Xvfb XVFBARGS=":1 -screen 0 1024x768x24 +extension GLX +render -noreset -nolisten tcp" PIDFILE=/var/run/xvfb.pid case "$1" in start) echo -n "Starting virtual X frame buffer: Xvfb" start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS echo "." ;; stop) echo -n "Stopping virtual X frame buffer: Xvfb" start-stop-daemon --stop --quiet --pidfile $PIDFILE echo "." ;; restart) $0 stop $0 start ;; *) echo "Usage: /etc/init.d/xvfb {start|stop|restart}" exit 1 esac exit 0
  • 31. Selenium Test in Headless Mode with Xvfb ● Now,open the terminal and go to your project and run : Xvfb :1 -screen 0 1920x1080x24 +extension GLX +render -noreset -nolisten tcp ● and open another tab of terminal and go to your project and run : export DISPLAY=:1 sbt test