Presentation from JAB-2014, I have talked about how we have setup PHPUnit and Selenium Webdriver for Testing Joomla CMS!,
How we can setup System test Suite for a Joomla! Component
2. OUTLINE
What is System Testing?
How is automation testing used in Joomla?
How do I set up my PC to run system tests?
How do I write system tests for my extension?
3. SOME BASIC QUESTION
What is Automated testing?
Running programs to test other programs
What is PHPunit?
A library used for creating PHP unit tests
What is Selenium?
A program which is used for creating System Tests,
Automating browsers
What is Xpath?
A syntax for navigating elements in a web page
4. AUTOMATED TESTING IN JOOMLA
Webdriver Tests was started in Nov, 2012, by
Mark Dexter
Backend CMS tests along with Selenium
Webdriver were developed as part of GSOC,2013.
Frontend CMS Tests are being developed as part
of GSOC, 2014.
7. WHY DO WE NEED AUTOMATION
TESTING
Helps in preventing software release with
obvious bugs
Allows you to integrate continuous testing into
your development process
Saves a lot of time
Reliable
Cost reduction
9. SYSTEM TESTING
Test at the user level from outside the program
Testing a process for example: testing user
creations, testing Tag creations
Running the application and testing it just like a
user would do.
10. SETUP TO RUN SYSTEM TESTS
PHPUnit 3.6 or higher (latest is 4.1) Use PHAR
to install.
PHP 5.3.8 (required for Webdriver system tests)
Curl package (extension=php_curl.dll or
php_curl.so in php.ini)
11. SETUP TO RUN SYSTEM TESTS-2
Download Selenium Server (Java ".jar") from
seleniumhq.com
run in background
Checkout Joomla from Github.com
Create configdef.php file (tests/system/servers)
used for old and new tests
13. EXECUTE SYSTEM TESTS
Run Selenium Server in the background
do once and let it run
Change to desired folder
Webdriver System: tests/system/webdriver/tests
phpunit <optional name of sub-folder or file>
14. TEST CONFIGURATION
phpunit.xml.dist / phpunit.xml
.dist is included in Git, .xml is local only
configdef.php.dist is generic
need to create configdef.php file with local values
15. LETS LOOK AT A DEMO
Installation Tests
Tag Manager Tests
16. SELENIUM WEBDRIVER VS
SELENIUM IDE
IDE is a record and playback tool, which is not
reliable as compared to Selenium Webdriver.
Selenium IDE tests require huge amount of
Maintenance
Webdriver has a Object Oriented API
It is difficult to use Selenium IDE for checking
complex test cases involving dynamic contents
No Programming logic (like loops, conditional
statements) can be applied in Selenium IDE.
19. PAGE CLASSES
Classes that contains specific details about the
Joomla page
$waitForXpath: identifies this page
$url: URL for the page
Elements: toolbar, input elements, menu elements
Methods specific to the page:
For example: TagManagerPage would contain functions like
createTag(), editTag(), deleteTag(), searchTag()
Page classes do not perform any assertions, it is
the job of test class to perform assertions.
Re-Usable/Maintainable code
21. ACTIONS
We can perform several actions such as:
Click, sendKeys, Select etc.
We can not perform certain actions such as:
Changing Value of a Hidden Field.
Element must be present in the view to access.
22. VERFICATION
We perform several assertions based on our
actions
Did the right page load?
Did we get the expected message?
Was the item created?
Was the state of a item changed?
Was the item deleted?
Can we search for the item?
Are all the expected elements present on the page?
23. WEBDRIVER FOR PHP
Requires third-party library
Using Nearsoft library
https://github.com/Nearsoft/PHP-SeleniumClient
Located in folder
tests/system/webdriver/SeleniumClient
Provides the "magic" for interacting with the
page
24. WEBDRIVER CLASS
Provided by third party library for PHP
PHP implementations based on Java
Found in
tests/system/webdriver/SeleniumClient/WebDriv
er.php
25. WEBDRIVER KEY METHODS
get($url) – loads URL
findElement(By::<>) – returns a WebElement
xPath, id, name, className, cssSelector, linkText,
partialLinkText, tagName
findElements(By::<>)
returns array of WebElements (can be zero)
executeScript() – executes JavaScript
for example, move mouse to location
26. WEB ELEMENTS KEY METHODS
sendKeys(): types into element
getText(): returns element text
getTagName: returns tag name
getAttribute: returns value of attribute
clear(): clears text
click(): clicks
submit(): submits form
28. LOCATORS
Good Locators are:
Unique
Descriptive
Unlikely to change
CSS and Xpaths are mostly used selectors in automation
testing, ex.
Xpath Selector: //div[@id='example']//a
Css Selector: css=div.example a
Performance of them varies with different browsers, for
more details about CSS Vs Xpath please see here:
http://elementalselenium.com/tips/category/benchmarks
‘ID’ selectors is the fastest method, but for that we need to
have id attributes for all the test fields
29. XPATHS
Most powerful option for finding elements
Used in findElement(By::xPath(“XPATH of
Element”)) method of webdriver.
Slower than CSS selectors on most of the
browsers but reliable, and easy to maintain.
30. PHPUNIT ASSERT STATMENTS
Assertions are expression which verify testing
logic and make sure that application behaves in
expected way.
ex. assertTrue, assertFalse, assertEquals
31. SCALING SYSTEM TEST
Use cloud-based testing services
Parallelize tests to run multiple test classes at
once
Using Selenium Grid to Parallelize Tests
33. SAUCE LABS
Sauce On Demand is a cloud-based service that
allows you to run automated cross-browser
functional tests at high speeds in parallel, so you
don't need to maintain testing infrastructure.
Sauce Support 65+browser and OS combination .
Operating Systems like Windows, Linux, Mac ,
Browsers like Internet Explorer, Chrome, Firefox,
Safari, Opera, IPhone, Ipad, Android
All latest browsers versions are available.
34. INTEGRATING SAUCE WITH
JOOMLA SYSTEM TESTS
Setup Sauce Library
Get Sauce Connect
Change desired capabilities according to Sauce
Configuration
Change Host name and port No. for webdriver
connection
Demo
You release a new version and someone finds a really obvious bug (most likely due to a stupid, last-minute coding error).
Stop releasing new versions??
More Testing before each release
Continuous testing during development
Test daily after each change to the code base
Parent class for all test classes
Extends PHPUnit_Framework_TestCase (PHPUnitEclass)
Uses bootstrap.php to autoload, configdef.php to get SeleniumConfig class
Holds methods needed by all test classes
doAdminLogin(), doAdminLogout()
Problem: For an application that is under continuous development, web pages can change any time
New Elements introduced
Change in links, change in buttons
Changes in the way the page looks
Any change in the application should require changes in the page classes not in the actual test
Logic for interacting with the application is written in Test Class but functions to perform that logic are present in the Page Classes
Good Locators are:
Unique
Descriptive
Unlikely to change
CSS and Xpaths are mostly used selectors in automation testing, ex.
Xpath Selector: //div[@id=&apos;example&apos;]//a
Css Selector: css=div.example a
Performance of them varies with different browsers, for more details about CSS Vs Xpath please see here: http://elementalselenium.com/tips/category/benchmarks
‘ID’ selectors is the fastest method, but for that we need to have id attributes for all the test fields