selenium-webdriver with phpunit automation test for joomla cms!

Post on 10-May-2015

1.109 Views

Category:

Presentations & Public Speaking

1 Downloads

Preview:

Click to see full reader

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

TRANSCRIPT

AUTOMATED SYSTEM TESTS FOR JOOMLAPuneet Kala

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?

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

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.

DEVELOPER’S NIGHTMARE

HOW TO AVOID?

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

ALTERNATIVE TO AUTOMATION TESTING

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.

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)

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

FILE STRUCTURE

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>

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

LETS LOOK AT A DEMO

Installation Tests

Tag Manager Tests

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.

ANATOMY OF WEBDRIVER TEST CLASS

PAGE OBJECT DESIGN PATTERN

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

TEST DETAIL

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.

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?

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

WEBDRIVER CLASS

Provided by third party library for PHP

PHP implementations based on Java

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

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

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

LOCATOR STRATEGIES

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

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.

PHPUNIT ASSERT STATMENTS

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

ex. assertTrue, assertFalse, assertEquals

SCALING SYSTEM TEST

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

at once

Using Selenium Grid to Parallelize Tests

SAUCE-LABS

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.

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

THANKS!

Email ID:puneet.0191@gmail.com

Twitter: puneet_kala

Skype: puneet.0191

INEVITABLE

top related