SlideShare una empresa de Scribd logo
1 de 36
 Uniqueness of web app testing
◦ Heterogonous system
◦ Dynamic pages
◦ Load
◦ Security
 Selenium WebDriver
 Course project 4
 Heterogeneous system
◦ Front end
 Browser: IE, Firefox, Chrome, Safari…
◦ Server side
 Application Server
 Database Server
 File System
 ……
 Front end
◦ HTML, JavaScript, Adobe Flash……
HTMLHTML
JavaScriptJavaScript
Page in BrowserPage in Browser
Source behindSource behind
 Server side
◦ Can be written in PHP, Java, C#...
◦ Communicate with Database server in SQL
PHP ScriptPHP Script
SQLSQL
HTMLHTML
SQLSQL
PHPPHP
 Should test all involved parts
◦ Everything can go wrong…
 However, only front end is accessible for tests
◦ Can not directly test the Server code and SQL
◦ Have to drive the execution and test
 Frontend
 HTML: Malformed HTML page? (demo)
 JavaScript: Runtime Errors? (demo)
 Server script
 PHP, Java…: Runtime Errors? (demo)
 SQL: Malformed SQL query string? (demo)
 Good things
◦ Hide the complexity of the backend
◦ Uniformed interface
◦ Can put a robot in the front end and automate the tests
Bad things
◦ The front end is not trustable
 Crafted malicious requests
 Automated web app testing
◦ Compare to commend-line program testing…
 Sensitive to input values (the same)
 GUI testing: event driven (the difference)
 “Button A” then “Button B”  OK
 “Button B” then “Button A”  FAIL
◦ The robot should be able to
 Provide input values
 Simulate user actions
 Selenium
◦ A tool set automates web app testing across platforms
◦ Can simulate user interactions in browser
◦ Two components
 Selenium IDE
 Selenium WebDriver (aka. Selenium 2)
 Firefox extension
 Easy record and replay
 Debug and set breakpoints
 Save tests in HTML,
WebDriver and other
formats.
 Selenium saves all information in an HTML table format
 Each record consists of:
◦ Command – tells Selenium what to do (e.g. “open”, “type”, “click”,
“verifyText”)
◦ Target – tells Selenium which HTML element a command refers
to (e.g. textbox, header, table)
◦ Value – used for any command that might need a value of some
kind (e.g. type something into a textbox)
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……
 The front end is not trustable
◦ Front end code can be accessed to anybody
◦ They can infer the input parameters
◦ Crafted requests!
 Demo
◦ Front end limits the length of the input values
◦ Front end limits the content of the input values
◦ Front end limits the combination of the input values
 Client page is dynamic
◦ It can change itself in the runtime
◦ HTML can be modified by JavaScript
◦ JavaScript can modify itself
◦ Demo
 Server script is dynamic
◦ Client pages are constructed in the runtime
◦ A same server script can produce completely different client
pages
◦ Demo
 SchoolMate
 Performance is crucial to the success of a web app
◦ Recall the experience to register for a class in the first days of
the semester…
◦ Are the servers powerful enough?
 Performance testing evaluates system performance under
normal and heavy usage
◦ Load testing
 For expected concurrent number of users
◦ Stress testing
 To understand the upper limits of capacity
 Performance testing can be automated
 Web app usually deals with sensitive info, e.g.
◦ Credit card number
◦ SSN
◦ Billing / Shipping address
 Security is the biggest concern
 Security testing should simulate possible attacks
 SQL Injection
◦ The untrusted input is used to construct dynamic SQL
queries.
◦ 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
 Cross Site Scripting (XSS)
◦ The untrusted input is used to construct dynamic HTML
pages.
◦ The malicious JS injected executes in victim’s browser
◦ The malicious JS can steal sensitive info
◦ Demo
 Solution: Never trust user inputs
 Design test cases to simulate attacks
 Uniqueness of web app testing
