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
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
TESTS FOR JOOMLA
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?
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,
What is Xpath?
A syntax for navigating elements in a web page
AUTOMATED TESTING IN JOOMLA
Webdriver Tests was started in Nov, 2012, by
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.
WHY DO WE NEED AUTOMATION
Helps in preventing software release with
Allows you to integrate continuous testing into
your development process
Saves a lot of time
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.
SETUP TO RUN SYSTEM TESTS
PHPUnit 3.6 or higher (latest is 4.1) Use PHAR
PHP 5.3.8 (required for Webdriver system tests)
Curl package (extension=php_curl.dll or
php_curl.so in php.ini)
SETUP TO RUN SYSTEM TESTS-2
Download Selenium Server (Java ".jar") from
run in background
Checkout Joomla from Github.com
Create configdef.php file (tests/system/servers)
used for old and new tests
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>
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
LETS LOOK AT A DEMO
Tag Manager Tests
SELENIUM WEBDRIVER VS
IDE is a record and playback tool, which is not
reliable as compared to Selenium Webdriver.
Selenium IDE tests require huge amount of
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.
Classes that contains specific details about the
$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.
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.
We perform several assertions based on our
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?
WEBDRIVER FOR PHP
Requires third-party library
Using Nearsoft library
Located in folder
Provides the "magic" for interacting with the
Provided by third party library for PHP
PHP implementations based on Java
WEBDRIVER KEY METHODS
get($url) – loads URL
findElement(By::<>) – returns a WebElement
xPath, id, name, className, cssSelector, linkText,
returns array of WebElements (can be zero)
for example, move mouse to location
WEB ELEMENTS KEY METHODS
sendKeys(): types into element
getText(): returns element text
getTagName: returns tag name
getAttribute: returns value of attribute
clear(): clears text
submit(): submits form
Good Locators are:
Unlikely to change
CSS and Xpaths are mostly used selectors in automation
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:
‘ID’ selectors is the fastest method, but for that we need to
have id attributes for all the test fields
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.
PHPUNIT ASSERT STATMENTS
Assertions are expression which verify testing
logic and make sure that application behaves in
ex. assertTrue, assertFalse, assertEquals
SCALING SYSTEM TEST
Use cloud-based testing services
Parallelize tests to run multiple test classes at
Using Selenium Grid to Parallelize Tests
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.
INTEGRATING SAUCE WITH
JOOMLA SYSTEM TESTS
Setup Sauce Library
Get Sauce Connect
Change desired capabilities according to Sauce
Change Host name and port No. for webdriver