selenium 2 for php(unit)

33
Fabrizio Branca T3DD12 Selenium 2 for PHP(Unit)

Upload: aoe

Post on 06-May-2015

11.319 views

Category:

Entertainment & Humor


0 download

TRANSCRIPT

Page 1: Selenium 2 for PHP(Unit)

Fabrizio Branca T3DD12

Selenium 2

for PHP(Unit)

Page 2: Selenium 2 for PHP(Unit)

System Developer

AOE media

Wiesbaden

TYPO3 & Magento

Twitter: @fbrnc

Blog: http://www.fabrizio-branca.de

Fabrizio Branca

Page 3: Selenium 2 for PHP(Unit)

• Who has any experience with automated

testing? (PHPUnit,…)

• Who has used Selenium 1?

• Who has used Selenium 2 / Webdriver?

You?!

Page 4: Selenium 2 for PHP(Unit)

http://www.flickr.com/photos/dieselbug2007/414348333/

Page 5: Selenium 2 for PHP(Unit)

• Unit testing

• Performance testing

• Load testing

• Integration testing

• Acceptance testing

Testing

Page 6: Selenium 2 for PHP(Unit)

What is Selenium?

Page 7: Selenium 2 for PHP(Unit)

• Selenium IDE

• Selenium 1

(aka. Selenium RC or Remote Control)

• Selenium 2

(aka. Selenium Webdriver)

• Selenium-Grid

Selenium’s Tool Suite

Page 8: Selenium 2 for PHP(Unit)

Selenium Architecture

Page 9: Selenium 2 for PHP(Unit)

Selenium + WebDriver

2004:

Selenium (Jason Huggins, ThoughtWorks)

2006:

WebDriver (Simon Stewart,

Google)

2009:

Selenium 2

Page 10: Selenium 2 for PHP(Unit)

• New possibilities

– File uploads

– Browser functions (back/forward)

– Switch between urls

– Control mouse

• Different behaviour

– Typing into input boxes

– Interacting with invisible elements

– Viewport

Why Selenium 2?

Page 11: Selenium 2 for PHP(Unit)

• Firefox

• HTMLUnit

• IE

• Chrome (needs extra driver)

• iPhone / iPad

• Android

• …

Selenium 2

Page 12: Selenium 2 for PHP(Unit)

• Download:

http://seleniumhq.org/download/

• Launch: start java -jar C:\Programme\Selenium\selenium-server-standalone-2.20.0.jar

Selenium Server

Page 13: Selenium 2 for PHP(Unit)

• http://code.google.com/p/selenium/wiki/Js

onWireProtocol

• Json over HTTP

Rest API

Page 15: Selenium 2 for PHP(Unit)

• „A very thin wrapper of WebDriver“

• Server API (Json over HTTP)

php-webdriver

Page 16: Selenium 2 for PHP(Unit)

„Menta“ – Selenium Framework

Page 17: Selenium 2 for PHP(Unit)

Why „Menta“?

Page 18: Selenium 2 for PHP(Unit)

• Selenium Testing Framework

• Connects to Selenium 2

• Build on top of php-webdriver

• Developer friendly api to raw Selenium

commands

• Drop-In replacement for PHPUnit-

Selenium

• https://github.com/fbrnc/Menta

Menta

Page 19: Selenium 2 for PHP(Unit)

• Requires PHP 5.3 (using closures)

• Session management (incl. close on CTRL+C and fatal php errors)

• Event/Observer

• Configuration Management

• Create Suite Utility

• Listeners – HTML report (incl. Screenshots)

– Verbose text report

• Components

• Abstract PHPUnit Testcases

• Selenium1 facade

Menta

Page 21: Selenium 2 for PHP(Unit)

• PHPUnit

• default.xml + phpunit.xml

• Menta bootstrap.php

Configuration

Page 22: Selenium 2 for PHP(Unit)

File structure

Page 23: Selenium 2 for PHP(Unit)

$element = $this->getSession()->element(array(

'using' => WebDriver_Container::XPATH,

'value' => '//ul/li'

);

# ... or ...

$helper =

Menta_ComponentManager::get(

'Menta_Component_Helper_Common');

$element =

$helper->getElement('css=#menu li.first');

Selecting elements

Page 24: Selenium 2 for PHP(Unit)

• $element->click();

• $this->getSession()->click();

• $this->getSession()->buttondown();

• $this->getSession()->buttonup();

• $this->getSession()->touch();

• $this->getSession()->moveto();

Interacting with elements

Page 25: Selenium 2 for PHP(Unit)

• Capabilities

• Menta_SessionManager

• ->getSession($forceNew = false);

• ->activeSessionExists()

• ->closeSession()

• Automatic closing sessions on errors and

end of tests

Session Management

Page 26: Selenium 2 for PHP(Unit)

• Implicitly waiting for elements that are not

available yet

Implicit Wait

Page 27: Selenium 2 for PHP(Unit)

• Explict screenshots

• Automatically taking screenshots on errors

and failing tests and embed them into html

report (on client side)

Screenshots

Page 28: Selenium 2 for PHP(Unit)

Demo

Page 29: Selenium 2 for PHP(Unit)

CI integration

Build package

Unit tests Install on

latest

Selenium tests

Install on deploy

QA

Load tests

Install on stage

Install on production

Page 30: Selenium 2 for PHP(Unit)

Verbose Result Printer

Page 31: Selenium 2 for PHP(Unit)

HTML Result

Page 32: Selenium 2 for PHP(Unit)

• http://www.qaautomation.net/?p=365

• http://www.qaautomation.net/?p=498

• http://css.dzone.com/articles/selenium-2-

php-code

• http://rostislav-

matl.blogspot.de/2011/03/moving-to-

selenium-2-on-webdriver-part.html

Further reading

Page 33: Selenium 2 for PHP(Unit)

Questions?

Twitter: @fbrnc

Blog: http://www.fabrizio-branca.de