SlideShare a Scribd company logo
Web App Testing with Selenium João Prado Maia Lead Software Developer, Alert Logic March 6 th , 2008
Unit testing in PHP land Unit testing OOP code usually just business logic code (classes) Not good enough No way to test visual aspect of the app CSS Broken images How do you check JavaScript based pages? How about AJAX calls? Very labor intensive
Combined approach Unit testing of business logic code Data access classes Lots of best practices around for this UI testing with Selenium Make sure UI behaves correctly JavaScript based or not Examples: Log in to your app Log out from your app Change your account settings etc
Enter Selenium! Selenium Core JavaScript library Used by all other sub-projects Selenium IDE to record tests Firefox extension Playback tests Debug  and set breakpoints Selenium RC Java server Controls web browser remotely
Selenium IDE Firefox extension Record and replay tests Test files as HTML files (by default) Accepts commands, allowing you to: Run actions on browser Verify that document has valid content Run a suite of UI tests Multiple tests running in sequence
Recording and Replaying a Test Demonstration
Selenium test structure <html> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;> <title>google_houston</title> </head> <body> <table cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; border=&quot;1&quot;> <thead> <tr><td rowspan=&quot;1&quot; colspan=&quot;3&quot;>google_houston</td></tr> </thead><tbody> <tr> <td>open</td> <td>/</td> <td></td> </tr> <tr> <td>type</td> <td>q</td> <td>houston php</td> </tr> <tr> <td>click</td> <td>btnG</td> <td></td> </tr> <tr> <td>verifyTextPresent</td> <td>Houston PHP / MySQL Users Group</td> <td></td> </tr> </tbody></table> </body> </html>
Understanding Selenium Reference documentation http://release.openqa.org/selenium-core/0.8.2/reference.html Key concepts Actions Accessors Assertions Patterns Locators Valid locators values: id=nav_bar name=username dom=document.images[2] xpath=//table[@id=“results”]/tr[1]/td[4] css=a[href=“#top”] link=Logout
Running  a Test Suite TestRunner interface Run multiple tests in sequence Internal to Selenium Demonstration
Test suite structure <table> <tr> <td>Meetup presentation</td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_smarty.html&quot;>Google - smarty</a></td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_latest_php.html&quot;>Google - latest php version</a></td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_houston.html&quot;>Google - houston php</a></td> </tr> </table>
Dynamic test suite Put all HTML test files in the same directory Create a new PHP script: <?php $tests = glob('*.html'); ?> <table> <tr> <td>Meetup presentation</td> </tr> <?php foreach ($tests as $filename) { ?> <tr> <td> <a target=&quot;testFrame&quot; href=&quot;<?php echo $filename; ?>&quot; > <?php echo ucwords(str_replace('.html', '', str_replace('_', ' ', $filename))); ?> </a> </td> </tr> <?php } ?> </table>
Selenium RC Java server controls the browser Windows, Mac OS X, Linux platforms Allows you to write tests in PHP Remotely send commands to Java server Tightly integrated with PHPUnit! Allows you to run UI test suites as regular PHPUnit suites
Selenium RC requirements PHPUnit PEAR::Testing_Selenium Machine to run the actual UI tests from We run a VMware image with the latest IE/Firefox, another one with IE6 and Firefox 1.5
Example of a Test in PHP <?php require_once 'SeleniumTestHelper.php'; class LoginTest extends SeleniumTestHelper  { public function testAccessToLoginForm() { $this->selenium->open(&quot;index.php&quot;); $this->selenium->verifyTextPresent('Having trouble logging in?'); } public function testFailedLogin() { $this->selenium->open(&quot;index.php&quot;); $this->selenium->type(&quot;username&quot;, &quot;admin&quot;); $this->selenium->type(&quot;customer&quot;, &quot;2&quot;); $this->selenium->type(&quot;password&quot;, &quot;blahblah&quot;); $this->selenium->clickAndWait(&quot;//input[@value='Log In']&quot;); $this->selenium->verifyTextPresent('Invalid login. Please try again.'); } } ?>
HTML content <!-- more stuff here --> <table cellspacing='0' cellpadding='0'> <tr> <th>Name</th> </tr> <tr> <td><input type=&quot;text&quot; class=&quot;textfield&quot; name=&quot;username&quot; /></td> </tr> <tr> <th>Customer ID</th> </tr> <tr> <td><input type=&quot;text&quot; class=&quot;textfield&quot; name=&quot;customer&quot; /></td> </tr> <tr> <th>Password</th> </tr> <tr> <td><input type=&quot;password&quot; class=&quot;textfield&quot; name=&quot;password&quot; /></td> </tr> <tr> <td colspan=&quot;2&quot;> <input type=&quot;image&quot; src=&quot;/4/branding.php?param=btn_login&quot; value=&quot;Log In&quot; /> <span id=&quot;processing&quot; style=&quot;display: none;&quot;> <img src=&quot;/4/images/icons/spinner.gif&quot; /> <strong>Processing...</strong> </span> </td> </tr> </table> <!-- more stuff here -->
SeleniumTestHelper <?php require_once '../../setup/config.php'; require_once 'Testing/Selenium.php'; require_once 'PHPUnit2/Framework/TestCase.php'; // ip address of selenium server if (!defined('APP_SELENIUM_SERVER')) { define('APP_SELENIUM_SERVER', '172.17.0.110'); } // which browser to use on this run of the test if (!defined('APP_SELENIUM_BROWSER')) { define('APP_SELENIUM_BROWSER', '*firefox'); } class SeleniumTestHelper extends PHPUnit2_Framework_TestCase { protected $selenium; public function setUp() { $this->selenium = new Testing_Selenium(APP_SELENIUM_BROWSER, APP_BASE_URL . APP_RELATIVE_URL, APP_SELENIUM_SERVER); $this->selenium->start(); } public function tearDown() { $this->selenium->stop(); } } ?>
Targeting browsers Selenium RC allows for you to run tests in different browsers Windows Internet Explorer 6.0+ Firefox 1.5+ Linux Firefox 1.5+ Opera 9.0.2 Konqueror 3.5.3 Mac OS X Firefox 1.5+ Full list at  http://selenium-rc.openqa.org/
How to target browsers First parameter tells Testing_Selenium what browser to use $selenium = new Testing_Selenium(“*firefox”, “http://google.com”, “192.168.1.12”); Possible values: *firefox *iexplore *opera *custom more details on this at  http://wiki.openqa.org/display/SRC/Selenium+RC+FAQ Idea: setup multiple VMware images, one with a specific set of browsers
RC Test suite <?php if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'TestSuite::main'); } require_once 'SeleniumTestHelper.php'; class TestSuite { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Framework'); $test_files = glob('*Test.php'); foreach ($test_files as $file) { $suite->addTestFile($file); } return $suite; } } if (PHPUnit2_MAIN_METHOD == 'TestSuite::main') { TestSuite::main(); } ?>
Advanced Tests Testing AJAX requests Look for after effects of the AJAX request, such as: Icon gets displayed Hidden <DIV> is made visible XPath support //div[@id=“recent_traffic_graph”]/img //div[4]/div/div/div[1]/div[1]/table/tbody/tr/td[2]/span[4]/a/img //table[@id=“table1”]//tr[4]/td[2] (//table[@class=“results”])//th[text()=“Price”]/../tr
Last slide Selenium (IDE, RC, etc) http://openqa.org PHPUnit http://phpunit.de PEAR::Testing_Selenium http://pear.php.net/package/Testing_Selenium Recommended books PHPUnit Pocket Guide http://oreilly.com/catalog/phpunitpg/ PHPUnit Pocket Guide (online for free) http://phpunit.de/pocket_guide/ Smarty PHP Template Programming and Applications (buy it!) http://smartybook.com
Ad

Recommended

Pentesting for startups
Pentesting for startups
levigross
 
Codeception
Codeception
Jonathan Lau
 
Codeception introduction and use in Yii
Codeception introduction and use in Yii
IlPeach
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Selenium interview questions and answers
Selenium interview questions and answers
kavinilavuG
 
Selenium Interpreter
Selenium Interpreter
melbournepatterns
 
Codeception: introduction to php testing
Codeception: introduction to php testing
Engineor
 
DevDays09 Internet Explorer 8
DevDays09 Internet Explorer 8
Konstantinos Pantos
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Codeception
Codeception
少東 張
 
Codeception presentation
Codeception presentation
Andrei Burian
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Alfresco Software
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Selenium Interview Questions & Answers
Selenium Interview Questions & Answers
Techcanvass
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem
 
Selenium interview-questions-freshers
Selenium interview-questions-freshers
Naga Mani
 
The PHP Way Of TDD - Think First, Code Later
The PHP Way Of TDD - Think First, Code Later
Hiraq Citra M
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Php Best Practices
Php Best Practices
Ansar Ahmed
 
Introduction to Selenium
Introduction to Selenium
rohitnayak
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
Top trending selenium interview questions
Top trending selenium interview questions
Rock Interview
 
10reasons
10reasons
Li Huan
 
More about PHP
More about PHP
Jonathan Francis Roscoe
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
PHPUnit
PHPUnit
Hampton Roads PHP User Grop
 
Mobile Testing with Selenium 2 by Jason Huggins
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs
 
Raj Subramanian - Mobile Web Testing
Raj Subramanian - Mobile Web Testing
QA or the Highway
 
Mobile testing in the cloud
Mobile testing in the cloud
Diaconu Andrei-Tudor
 

More Related Content

What's hot (20)

Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Codeception
Codeception
少東 張
 
Codeception presentation
Codeception presentation
Andrei Burian
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Alfresco Software
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Selenium Interview Questions & Answers
Selenium Interview Questions & Answers
Techcanvass
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem
 
Selenium interview-questions-freshers
Selenium interview-questions-freshers
Naga Mani
 
The PHP Way Of TDD - Think First, Code Later
The PHP Way Of TDD - Think First, Code Later
Hiraq Citra M
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Php Best Practices
Php Best Practices
Ansar Ahmed
 
Introduction to Selenium
Introduction to Selenium
rohitnayak
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
Top trending selenium interview questions
Top trending selenium interview questions
Rock Interview
 
10reasons
10reasons
Li Huan
 
More about PHP
More about PHP
Jonathan Francis Roscoe
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
PHPUnit
PHPUnit
Hampton Roads PHP User Grop
 
Mobile Testing with Selenium 2 by Jason Huggins
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Codeception presentation
Codeception presentation
Andrei Burian
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Alfresco Software
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Selenium Interview Questions & Answers
Selenium Interview Questions & Answers
Techcanvass
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem
 
Selenium interview-questions-freshers
Selenium interview-questions-freshers
Naga Mani
 
The PHP Way Of TDD - Think First, Code Later
The PHP Way Of TDD - Think First, Code Later
Hiraq Citra M
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Php Best Practices
Php Best Practices
Ansar Ahmed
 
Introduction to Selenium
Introduction to Selenium
rohitnayak
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
Top trending selenium interview questions
Top trending selenium interview questions
Rock Interview
 
10reasons
10reasons
Li Huan
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
Mobile Testing with Selenium 2 by Jason Huggins
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs
 

Viewers also liked (11)

Raj Subramanian - Mobile Web Testing
Raj Subramanian - Mobile Web Testing
QA or the Highway
 
Mobile testing in the cloud
Mobile testing in the cloud
Diaconu Andrei-Tudor
 
Mobile web or native app
Mobile web or native app
Mike Takahashi
 
Web App VS. Hybrid App VS. Native App?
Web App VS. Hybrid App VS. Native App?
Justin O'Neill
 
Extended Finite State Machine - EFSM
Extended Finite State Machine - EFSM
Sun Technlogies
 
Mobile web vs. native apps: It's not about technology, it's about psychology
Mobile web vs. native apps: It's not about technology, it's about psychology
iQcontent
 
Mobile App Testing
Mobile App Testing
Geekit |Software Testing Services and Consultancy
 
Mobile application testing
Mobile application testing
Softheme
 
Mobile Application Testing
Mobile Application Testing
Sun Technlogies
 
Mobile Application Testing Training Presentation
Mobile Application Testing Training Presentation
MobiGnosis
 
Web application testing with Selenium
Web application testing with Selenium
Kerry Buckley
 
Raj Subramanian - Mobile Web Testing
Raj Subramanian - Mobile Web Testing
QA or the Highway
 
Mobile web or native app
Mobile web or native app
Mike Takahashi
 
Web App VS. Hybrid App VS. Native App?
Web App VS. Hybrid App VS. Native App?
Justin O'Neill
 
Extended Finite State Machine - EFSM
Extended Finite State Machine - EFSM
Sun Technlogies
 
Mobile web vs. native apps: It's not about technology, it's about psychology
Mobile web vs. native apps: It's not about technology, it's about psychology
iQcontent
 
Mobile application testing
Mobile application testing
Softheme
 
Mobile Application Testing
Mobile Application Testing
Sun Technlogies
 
Mobile Application Testing Training Presentation
Mobile Application Testing Training Presentation
MobiGnosis
 
Web application testing with Selenium
Web application testing with Selenium
Kerry Buckley
 
Ad

Similar to Web App Testing With Selenium (20)

Selenium
Selenium
Adam Goucher
 
Selenium
Selenium
shrialinda
 
Better Testing With PHP Unit
Better Testing With PHP Unit
sitecrafting
 
Selenium Ide Tutorial
Selenium Ide Tutorial
metapix
 
Intro Of Selenium
Intro Of Selenium
Kai Feng Zhang
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
selenium.ppt
selenium.ppt
rajnexient
 
selenium.ppt
selenium.ppt
ssuser7b4894
 
selenium.ppt
selenium.ppt
AmenSheikh
 
Gems Of Selenium
Gems Of Selenium
Skills Matter
 
Selenium
Selenium
Purna Chandar
 
Selenium
Selenium
Sun Technlogies
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
Michelangelo van Dam
 
Let's talk testing with Selenium
Let's talk testing with Selenium
anishanarang
 
Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)
AOE
 
Selenium Ide Tutorials
Selenium Ide Tutorials
gueste1e4db
 
Selenium
Selenium
husnara mohammad
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
Michelangelo van Dam
 
Automated Web Testing Using Selenium
Automated Web Testing Using Selenium
Weifeng Zhang
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
Quontra Solutions
 
Better Testing With PHP Unit
Better Testing With PHP Unit
sitecrafting
 
Selenium Ide Tutorial
Selenium Ide Tutorial
metapix
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
Michelangelo van Dam
 
Let's talk testing with Selenium
Let's talk testing with Selenium
anishanarang
 
Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)
AOE
 
Selenium Ide Tutorials
Selenium Ide Tutorials
gueste1e4db
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
Michelangelo van Dam
 
Automated Web Testing Using Selenium
Automated Web Testing Using Selenium
Weifeng Zhang
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
Quontra Solutions
 
Ad

More from joaopmaia (7)

AFNetworking
AFNetworking
joaopmaia
 
Core Data presentation
Core Data presentation
joaopmaia
 
SQLite Techniques
SQLite Techniques
joaopmaia
 
SQLite Techniques
SQLite Techniques
joaopmaia
 
Meetup uikit programming
Meetup uikit programming
joaopmaia
 
Eventum Presentation
Eventum Presentation
joaopmaia
 
Form Validation NG
Form Validation NG
joaopmaia
 
AFNetworking
AFNetworking
joaopmaia
 
Core Data presentation
Core Data presentation
joaopmaia
 
SQLite Techniques
SQLite Techniques
joaopmaia
 
SQLite Techniques
SQLite Techniques
joaopmaia
 
Meetup uikit programming
Meetup uikit programming
joaopmaia
 
Eventum Presentation
Eventum Presentation
joaopmaia
 
Form Validation NG
Form Validation NG
joaopmaia
 

Recently uploaded (20)

The Executive’s Guide to Stress-Free Airport Transfers in London
The Executive’s Guide to Stress-Free Airport Transfers in London
Jannah Express
 
Architecture that Advances Part I Review.pdf
Architecture that Advances Part I Review.pdf
Brij Consulting, LLC
 
The Ultimate Guide to Print on Demand Apparel.docx
The Ultimate Guide to Print on Demand Apparel.docx
Aesthetic Bk
 
Stuart Frost - The Chief Executive Officer Of Geminos
Stuart Frost - The Chief Executive Officer Of Geminos
Stuart Frost
 
Extending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective Coatings
rahil wit
 
IBX Prospective Consultant Information Pack
IBX Prospective Consultant Information Pack
IBX Daya Nusantara
 
Auditing Property Financials_ Best Practices.pptx
Auditing Property Financials_ Best Practices.pptx
exoedgemarketingteam
 
Breaking Through Cultural Friction: The Role of Respect for People (Strengthe...
Breaking Through Cultural Friction: The Role of Respect for People (Strengthe...
KaiNexus
 
“Built with our sleeves rolled up”Action
“Built with our sleeves rolled up”Action
Action EDI
 
1911 Gold Corporate Presentation June 2025
1911 Gold Corporate Presentation June 2025
Shaun Heinrichs
 
Kenyan Msme Export Book by Dickens Aluha Mujumba
Kenyan Msme Export Book by Dickens Aluha Mujumba
JoshuaKihara
 
Building a Customer-Centric Business Best Practices.pdf
Building a Customer-Centric Business Best Practices.pdf
Stacy Neir
 
🧪 JIS Z 8901 Class 8 Kanto Loam .pdf
🧪 JIS Z 8901 Class 8 Kanto Loam .pdf
Particle Powder
 
ISO 45001 Certification in Singapore Company
ISO 45001 Certification in Singapore Company
achharsharma105
 
Redefining Business Experiences: The Role of a Corporate Event Management Com...
Redefining Business Experiences: The Role of a Corporate Event Management Com...
Be Executive Events
 
chapter 9 leadership qualityies university of windsor
chapter 9 leadership qualityies university of windsor
zamananalyst29
 
Podcast Show Notes - Rapid International Expansion for Scale-up Stage Tech Bu...
Podcast Show Notes - Rapid International Expansion for Scale-up Stage Tech Bu...
Dave Litwiller
 
Ian McAllister - Respected Photographer And Writer
Ian McAllister - Respected Photographer And Writer
Ian McAllister
 
solulab.com-How to Build a Private LLM.pdf
solulab.com-How to Build a Private LLM.pdf
celinedion89121
 
Ch01.ppt bisnis internasional bisnis internasional
Ch01.ppt bisnis internasional bisnis internasional
devina81
 
The Executive’s Guide to Stress-Free Airport Transfers in London
The Executive’s Guide to Stress-Free Airport Transfers in London
Jannah Express
 
Architecture that Advances Part I Review.pdf
Architecture that Advances Part I Review.pdf
Brij Consulting, LLC
 
The Ultimate Guide to Print on Demand Apparel.docx
The Ultimate Guide to Print on Demand Apparel.docx
Aesthetic Bk
 
Stuart Frost - The Chief Executive Officer Of Geminos
Stuart Frost - The Chief Executive Officer Of Geminos
Stuart Frost
 
Extending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective Coatings
rahil wit
 
IBX Prospective Consultant Information Pack
IBX Prospective Consultant Information Pack
IBX Daya Nusantara
 
Auditing Property Financials_ Best Practices.pptx
Auditing Property Financials_ Best Practices.pptx
exoedgemarketingteam
 
Breaking Through Cultural Friction: The Role of Respect for People (Strengthe...
Breaking Through Cultural Friction: The Role of Respect for People (Strengthe...
KaiNexus
 
“Built with our sleeves rolled up”Action
“Built with our sleeves rolled up”Action
Action EDI
 
1911 Gold Corporate Presentation June 2025
1911 Gold Corporate Presentation June 2025
Shaun Heinrichs
 
Kenyan Msme Export Book by Dickens Aluha Mujumba
Kenyan Msme Export Book by Dickens Aluha Mujumba
JoshuaKihara
 
Building a Customer-Centric Business Best Practices.pdf
Building a Customer-Centric Business Best Practices.pdf
Stacy Neir
 
🧪 JIS Z 8901 Class 8 Kanto Loam .pdf
🧪 JIS Z 8901 Class 8 Kanto Loam .pdf
Particle Powder
 
ISO 45001 Certification in Singapore Company
ISO 45001 Certification in Singapore Company
achharsharma105
 
Redefining Business Experiences: The Role of a Corporate Event Management Com...
Redefining Business Experiences: The Role of a Corporate Event Management Com...
Be Executive Events
 
chapter 9 leadership qualityies university of windsor
chapter 9 leadership qualityies university of windsor
zamananalyst29
 
Podcast Show Notes - Rapid International Expansion for Scale-up Stage Tech Bu...
Podcast Show Notes - Rapid International Expansion for Scale-up Stage Tech Bu...
Dave Litwiller
 
Ian McAllister - Respected Photographer And Writer
Ian McAllister - Respected Photographer And Writer
Ian McAllister
 
solulab.com-How to Build a Private LLM.pdf
solulab.com-How to Build a Private LLM.pdf
celinedion89121
 
Ch01.ppt bisnis internasional bisnis internasional
Ch01.ppt bisnis internasional bisnis internasional
devina81
 

Web App Testing With Selenium

  • 1. Web App Testing with Selenium João Prado Maia Lead Software Developer, Alert Logic March 6 th , 2008
  • 2. Unit testing in PHP land Unit testing OOP code usually just business logic code (classes) Not good enough No way to test visual aspect of the app CSS Broken images How do you check JavaScript based pages? How about AJAX calls? Very labor intensive
  • 3. Combined approach Unit testing of business logic code Data access classes Lots of best practices around for this UI testing with Selenium Make sure UI behaves correctly JavaScript based or not Examples: Log in to your app Log out from your app Change your account settings etc
  • 4. Enter Selenium! Selenium Core JavaScript library Used by all other sub-projects Selenium IDE to record tests Firefox extension Playback tests Debug and set breakpoints Selenium RC Java server Controls web browser remotely
  • 5. Selenium IDE Firefox extension Record and replay tests Test files as HTML files (by default) Accepts commands, allowing you to: Run actions on browser Verify that document has valid content Run a suite of UI tests Multiple tests running in sequence
  • 6. Recording and Replaying a Test Demonstration
  • 7. Selenium test structure <html> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;> <title>google_houston</title> </head> <body> <table cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; border=&quot;1&quot;> <thead> <tr><td rowspan=&quot;1&quot; colspan=&quot;3&quot;>google_houston</td></tr> </thead><tbody> <tr> <td>open</td> <td>/</td> <td></td> </tr> <tr> <td>type</td> <td>q</td> <td>houston php</td> </tr> <tr> <td>click</td> <td>btnG</td> <td></td> </tr> <tr> <td>verifyTextPresent</td> <td>Houston PHP / MySQL Users Group</td> <td></td> </tr> </tbody></table> </body> </html>
  • 8. Understanding Selenium Reference documentation http://release.openqa.org/selenium-core/0.8.2/reference.html Key concepts Actions Accessors Assertions Patterns Locators Valid locators values: id=nav_bar name=username dom=document.images[2] xpath=//table[@id=“results”]/tr[1]/td[4] css=a[href=“#top”] link=Logout
  • 9. Running a Test Suite TestRunner interface Run multiple tests in sequence Internal to Selenium Demonstration
  • 10. Test suite structure <table> <tr> <td>Meetup presentation</td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_smarty.html&quot;>Google - smarty</a></td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_latest_php.html&quot;>Google - latest php version</a></td> </tr> <tr> <td><a target=&quot;testFrame&quot; href=&quot;google_houston.html&quot;>Google - houston php</a></td> </tr> </table>
  • 11. Dynamic test suite Put all HTML test files in the same directory Create a new PHP script: <?php $tests = glob('*.html'); ?> <table> <tr> <td>Meetup presentation</td> </tr> <?php foreach ($tests as $filename) { ?> <tr> <td> <a target=&quot;testFrame&quot; href=&quot;<?php echo $filename; ?>&quot; > <?php echo ucwords(str_replace('.html', '', str_replace('_', ' ', $filename))); ?> </a> </td> </tr> <?php } ?> </table>
  • 12. Selenium RC Java server controls the browser Windows, Mac OS X, Linux platforms Allows you to write tests in PHP Remotely send commands to Java server Tightly integrated with PHPUnit! Allows you to run UI test suites as regular PHPUnit suites
  • 13. Selenium RC requirements PHPUnit PEAR::Testing_Selenium Machine to run the actual UI tests from We run a VMware image with the latest IE/Firefox, another one with IE6 and Firefox 1.5
  • 14. Example of a Test in PHP <?php require_once 'SeleniumTestHelper.php'; class LoginTest extends SeleniumTestHelper { public function testAccessToLoginForm() { $this->selenium->open(&quot;index.php&quot;); $this->selenium->verifyTextPresent('Having trouble logging in?'); } public function testFailedLogin() { $this->selenium->open(&quot;index.php&quot;); $this->selenium->type(&quot;username&quot;, &quot;admin&quot;); $this->selenium->type(&quot;customer&quot;, &quot;2&quot;); $this->selenium->type(&quot;password&quot;, &quot;blahblah&quot;); $this->selenium->clickAndWait(&quot;//input[@value='Log In']&quot;); $this->selenium->verifyTextPresent('Invalid login. Please try again.'); } } ?>
  • 15. HTML content <!-- more stuff here --> <table cellspacing='0' cellpadding='0'> <tr> <th>Name</th> </tr> <tr> <td><input type=&quot;text&quot; class=&quot;textfield&quot; name=&quot;username&quot; /></td> </tr> <tr> <th>Customer ID</th> </tr> <tr> <td><input type=&quot;text&quot; class=&quot;textfield&quot; name=&quot;customer&quot; /></td> </tr> <tr> <th>Password</th> </tr> <tr> <td><input type=&quot;password&quot; class=&quot;textfield&quot; name=&quot;password&quot; /></td> </tr> <tr> <td colspan=&quot;2&quot;> <input type=&quot;image&quot; src=&quot;/4/branding.php?param=btn_login&quot; value=&quot;Log In&quot; /> <span id=&quot;processing&quot; style=&quot;display: none;&quot;> <img src=&quot;/4/images/icons/spinner.gif&quot; /> <strong>Processing...</strong> </span> </td> </tr> </table> <!-- more stuff here -->
  • 16. SeleniumTestHelper <?php require_once '../../setup/config.php'; require_once 'Testing/Selenium.php'; require_once 'PHPUnit2/Framework/TestCase.php'; // ip address of selenium server if (!defined('APP_SELENIUM_SERVER')) { define('APP_SELENIUM_SERVER', '172.17.0.110'); } // which browser to use on this run of the test if (!defined('APP_SELENIUM_BROWSER')) { define('APP_SELENIUM_BROWSER', '*firefox'); } class SeleniumTestHelper extends PHPUnit2_Framework_TestCase { protected $selenium; public function setUp() { $this->selenium = new Testing_Selenium(APP_SELENIUM_BROWSER, APP_BASE_URL . APP_RELATIVE_URL, APP_SELENIUM_SERVER); $this->selenium->start(); } public function tearDown() { $this->selenium->stop(); } } ?>
  • 17. Targeting browsers Selenium RC allows for you to run tests in different browsers Windows Internet Explorer 6.0+ Firefox 1.5+ Linux Firefox 1.5+ Opera 9.0.2 Konqueror 3.5.3 Mac OS X Firefox 1.5+ Full list at http://selenium-rc.openqa.org/
  • 18. How to target browsers First parameter tells Testing_Selenium what browser to use $selenium = new Testing_Selenium(“*firefox”, “http://google.com”, “192.168.1.12”); Possible values: *firefox *iexplore *opera *custom more details on this at http://wiki.openqa.org/display/SRC/Selenium+RC+FAQ Idea: setup multiple VMware images, one with a specific set of browsers
  • 19. RC Test suite <?php if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'TestSuite::main'); } require_once 'SeleniumTestHelper.php'; class TestSuite { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Framework'); $test_files = glob('*Test.php'); foreach ($test_files as $file) { $suite->addTestFile($file); } return $suite; } } if (PHPUnit2_MAIN_METHOD == 'TestSuite::main') { TestSuite::main(); } ?>
  • 20. Advanced Tests Testing AJAX requests Look for after effects of the AJAX request, such as: Icon gets displayed Hidden <DIV> is made visible XPath support //div[@id=“recent_traffic_graph”]/img //div[4]/div/div/div[1]/div[1]/table/tbody/tr/td[2]/span[4]/a/img //table[@id=“table1”]//tr[4]/td[2] (//table[@class=“results”])//th[text()=“Price”]/../tr
  • 21. Last slide Selenium (IDE, RC, etc) http://openqa.org PHPUnit http://phpunit.de PEAR::Testing_Selenium http://pear.php.net/package/Testing_Selenium Recommended books PHPUnit Pocket Guide http://oreilly.com/catalog/phpunitpg/ PHPUnit Pocket Guide (online for free) http://phpunit.de/pocket_guide/ Smarty PHP Template Programming and Applications (buy it!) http://smartybook.com