SlideShare a Scribd company logo
Selenium testing - Handle Elements in WebDriver
Test Web applicationsTest Web applications
using Seleniumusing Selenium
Design By :- Vibrant Technologies
& computers
OutlineOutline
• Uniqueness of web app testing
o Heterogonous system
o Dynamic pages
o Load
o Security
• Selenium WebDriver
• Course project 4
Web application architectureWeb application architecture
• Heterogeneous system
o Front end
• Browser: IE, Firefox,
Chrome, Safari…
o Server side
• Application Server
• Database Server
• File System
• ……
Heterogeneous systemHeterogeneous system
HTMHTM
JavaScrptJavaScrpt
Page in BrowserPage in Browser
Source behindSource behind
Uniqueness 1: Heterogeneous systemUniqueness 1: Heterogeneous system
• Server side
o Can be written in PHP, Java, C#...
o Communicate with Database server in SQL
PHP ScriptPHP Script
SQLSQL
HTMLHTML
SQLSQL
PHPPHP
Heterogeneous systemHeterogeneous system
• Should test all involved parts
o Everything can go wrong…
• However, only front end is accessible for tests
o Can not directly test the Server code and SQL
o Have to drive the execution and test
• Frontend
o HTML: Malformed HTML page? (demo)
o JavaScript: Runtime Errors? (demo)
• Server script
o PHP, Java…: Runtime Errors? (demo)
o SQL: Malformed SQL query string? (demo)
Test from the front endTest from the front end
• Good things
o Hide the complexity of the backend
o Uniformed interface
o Can put a robot in the front end and automate the tests
 Bad things