◦ Heterogonous system
◦ Dynamic pages
◦ Load
◦ Security
 Selenium WebDriver
 Course project 4
 No multiple browsers support
◦ It runs only in Mozilla Firefox.
 No manual scripts
◦ E.g. conditions and Loops for Data Driven Testing
 Fancy test cases  Selenium WebDriver
 Selenium-WebDriver
◦ A piece of program
◦ Control the browser by programming
◦ More flexible and powerful
 Selenium-WebDriver supports multiple browsers in
multiple platforms
◦ Google Chrome 12.0.712.0+
◦ Internet Explorer 6+
◦ Firefox 3.0+
◦ Opera 11.5+
◦ Android – 2.3+ for phones and tablets
◦ iOS 3+ for phones
◦ iOS 3.2+ for tablets
 WebDriver is designed to providing a simpler and
uniformed programming interface
◦ Same WebDriver script runs for different platforms
 Support multiple programming language:
◦ Java, C#, Python, Ruby, PHP, Perl…
 It’s efficient
◦ WebDriver leverages each browser’s native support for
automation.
 A solution for the automated testing
◦ Simulate user actions
◦ Functional testing
 Create regression tests to verify functionality and user
acceptance.
◦ Browser compatibility testing
 The same script can run on any Selenium platform
◦ Load testing
◦ Stress testing
(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
public 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();
}
 By id
◦ HTML: <div id="coolestWidgetEvah">...</div>
◦ WebDriver:
driver.findElement( By.id("coolestWidgetEvah") );
 By name
◦ HTML: <input name="cheese" type="text"/>
◦ WebDriver: driver.findElement( By.name("cheese") );
 By Xpath
◦ HTML
<html>
<input type="text" name="example" />
<input type="text" name="other" />
</html>
◦ WebDriver: driver.findElements( By.xpath("//input") );
◦ There are plug-ins for firefox/chrome to automatically display the Xpath
 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
◦ Submit a request
◦ Verify the response immediately
 Solution:
◦ Simulate the wait. Wait until some HTML object appears
◦ Demo
 What to test for a web application
 Test web app with selenium
◦ What’s Selenium?
◦ Why Selenium?
◦ How to use Selenium
 Course project 4
 Test a functionality without the source
 The subject web application
◦ “Add New Class” in “SchoolMate”
 Part 1: overview
◦ Design test cases against the requirement
 The tests should consider
 all possible cases
 equivalence class partitioning
◦ 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 templateinputinputinputinput outputoutputoutputoutput
TestTest
resultsresults
TestTest
resultsresults
 Requirement for values entered/selected
◦ [R-1] Class Name : alphabets and numbers are allowed.
◦ [R-2] Section Number : only numbers are allowed.
◦ [R-3] Room Number : only numbers are allowed.
◦ [R-4] Period Number : only numbers are allowed.
◦ [R-5] All textbox fields : no Cross-Site Scripting (XSS) injection
vulnerabilities.
 Requirement for the “add” function
 After clicking the “Add class” button…
◦ [R-6] The class record added is successfully shown in
the table.
◦ [R-7] The values are exactly the same as those were
entered or selected.
 For each requirement, design test cases
 Only need test one field in each case
◦ Do not need consider combinations of fileds
 E.g.
◦ [R-1] Class Name : alphabets and numbers are allowed.
◦ You need consider all possible cases
◦ Divide the test space and find the equivalence class
 Alphabets
 Numbers
 ….
 The test case format is defined
◦ Test cases will be used as input to your WebDriver Script
 In WebDriver script, Simulate the user action
◦ Navigate to the subject page
◦ Enter values into textboxs based on input values
◦ Select options based on input values
◦ Click the “add class” button
◦ Check the result against the requirements
 Run all your test cases and report the results.
 Part 2: Pair wise testing
◦ Use an existing pair wise testing tool fire-eye
◦ 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 templateinputinputinputinput outputoutputoutputoutput
TestTest
resultresult
TestTest
resultresult
Test casesTest cases
generatedgenerated
Test casesTest cases
generatedgenerated
ConvertConvertConvertConvert
 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
 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
