36
AUTOMATED SYSTEM TESTS FOR JOOMLA Puneet Kala

Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

AUTOMATED SYSTEM TESTS FOR JOOMLAPuneet Kala

Page 2: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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?

Page 3: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 4: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 5: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

DEVELOPER’S NIGHTMARE

Page 6: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

HOW TO AVOID?

Page 7: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 8: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

ALTERNATIVE TO AUTOMATION TESTING

Page 9: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 10: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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)

Page 11: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 12: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

FILE STRUCTURE

Page 13: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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>

Page 14: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 15: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

LETS LOOK AT A DEMO

Installation Tests

Tag Manager Tests

Page 16: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 17: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

ANATOMY OF WEBDRIVER TEST CLASS

Page 18: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

PAGE OBJECT DESIGN PATTERN

Page 19: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 20: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

TEST DETAIL

Page 21: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 22: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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?

Page 23: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 24: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

WEBDRIVER CLASS

Provided by third party library for PHP

PHP implementations based on Java

Found in tests/system/webdriver/SeleniumClient/WebDriver.php

Page 25: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 26: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 27: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

LOCATOR STRATEGIES

Page 28: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 29: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 30: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

PHPUNIT ASSERT STATMENTS

Assertions are expression which verify testing logic and make sure that application behaves in expected way.

ex. assertTrue, assertFalse, assertEquals

Page 31: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

SCALING SYSTEM TEST

Use cloud-based testing services Parallelize tests to run multiple test classes

at once

Using Selenium Grid to Parallelize Tests

Page 32: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

SAUCE-LABS

Page 33: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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.

Page 34: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

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

Page 35: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

THANKS!

Email ID:[email protected]

Twitter: puneet_kala

Skype: puneet.0191

Page 36: Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!

INEVITABLE