o The front end is not trustable
• Crafted malicious requests
Good things of testing from the front endGood things of testing from the front end
• Automated web app testing
o Compare to commend-line program testing…
• Sensitive to input values (the same)
• GUI testing: event driven (the difference)
o “Button A” then “Button B”  OK
o “Button B” then “Button A”  FAIL
o The robot should be able to
• Provide input values
• Simulate user actions
• Selenium
o A tool set automates web app testing across platforms
o Can simulate user interactions in browser
o Two components
• Selenium IDE
• Selenium WebDriver (aka. Selenium 2)
Selenium IDESelenium IDE
• Firefox extension
• Easy record and replay
• Debug and set breakpoints
• Save tests in HTML,
WebDriver and other
formats.
Selenium IDE test casesSelenium IDE test cases
• Selenium saves all information in an HTML table format
• Each record consists of:
o Command – tells Selenium what to do (e.g. “open”, “type”,
“click”, “verifyText”)
o Target – tells Selenium which HTML element a command refers to
(e.g. textbox, header, table)
o Value – used for any command that might need a value of some
kind (e.g. type something into a textbox)
How to record/replay with Selenium IDEHow to record/replay with Selenium IDE
1. Start recording in Selenium IDE
2. Execute scenario on running web application
3. Stop recording in Selenium IDE
4. Verify / Add assertions
5. Replay the test.
Selenium IDE Demo……
Bad things of testing from the front endBad things of testing from the front end
• The front end is not trustable
o Front end code can be accessed to anybody
o They can infer the input parameters
o Crafted requests!
• Demo
o Front end limits the length of the input values
o Front end limits the content of the input values
o Front end limits the combination of the input values
Uniqueness 2: Dynamic pagesUniqueness 2: Dynamic pages
• Client page is dynamic
o It can change itself in the runtime
o HTML can be modified by JavaScript
o JavaScript can modify itself
o Demo
• Server script is dynamic
o Client pages are constructed in the runtime
o A same server script can produce completely different client pages
o Demo
• SchoolMate
Uniqueness 3: PerformanceUniqueness 3: Performance
• Performance is crucial to the success of a web app
o Recall the experience to register for a class in the first days of the semester…
o Are the servers powerful enough?
• Performance testing evaluates system performance under normal and
heavy usage
o Load testing
• For expected concurrent number of users
o Stress testing
• To understand the upper limits of capacity
• Performance testing can be automated
Uniqueness 4: SecurityUniqueness 4: Security
• Web app usually deals with sensitive info, e.g.
o Credit card number
o SSN
o Billing / Shipping address
• Security is the biggest concern
• Security testing should simulate possible attacks
Uniqueness 4: SecurityUniqueness 4: Security
• SQL Injection
o The untrusted input is used to construct dynamic SQL queries.
o E.g, update my own password
$str = "UPDATE users SET password = ” “ . $_POST['newPass’] .
“” WHERE username =”“ . $_POST['username'] . “””;
mysql_query( $str );
$_POST['newPass’] = pass, $_POST['username'] = me
Query String: UPDATE users SET password = “pass” WHERE username =“me”
$_POST['newPass’] = pass, $_POST['username'] = “ OR 1=1 --
Query String: UPDATE users SET password = “pass” WHERE username =“” OR 1=1 --”
Normal CaseNormal Case
AttackAttack
PHP ScriptPHP Script
Uniqueness 4: SecurityUniqueness 4: Security
• Cross Site Scripting (XSS)
o The untrusted input is used to construct dynamic HTML pages.
o The malicious JS injected executes in victim’s browser
o The malicious JS can steal sensitive info
o Demo
• Solution: Never trust user inputs
• Design test cases to simulate attacks
OutlineOutline
• Uniqueness of web app testing
o Heterogonous system
o Dynamic pages
o Load
o Security
• Selenium WebDriver
• Course project 4
Limitation of Selenium IDELimitation of Selenium IDE
• No multiple browsers support
o It runs only in Mozilla Firefox.
• No manual scripts
o E.g. conditions and Loops for Data Driven Testing
• Fancy test cases  Selenium WebDriver
Selenium WebDriver (Selenium 2)Selenium WebDriver (Selenium 2)
• Selenium-WebDriver
o A piece of program
o Control the browser by programming
o More flexible and powerful
• Selenium-WebDriver supports multiple browsers in multiple
platforms
o Google Chrome 12.0.712.0+
o Internet Explorer 6+
o Firefox 3.0+
o Opera 11.5+
o Android – 2.3+ for phones and tablets
o iOS 3+ for phones
o iOS 3.2+ for tablets
Selenium WebDriverSelenium WebDriver
• WebDriver is designed to providing a simpler and
uniformed programming interface
o Same WebDriver script runs for different platforms
• Support multiple programming language:
o Java, C#, Python, Ruby, PHP, Perl…
• It’s efficient
o WebDriver leverages each browser’s native support for automation.
What Selenium can doWhat Selenium can do
• A solution for the automated testing
o Simulate user actions
o Functional testing
• Create regression tests to verify functionality and user acceptance.
o Browser compatibility testing
• The same script can run on any Selenium platform
o Load testing
o Stress testing
How to use Selenium WebDriverHow to use Selenium WebDriver
(1) Go to a page
(2) Locate an element
(3) Do something with that element
......
(i) Locate an element
(i+1) Do something with that element
(i+2) Verify / Assert the result
DemoDemo: Verify page title: Verify page titlepublic static void main( String[] args )
{
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
// (1) Go to a page
driver.get("http://www.google.com");
// (2) Locate an element
WebElement element = driver.findElement(By.name("q"));
// (3-1) Enter something to search for
element.sendKeys("Purdue Univeristy");
// (3-2) Now submit the form. WebDriver will find the form for us from the element
element.submit();
// (3-3) Wait up to 10 seconds for a condition
WebDriverWait waiting = new WebDriverWait(driver, 10);
waiting.until( ExpectedConditions.presenceOfElementLocated( By.id("pnnext") ) );
// (4) Check the title of the page
if( driver.getTitle().equals("purdue univeristy - Google Search") )
System.out.println("PASS");
else
System.err.println("FAIL");
//Close the browser
driver.quit();
}
How to locate an elementHow to locate an element
• By id
o HTML: <div id="coolestWidgetEvah">...</div>
o WebDriver:
driver.findElement( By.id("coolestWidgetEvah") );
• By name
o HTML: <input name="cheese" type="text"/>
o WebDriver: driver.findElement( By.name("cheese") );
• By Xpath
o HTML
<html>
<input type="text" name="example" />
<input type="text" name="other" />
</html>
o WebDriver: driver.findElements( By.xpath("//input") );
o There are plug-ins for firefox/chrome to automatically display the Xpath
Time issueTime issue
• There are delays between submitting a request and receiving the
response
• We can wait until the response page is loaded
• Robot doesn’t know!
• In WebDriver, sometimes it doesn’t work if
o Submit a request
o Verify the response immediately
• Solution:
o Simulate the wait. Wait until some HTML object appears
o Demo
OutlineOutline
• What to test for a web application
• Test web app with selenium
o What’s Selenium?
o Why Selenium?
o How to use Selenium
• Course project 4
Course Project 4Course Project 4
• Test a functionality
without the source
• The subject web
application
o “Add New Class” in
“SchoolMate”
Course Project 4Course Project 4
• Part 1: overview
o Design test cases against the requirement
• The tests should consider
o all possible cases
o equivalence class partitioning
o Implement Selenium WebDriver Script for “Add new class”
Your testYour test
casescases
Your testYour test
casescases
Your WebDriverYour WebDriver
test templatetest template
Your WebDriverYour WebDriver
test templatetest template
inputinputinputinput outputoutputoutputoutput
TestTest
resultsresults
TestTest
resultsresults
Part 1: requirement analysisPart 1: requirement analysis
• Requirement for values
entered/selected
o [R-1] Class Name : alphabets
and numbers are allowed.
o [R-2] Section Number : only
numbers are allowed.
o [R-3] Room Number : only
numbers are allowed.
o [R-4] Period Number : only
numbers are allowed.
o [R-5] All textbox fields : no
Cross-Site Scripting (XSS)
injection vulnerabilities.
Part 1: requirement analysisPart 1: requirement analysis
• Requirement for the “add” function
• After clicking the “Add class” button…
o [R-6] The class record added is successfully shown in the table.
o [R-7] The values are exactly the same as those were entered or selected.
Part 1:Design testcasesPart 1:Design testcases
• For each requirement, design test cases
• Only need test one field in each case
o Do not need consider combinations of fileds
• E.g.
o [R-1] Class Name : alphabets and numbers are allowed.
o You need consider all possible cases
o Divide the test space and find the equivalence class
• Alphabets
• Numbers
• ….
• The test case format is defined
o Test cases will be used as input to your WebDriver Script
Part 1: Implement WebDriver ScriptPart 1: Implement WebDriver Script
• In WebDriver script, Simulate the user action
o Navigate to the subject page
o Enter values into textboxs based on input values
o Select options based on input values
o Click the “add class” button
o Check the result against the requirements
• Run all your test cases and report the results.
Course Project 4Course Project 4
• Part 2: Pair wise testing
o Use an existing pair wise testing tool fire-eye
o Largely you may reuse the WebDriver template in
Part 1
Your testYour test
casescases
Your testYour test
casescases
Your WebDriverYour WebDriver
test templatetest template
Your WebDriverYour WebDriver
test templatetest template
inputinputinputinput outputoutputoutputoutput
TestTest
resultresult
TestTest
resultresult
Test casesTest cases
generatedgenerated
Test casesTest cases
generatedgenerated
ConvertConvertConvertConvert
Part 2: Generate test casesPart 2: Generate test cases
• Consider the combination of all textboxs/options
• Use the existing tool, fire-eye, to generate test cases
• Export the test case in “Nist form”
• Parse and convert the exported test cases to the form
that your WebDriver can accept
• Run all pair-wise test cases
• Report the result
Part 2: Solution designPart 2: Solution design
• Selenium can do more …
• Black Friday is coming, hot items can be sold in a few seconds
• Can you leverage the automated tool and design a practical solution to score a super
hot deal?
• Explain
o What’s the challenge
o What’s the possible cases to handle and how?
• In stock
• Out of stock
• Your shopping cart may be reset under what conditions…
o How to add it into your shopping cart asap
o How you are going to cooperate with the automated tool
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/selenium-classes-in-mu

More Related Content

PPT
PPT
Selenium
PDF
Selenium Introduction by Sandeep Sharda
PDF
Testing mit Codeception: Full-stack testing PHP framework
PPTX
Web driver training
PDF
Selenium webdriver
PDF
Introduction to Selenium and Ruby
PDF
Foundation selenium java
Selenium
Selenium Introduction by Sandeep Sharda
Testing mit Codeception: Full-stack testing PHP framework
Web driver training
Selenium webdriver
Introduction to Selenium and Ruby
Foundation selenium java

What's hot (20)

DOC
Selenium Automation Using Ruby
PPTX
Basic Selenium Training
PDF
Selenide
PDF
PDF
Expert selenium with core java
PPT
Automated Testing With Watir
PDF
Webdriver cheatsheets summary
PDF
Automation Abstraction Layers: Page Objects and Beyond
PDF
Join the darkside: Selenium testing with Nightwatch.js
PDF
Interview Question & Answers for Selenium Freshers | LearningSlot
PDF
jQuery Proven Performance Tips & Tricks
PPTX
Hacking Wordpress Plugins
PPTX
Intro to Pentesting Jenkins
DOCX
Selenium WebDriver FAQ's
PPTX
Pentesting Modern Web Apps: A Primer
PDF
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
PPT
Introduction To Ruby Watir (Web Application Testing In Ruby)
PPTX
Introduction to Selenium Web Driver
PDF
Tellurium.A.New.Approach.For.Web.Testing
PDF
Tellurium At Rich Web Experience2009
Selenium Automation Using Ruby
Basic Selenium Training
Selenide
Expert selenium with core java
Automated Testing With Watir
Webdriver cheatsheets summary
Automation Abstraction Layers: Page Objects and Beyond
Join the darkside: Selenium testing with Nightwatch.js
Interview Question & Answers for Selenium Freshers | LearningSlot
jQuery Proven Performance Tips & Tricks
Hacking Wordpress Plugins
Intro to Pentesting Jenkins
Selenium WebDriver FAQ's
Pentesting Modern Web Apps: A Primer
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Introduction To Ruby Watir (Web Application Testing In Ruby)
Introduction to Selenium Web Driver
Tellurium.A.New.Approach.For.Web.Testing
Tellurium At Rich Web Experience2009
Ad

Similar to Selenium testing - Handle Elements in WebDriver (20)

PPT
selenium.ppt
PPT
selenium.ppt
PPT
selenium.ppt
PPT
Selenium
PPT
By combining Selenium for frontend testing and tools
PPTX
4&5.pptx SOFTWARE TESTING UNIT-4 AND UNIT-5
PPTX
Selenium Automation
PPTX
Web UI Tests: Introduce UI tests using Selenium
PPTX
Selenium web driver
PDF
Selenium -Test automation for web applications
PPTX
Selenium WebDriver - Test automation for web applications
PPT
Selenium
PPTX
Selenium.pptx
PDF
Intelligent Testing Tool: Selenium Web Driver
PPTX
Test automation using selenium
ODP
Integrating Selenium testing infrastructure into Scala Project
PPT
Selenium Concepts
PPTX
Selenium web driver
PDF
How To Use Selenium Successfully
PPTX
Web Testing
selenium.ppt
selenium.ppt
selenium.ppt
Selenium
By combining Selenium for frontend testing and tools
4&5.pptx SOFTWARE TESTING UNIT-4 AND UNIT-5
Selenium Automation
Web UI Tests: Introduce UI tests using Selenium
Selenium web driver
Selenium -Test automation for web applications
Selenium WebDriver - Test automation for web applications
Selenium
Selenium.pptx
Intelligent Testing Tool: Selenium Web Driver
Test automation using selenium
Integrating Selenium testing infrastructure into Scala Project
Selenium Concepts
Selenium web driver
How To Use Selenium Successfully
Web Testing
Ad

More from Vibrant Technologies & Computers (20)

PPT
Buisness analyst business analysis overview ppt 5
PPT
SQL Introduction to displaying data from multiple tables
PPT
SQL- Introduction to MySQL
PPT
SQL- Introduction to SQL database
PPT
ITIL - introduction to ITIL
PPT
Salesforce - Introduction to Security & Access
PPT
Data ware housing- Introduction to olap .
PPT
Data ware housing - Introduction to data ware housing process.
PPT
Data ware housing- Introduction to data ware housing
PPT
Salesforce - classification of cloud computing
PPT
Salesforce - cloud computing fundamental
PPT
SQL- Introduction to PL/SQL
PPT
SQL- Introduction to advanced sql concepts
PPT
SQL Inteoduction to SQL manipulating of data
PPT
SQL- Introduction to SQL Set Operations
PPT
Sas - Introduction to designing the data mart
PPT
Sas - Introduction to working under change management
PPT
SAS - overview of SAS
PPT
Teradata - Architecture of Teradata
PPT
Teradata - Restoring Data
Buisness analyst business analysis overview ppt 5
SQL Introduction to displaying data from multiple tables
SQL- Introduction to MySQL
SQL- Introduction to SQL database
ITIL - introduction to ITIL
Salesforce - Introduction to Security & Access
Data ware housing- Introduction to olap .
Data ware housing - Introduction to data ware housing process.
Data ware housing- Introduction to data ware housing
Salesforce - classification of cloud computing
Salesforce - cloud computing fundamental
SQL- Introduction to PL/SQL
SQL- Introduction to advanced sql concepts
SQL Inteoduction to SQL manipulating of data
SQL- Introduction to SQL Set Operations
Sas - Introduction to designing the data mart
Sas - Introduction to working under change management
SAS - overview of SAS
Teradata - Architecture of Teradata
Teradata - Restoring Data

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
madgavkar20181017ppt McKinsey Presentation.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
NewMind AI Weekly Chronicles - August'25 Week I
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
NewMind AI Monthly Chronicles - July 2025
Advanced Soft Computing BINUS July 2025.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Sensors and Actuators in IoT Systems using pdf
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks

Selenium testing - Handle Elements in WebDriver

  • 2. Test Web applicationsTest Web applications using Seleniumusing Selenium Design By :- Vibrant Technologies & computers
  • 3. OutlineOutline • Uniqueness of web app testing o Heterogonous system o Dynamic pages o Load o Security • Selenium WebDriver • Course project 4
  • 4. Web application architectureWeb application architecture • Heterogeneous system o Front end • Browser: IE, Firefox, Chrome, Safari… o Server side • Application Server • Database Server • File System • ……
  • 5. Heterogeneous systemHeterogeneous system HTMHTM JavaScrptJavaScrpt Page in BrowserPage in Browser Source behindSource behind
  • 6. Uniqueness 1: Heterogeneous systemUniqueness 1: Heterogeneous system • Server side o Can be written in PHP, Java, C#... o Communicate with Database server in SQL PHP ScriptPHP Script SQLSQL HTMLHTML SQLSQL PHPPHP
  • 7. Heterogeneous systemHeterogeneous system • Should test all involved parts o Everything can go wrong… • However, only front end is accessible for tests o Can not directly test the Server code and SQL o Have to drive the execution and test • Frontend o HTML: Malformed HTML page? (demo) o JavaScript: Runtime Errors? (demo) • Server script o PHP, Java…: Runtime Errors? (demo) o SQL: Malformed SQL query string? (demo)
  • 8. Test from the front endTest from the front end • Good things o Hide the complexity of the backend o Uniformed interface o Can put a robot in the front end and automate the tests  Bad things o The front end is not trustable • Crafted malicious requests
  • 9. Good things of testing from the front endGood things of testing from the front end • Automated web app testing o Compare to commend-line program testing… • Sensitive to input values (the same) • GUI testing: event driven (the difference) o “Button A” then “Button B”  OK o “Button B” then “Button A”  FAIL o The robot should be able to • Provide input values • Simulate user actions • Selenium o A tool set automates web app testing across platforms o Can simulate user interactions in browser o Two components • Selenium IDE • Selenium WebDriver (aka. Selenium 2)
  • 10. Selenium IDESelenium IDE • Firefox extension • Easy record and replay • Debug and set breakpoints • Save tests in HTML, WebDriver and other formats.
  • 11. Selenium IDE test casesSelenium IDE test cases • Selenium saves all information in an HTML table format • Each record consists of: o Command – tells Selenium what to do (e.g. “open”, “type”, “click”, “verifyText”) o Target – tells Selenium which HTML element a command refers to (e.g. textbox, header, table) o Value – used for any command that might need a value of some kind (e.g. type something into a textbox)
  • 12. How to record/replay with Selenium IDEHow to record/replay with Selenium IDE 1. Start recording in Selenium IDE 2. Execute scenario on running web application 3. Stop recording in Selenium IDE 4. Verify / Add assertions 5. Replay the test. Selenium IDE Demo……
  • 13. Bad things of testing from the front endBad things of testing from the front end • The front end is not trustable o Front end code can be accessed to anybody o They can infer the input parameters o Crafted requests! • Demo o Front end limits the length of the input values o Front end limits the content of the input values o Front end limits the combination of the input values
  • 14. Uniqueness 2: Dynamic pagesUniqueness 2: Dynamic pages • Client page is dynamic o It can change itself in the runtime o HTML can be modified by JavaScript o JavaScript can modify itself o Demo • Server script is dynamic o Client pages are constructed in the runtime o A same server script can produce completely different client pages o Demo • SchoolMate
  • 15. Uniqueness 3: PerformanceUniqueness 3: Performance • Performance is crucial to the success of a web app o Recall the experience to register for a class in the first days of the semester… o Are the servers powerful enough? • Performance testing evaluates system performance under normal and heavy usage o Load testing • For expected concurrent number of users o Stress testing • To understand the upper limits of capacity • Performance testing can be automated
  • 16. Uniqueness 4: SecurityUniqueness 4: Security • Web app usually deals with sensitive info, e.g. o Credit card number o SSN o Billing / Shipping address • Security is the biggest concern • Security testing should simulate possible attacks
  • 17. Uniqueness 4: SecurityUniqueness 4: Security • SQL Injection o The untrusted input is used to construct dynamic SQL queries. o E.g, update my own password $str = "UPDATE users SET password = ” “ . $_POST['newPass’] . “” WHERE username =”“ . $_POST['username'] . “””; mysql_query( $str ); $_POST['newPass’] = pass, $_POST['username'] = me Query String: UPDATE users SET password = “pass” WHERE username =“me” $_POST['newPass’] = pass, $_POST['username'] = “ OR 1=1 -- Query String: UPDATE users SET password = “pass” WHERE username =“” OR 1=1 --” Normal CaseNormal Case AttackAttack PHP ScriptPHP Script
  • 18. Uniqueness 4: SecurityUniqueness 4: Security • Cross Site Scripting (XSS) o The untrusted input is used to construct dynamic HTML pages. o The malicious JS injected executes in victim’s browser o The malicious JS can steal sensitive info o Demo • Solution: Never trust user inputs • Design test cases to simulate attacks
  • 19. OutlineOutline • Uniqueness of web app testing o Heterogonous system o Dynamic pages o Load o Security • Selenium WebDriver • Course project 4
  • 20. Limitation of Selenium IDELimitation of Selenium IDE • No multiple browsers support o It runs only in Mozilla Firefox. • No manual scripts o E.g. conditions and Loops for Data Driven Testing • Fancy test cases  Selenium WebDriver
  • 21. Selenium WebDriver (Selenium 2)Selenium WebDriver (Selenium 2) • Selenium-WebDriver o A piece of program o Control the browser by programming o More flexible and powerful • Selenium-WebDriver supports multiple browsers in multiple platforms o Google Chrome 12.0.712.0+ o Internet Explorer 6+ o Firefox 3.0+ o Opera 11.5+ o Android – 2.3+ for phones and tablets o iOS 3+ for phones o iOS 3.2+ for tablets
  • 22. Selenium WebDriverSelenium WebDriver • WebDriver is designed to providing a simpler and uniformed programming interface o Same WebDriver script runs for different platforms • Support multiple programming language: o Java, C#, Python, Ruby, PHP, Perl… • It’s efficient o WebDriver leverages each browser’s native support for automation.
  • 23. What Selenium can doWhat Selenium can do • A solution for the automated testing o Simulate user actions o Functional testing • Create regression tests to verify functionality and user acceptance. o Browser compatibility testing • The same script can run on any Selenium platform o Load testing o Stress testing
  • 24. How to use Selenium WebDriverHow to use Selenium WebDriver (1) Go to a page (2) Locate an element (3) Do something with that element ...... (i) Locate an element (i+1) Do something with that element (i+2) Verify / Assert the result
  • 25. DemoDemo: Verify page title: Verify page titlepublic static void main( String[] args ) { // Create a new instance of the Firefox driver WebDriver driver = new FirefoxDriver(); // (1) Go to a page driver.get("http://www.google.com"); // (2) Locate an element WebElement element = driver.findElement(By.name("q")); // (3-1) Enter something to search for element.sendKeys("Purdue Univeristy"); // (3-2) Now submit the form. WebDriver will find the form for us from the element element.submit(); // (3-3) Wait up to 10 seconds for a condition WebDriverWait waiting = new WebDriverWait(driver, 10); waiting.until( ExpectedConditions.presenceOfElementLocated( By.id("pnnext") ) ); // (4) Check the title of the page if( driver.getTitle().equals("purdue univeristy - Google Search") ) System.out.println("PASS"); else System.err.println("FAIL"); //Close the browser driver.quit(); }
  • 26. How to locate an elementHow to locate an element • By id o HTML: <div id="coolestWidgetEvah">...</div> o WebDriver: driver.findElement( By.id("coolestWidgetEvah") ); • By name o HTML: <input name="cheese" type="text"/> o WebDriver: driver.findElement( By.name("cheese") ); • By Xpath o HTML <html> <input type="text" name="example" /> <input type="text" name="other" /> </html> o WebDriver: driver.findElements( By.xpath("//input") ); o There are plug-ins for firefox/chrome to automatically display the Xpath
  • 27. Time issueTime issue • There are delays between submitting a request and receiving the response • We can wait until the response page is loaded • Robot doesn’t know! • In WebDriver, sometimes it doesn’t work if o Submit a request o Verify the response immediately • Solution: o Simulate the wait. Wait until some HTML object appears o Demo
  • 28. OutlineOutline • What to test for a web application • Test web app with selenium o What’s Selenium? o Why Selenium? o How to use Selenium • Course project 4
  • 29. Course Project 4Course Project 4 • Test a functionality without the source • The subject web application o “Add New Class” in “SchoolMate”
  • 30. Course Project 4Course Project 4 • Part 1: overview o Design test cases against the requirement • The tests should consider o all possible cases o equivalence class partitioning o Implement Selenium WebDriver Script for “Add new class” Your testYour test casescases Your testYour test casescases Your WebDriverYour WebDriver test templatetest template Your WebDriverYour WebDriver test templatetest template inputinputinputinput outputoutputoutputoutput TestTest resultsresults TestTest resultsresults
  • 31. Part 1: requirement analysisPart 1: requirement analysis • Requirement for values entered/selected o [R-1] Class Name : alphabets and numbers are allowed. o [R-2] Section Number : only numbers are allowed. o [R-3] Room Number : only numbers are allowed. o [R-4] Period Number : only numbers are allowed. o [R-5] All textbox fields : no Cross-Site Scripting (XSS) injection vulnerabilities.
  • 32. Part 1: requirement analysisPart 1: requirement analysis • Requirement for the “add” function • After clicking the “Add class” button… o [R-6] The class record added is successfully shown in the table. o [R-7] The values are exactly the same as those were entered or selected.
  • 33. Part 1:Design testcasesPart 1:Design testcases • For each requirement, design test cases • Only need test one field in each case o Do not need consider combinations of fileds • E.g. o [R-1] Class Name : alphabets and numbers are allowed. o You need consider all possible cases o Divide the test space and find the equivalence class • Alphabets • Numbers • …. • The test case format is defined o Test cases will be used as input to your WebDriver Script
  • 34. Part 1: Implement WebDriver ScriptPart 1: Implement WebDriver Script • In WebDriver script, Simulate the user action o Navigate to the subject page o Enter values into textboxs based on input values o Select options based on input values o Click the “add class” button o Check the result against the requirements • Run all your test cases and report the results.
  • 35. Course Project 4Course Project 4 • Part 2: Pair wise testing o Use an existing pair wise testing tool fire-eye o Largely you may reuse the WebDriver template in Part 1 Your testYour test casescases Your testYour test casescases Your WebDriverYour WebDriver test templatetest template Your WebDriverYour WebDriver test templatetest template inputinputinputinput outputoutputoutputoutput TestTest resultresult TestTest resultresult Test casesTest cases generatedgenerated Test casesTest cases generatedgenerated ConvertConvertConvertConvert
  • 36. Part 2: Generate test casesPart 2: Generate test cases • Consider the combination of all textboxs/options • Use the existing tool, fire-eye, to generate test cases • Export the test case in “Nist form” • Parse and convert the exported test cases to the form that your WebDriver can accept • Run all pair-wise test cases • Report the result
  • 37. Part 2: Solution designPart 2: Solution design • Selenium can do more … • Black Friday is coming, hot items can be sold in a few seconds • Can you leverage the automated tool and design a practical solution to score a super hot deal? • Explain o What’s the challenge o What’s the possible cases to handle and how? • In stock • Out of stock • Your shopping cart may be reset under what conditions… o How to add it into your shopping cart asap o How you are going to cooperate with the automated tool
  • 38. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/selenium-classes-in-mu