◦ What’s the challenge
◦ What’s the possible cases to handle and how?
 In stock
 Out of stock
 Your shopping cart may be reset under what conditions…
◦ How to add it into your shopping cart asap
◦ How you are going to cooperate with the automated tool

Más contenido relacionado

La actualidad más candente

Development of automated tests for ext js based web sites
Development of automated tests for ext js based web sitesDevelopment of automated tests for ext js based web sites
Development of automated tests for ext js based web sites
ISsoft
 

La actualidad más candente (19)

watir-webdriver
watir-webdriverwatir-webdriver
watir-webdriver
 
Tellurium.A.New.Approach.For.Web.Testing
Tellurium.A.New.Approach.For.Web.TestingTellurium.A.New.Approach.For.Web.Testing
Tellurium.A.New.Approach.For.Web.Testing
 
Introduction To Ruby Watir (Web Application Testing In Ruby)
Introduction To Ruby Watir (Web Application Testing In Ruby)Introduction To Ruby Watir (Web Application Testing In Ruby)
Introduction To Ruby Watir (Web Application Testing In Ruby)
 
Development of automated tests for ext js based web sites
Development of automated tests for ext js based web sitesDevelopment of automated tests for ext js based web sites
Development of automated tests for ext js based web sites
 
Foundation selenium java
Foundation selenium java Foundation selenium java
Foundation selenium java
 
Basic Selenium Training
Basic Selenium TrainingBasic Selenium Training
Basic Selenium Training
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
Watir web automated tests
Watir web automated testsWatir web automated tests
Watir web automated tests
 
What you can do In WatiR
What you can do In WatiRWhat you can do In WatiR
What you can do In WatiR
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlotInterview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlot
 
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotInterview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
 
Selenium and The Grinder
Selenium and The GrinderSelenium and The Grinder
Selenium and The Grinder
 
PhpUnit & web driver
PhpUnit & web driverPhpUnit & web driver
PhpUnit & web driver
 
Better Testing With PHP Unit
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unit
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
WinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test AutomationWinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test Automation
 
Integrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala ProjectIntegrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala Project
 
Scaladays 2014 introduction to scalatest selenium dsl
Scaladays 2014   introduction to scalatest selenium dslScaladays 2014   introduction to scalatest selenium dsl
Scaladays 2014 introduction to scalatest selenium dsl
 

Similar a Selenium

Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
Neeraj Mathur
 

Similar a Selenium (20)

selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019
 
Selenium Automation
Selenium AutomationSelenium Automation
Selenium Automation
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 

Más de husnara mohammad (16)

Ajax
AjaxAjax
Ajax
 
Log4e
Log4eLog4e
Log4e
 
Jsp intro
Jsp introJsp intro
Jsp intro
 
Hibernate
HibernateHibernate
Hibernate
 
J2EE
J2EEJ2EE
J2EE
 
Spring frame work
Spring frame workSpring frame work
Spring frame work
 
Java intro
Java introJava intro
Java intro
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
Asp dot net
Asp dot netAsp dot net
Asp dot net
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
Sql introduction
Sql introductionSql introduction
Sql introduction
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
C++ basics
C++ basicsC++ basics
C++ basics
 
Ajax basic intro
Ajax basic introAjax basic intro
Ajax basic intro
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Web attacks
Web attacksWeb attacks
Web attacks
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Selenium

  • 1.
  • 2.  Uniqueness of web app testing ◦ Heterogonous system ◦ Dynamic pages ◦ Load ◦ Security  Selenium WebDriver  Course project 4
  • 3.  Heterogeneous system ◦ Front end  Browser: IE, Firefox, Chrome, Safari… ◦ Server side  Application Server  Database Server  File System  ……
  • 4.  Front end ◦ HTML, JavaScript, Adobe Flash…… HTMLHTML JavaScriptJavaScript Page in BrowserPage in Browser Source behindSource behind
  • 5.  Server side ◦ Can be written in PHP, Java, C#... ◦ Communicate with Database server in SQL PHP ScriptPHP Script SQLSQL HTMLHTML SQLSQL PHPPHP
  • 6.  Should test all involved parts ◦ Everything can go wrong…  However, only front end is accessible for tests ◦ Can not directly test the Server code and SQL ◦ Have to drive the execution and test  Frontend  HTML: Malformed HTML page? (demo)  JavaScript: Runtime Errors? (demo)  Server script  PHP, Java…: Runtime Errors? (demo)  SQL: Malformed SQL query string? (demo)
  • 7.  Good things ◦ Hide the complexity of the backend ◦ Uniformed interface ◦ Can put a robot in the front end and automate the tests Bad things ◦ The front end is not trustable  Crafted malicious requests
  • 8.  Automated web app testing ◦ Compare to commend-line program testing…  Sensitive to input values (the same)  GUI testing: event driven (the difference)  “Button A” then “Button B”  OK  “Button B” then “Button A”  FAIL ◦ The robot should be able to  Provide input values  Simulate user actions  Selenium ◦ A tool set automates web app testing across platforms ◦ Can simulate user interactions in browser ◦ Two components  Selenium IDE  Selenium WebDriver (aka. Selenium 2)
  • 9.  Firefox extension  Easy record and replay  Debug and set breakpoints  Save tests in HTML, WebDriver and other formats.
  • 10.  Selenium saves all information in an HTML table format  Each record consists of: ◦ Command – tells Selenium what to do (e.g. “open”, “type”, “click”, “verifyText”) ◦ Target – tells Selenium which HTML element a command refers to (e.g. textbox, header, table) ◦ Value – used for any command that might need a value of some kind (e.g. type something into a textbox)
  • 11. 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……
  • 12.  The front end is not trustable ◦ Front end code can be accessed to anybody ◦ They can infer the input parameters ◦ Crafted requests!  Demo ◦ Front end limits the length of the input values ◦ Front end limits the content of the input values ◦ Front end limits the combination of the input values
  • 13.  Client page is dynamic ◦ It can change itself in the runtime ◦ HTML can be modified by JavaScript ◦ JavaScript can modify itself ◦ Demo  Server script is dynamic ◦ Client pages are constructed in the runtime ◦ A same server script can produce completely different client pages ◦ Demo  SchoolMate
  • 14.  Performance is crucial to the success of a web app ◦ Recall the experience to register for a class in the first days of the semester… ◦ Are the servers powerful enough?  Performance testing evaluates system performance under normal and heavy usage ◦ Load testing  For expected concurrent number of users ◦ Stress testing  To understand the upper limits of capacity  Performance testing can be automated
  • 15.  Web app usually deals with sensitive info, e.g. ◦ Credit card number ◦ SSN ◦ Billing / Shipping address  Security is the biggest concern  Security testing should simulate possible attacks
  • 16.  SQL Injection ◦ The untrusted input is used to construct dynamic SQL queries. ◦ 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
  • 17.  Cross Site Scripting (XSS) ◦ The untrusted input is used to construct dynamic HTML pages. ◦ The malicious JS injected executes in victim’s browser ◦ The malicious JS can steal sensitive info ◦ Demo  Solution: Never trust user inputs  Design test cases to simulate attacks
  • 18.  Uniqueness of web app testing ◦ Heterogonous system ◦ Dynamic pages ◦ Load ◦ Security  Selenium WebDriver  Course project 4
  • 19.  No multiple browsers support ◦ It runs only in Mozilla Firefox.  No manual scripts ◦ E.g. conditions and Loops for Data Driven Testing  Fancy test cases  Selenium WebDriver
  • 20.  Selenium-WebDriver ◦ A piece of program ◦ Control the browser by programming ◦ More flexible and powerful  Selenium-WebDriver supports multiple browsers in multiple platforms ◦ Google Chrome 12.0.712.0+ ◦ Internet Explorer 6+ ◦ Firefox 3.0+ ◦ Opera 11.5+ ◦ Android – 2.3+ for phones and tablets ◦ iOS 3+ for phones ◦ iOS 3.2+ for tablets
  • 21.  WebDriver is designed to providing a simpler and uniformed programming interface ◦ Same WebDriver script runs for different platforms  Support multiple programming language: ◦ Java, C#, Python, Ruby, PHP, Perl…  It’s efficient ◦ WebDriver leverages each browser’s native support for automation.
  • 22.  A solution for the automated testing ◦ Simulate user actions ◦ Functional testing  Create regression tests to verify functionality and user acceptance. ◦ Browser compatibility testing  The same script can run on any Selenium platform ◦ Load testing ◦ Stress testing
  • 23. (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
  • 24. public 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(); }
  • 25.  By id ◦ HTML: <div id="coolestWidgetEvah">...</div> ◦ WebDriver: driver.findElement( By.id("coolestWidgetEvah") );  By name ◦ HTML: <input name="cheese" type="text"/> ◦ WebDriver: driver.findElement( By.name("cheese") );  By Xpath ◦ HTML <html> <input type="text" name="example" /> <input type="text" name="other" /> </html> ◦ WebDriver: driver.findElements( By.xpath("//input") ); ◦ There are plug-ins for firefox/chrome to automatically display the Xpath
  • 26.  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 ◦ Submit a request ◦ Verify the response immediately  Solution: ◦ Simulate the wait. Wait until some HTML object appears ◦ Demo
  • 27.  What to test for a web application  Test web app with selenium ◦ What’s Selenium? ◦ Why Selenium? ◦ How to use Selenium  Course project 4
  • 28.  Test a functionality without the source  The subject web application ◦ “Add New Class” in “SchoolMate”
  • 29.  Part 1: overview ◦ Design test cases against the requirement  The tests should consider  all possible cases  equivalence class partitioning ◦ 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 templateinputinputinputinput outputoutputoutputoutput TestTest resultsresults TestTest resultsresults
  • 30.  Requirement for values entered/selected ◦ [R-1] Class Name : alphabets and numbers are allowed. ◦ [R-2] Section Number : only numbers are allowed. ◦ [R-3] Room Number : only numbers are allowed. ◦ [R-4] Period Number : only numbers are allowed. ◦ [R-5] All textbox fields : no Cross-Site Scripting (XSS) injection vulnerabilities.
  • 31.  Requirement for the “add” function  After clicking the “Add class” button… ◦ [R-6] The class record added is successfully shown in the table. ◦ [R-7] The values are exactly the same as those were entered or selected.
  • 32.  For each requirement, design test cases  Only need test one field in each case ◦ Do not need consider combinations of fileds  E.g. ◦ [R-1] Class Name : alphabets and numbers are allowed. ◦ You need consider all possible cases ◦ Divide the test space and find the equivalence class  Alphabets  Numbers  ….  The test case format is defined ◦ Test cases will be used as input to your WebDriver Script
  • 33.  In WebDriver script, Simulate the user action ◦ Navigate to the subject page ◦ Enter values into textboxs based on input values ◦ Select options based on input values ◦ Click the “add class” button ◦ Check the result against the requirements  Run all your test cases and report the results.
  • 34.  Part 2: Pair wise testing ◦ Use an existing pair wise testing tool fire-eye ◦ 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 templateinputinputinputinput outputoutputoutputoutput TestTest resultresult TestTest resultresult Test casesTest cases generatedgenerated Test casesTest cases generatedgenerated ConvertConvertConvertConvert
  • 35.  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
  • 36.  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 ◦ What’s the challenge ◦ What’s the possible cases to handle and how?  In stock  Out of stock  Your shopping cart may be reset under what conditions… ◦ How to add it into your shopping cart asap ◦ How you are going to cooperate with the automated tool