SlideShare a Scribd company logo
1 of 22
Download to read offline
Selenium & PHPUnit
made easy with Steward
Berlin PHP Usergroup
4th April 2017
Ondřej Machulda
@OndraM
Annotated slides
Source: https://commons.wikimedia.org/wiki/File:Bicycle_diagram-unif.svg, author Fiestoforo, licence CC BY 3.0
Web app is a machine – like a bicycle. Lots of different parts in different layers, which needs to
fit together to accomplish the one ultimate purpose of the machine – so you can ride the bike.
Source: http://shop.toddmclellan.com/product/disassembled-bike
UNIT TESTS FOR EVERYTHING!
But we usually do test the machine disassembled on smallest piceses. Why? Becase it is easy to test
them - you can easily define their behavior and you can usually easily and fast validate it! Like
inputs/outputs of method and its beavior in edge cases. However, this it not always enough...
Functional system testing
(„end-to-end tests“ / „UI tests“)
Source: http://www.gianlucagimini.it/prototypes/velocipedia.html, author Gianluca Gimini
If you want to make sure the assembled machine works and everything fits together (eg. you can really
drive & steew the bike), you will test the main business critical scenarios from customer point of view.
Thats why these kind of tests is unreplaceable – its your output quality control. Next one in the QA
chain is usually only the customer, and thats too late :-).
Test pyramid
5 %
15 %
80 %
Test pyramid is a visual guide showing how much time you should be investing in which layer of tests. Why
approx. this ratio? The higher layer, the harder is to write and maintain the tests and the slower feedback you
have from them. Unit-tests are fast to write and run, stable and helps with code design – so as a developer
you want to primary write them. But remember the bicycle – you could miss a lot without functional tests.
(WebDriver)
The tool you need is Selenium -
open-source library for browser
automation. You tell it what
actions in browser should be
done and it executes them. The
WebDriver protcol is also W3C
draft standard and it is
implemented in almost all
browsers.
Start Selenium server
$ docker run -p 4444:4444 selenium/standalone-firefox-debug
OR
$ java -jar selenium-server-standalone-3.3.1.jar &
 localhost:4444
Selenium requires practically zero-config installation. You may start it using Docker or local jar file.
Using any of the examples above will start Selenium server listening on port 4444.
Selenium server is platform and language independent (it just listens on the port), and
there is a lot of libraries for many languages – inlcuding PHP. There are also multiple ways
how to run tests in PHP, however we wanted to use PHPUnit, because we are already using
it for our unit tests. And besides a different domain languguage the other tools (like
Codeception, Behat...) has, we were also missing some key features we needed.
Install Steward
$ mkdir selenium-tests
$ composer require lmc-eu/steward
PHPUnit + facebook/php-webdriver = 
So here comes Steward, an open-source tool built on top of PHPUnit and Symfony components. It is a
test-runner (controlled from CLI) and also extension for PHPUnit, integrating the php-webdriver
library. The installation is quite easy, actually, nothing else is needed to start writing tests.
https://github.com/lmc-eu/steward
<?php
namespace My;
use LmcStewardTestAbstractTestCase;
class GithubSearchTest extends AbstractTestCase
{
public function testShouldSubmitSearchFromHeaderAndShowResults()
{
$this->wd->get('https://github.com/');
$searchInput = $this->findByCss('.header-search-input');
$searchInput->sendKeys('symfony')
->submit();
$this->waitForTitle('Search · symfony · GitHub');
$firstItem = $this->findByCss('ul h3 a');
$this->assertSame('symfony/symfony', $firstItem->getText());
$firstItem->click();
$this->waitForTitle('GitHub - symfony/symfony: The Symfony PHP framework');
$headerText = $this->findByCss('h1')->getText();
$this->assertSame('symfony/symfony', $headerText);
}
}
Here you can see some examples of what Selenium is capable of: load URL, locate elements, write to
inputs, read meta titles, read text from elements, click on element etc. And even more complex actions
like chaning the browser window size, executing javascript, navigating back in the history and so on.
Live Demo
Repository with examples:
https://github.com/OndraM/steward-bephpug
Clone the GitHub repository and run the tests like this:
$ cd selenium-tests
$ ./vendor/bin/steward run prod firefox -vv
See the repository for more description and more examples how to start the test execution.
Parallelization
While unit-tests are executed in a matter of seconds, functional tests can take minutes or even more.
To keep their execution time somehow reasonable, you have to parallelize and run multiple tests at
once – what is one of the features Steward provides.
Error reporting
When some test fails, Steward gathers PNG screenshot from the browser and also saves HTML
snapshot of the DOM state of the webpage, so you can debug it later. It also provides results overview
of the test execution progress – using generated webpage or CLI command.
Example of results.xml file as seen in browser. The test status is generated and updated during the
whole run, so you can also watch the progress here.
Example output of `steward results` command – this is CLI equivalent of the reports.xml file.
Page Object Pattern
Page Object is a design pattern from Martin Fowler, which suggest interacting with the webpage UI
through an abstraction – ie. an object with methods mapping the UI structure and UI interactions.
Because in the tests scenario you want to interact with the UI, not with its HTML implementation.
Page objects are also a way how to make your functional tests maintainable in a long-term.
<?php
namespace My;
use LmcStewardTestAbstractTestCase;
class GithubSearchTest extends AbstractTestCase
{
public function testShouldSubmitSearchFromHeaderAndShowResults()
{
$this->wd->get('https://github.com/');
$searchInput = $this->findByCss('.header-search-input');
$searchInput->sendKeys('symfony')
->submit();
$this->waitForTitle('Search · symfony · GitHub');
$firstItem = $this->findByCss('ul h3 a');
$this->assertSame('symfony/symfony', $firstItem->getText());
$firstItem->click();
$this->waitForTitle('GitHub - symfony/symfony: The Symfony PHP framework');
$headerText = $this->findByCss('h1')->getText();
$this->assertSame('symfony/symfony', $headerText);
}
}
This is the original test as shown before, without using page objects.
Source code of the file on GitHub
<?php
namespace My;
use LmcStewardTestAbstractTestCase;
class GithubSearchUsingPageObjectTest extends AbstractTestCase
{
public function testShouldSubmitSearchFormAndShowSearchResults()
{
$this->wd->get('https://github.com/');
$navigationPanel = new NavigationPanel($this);
$searchResultsPanel = $navigationPanel->submitSearchWithQuery('symfony');
$foundItems = $searchResultsPanel->getFoundItems();
$this->assertSame('symfony/symfony', $foundItems[0]);
$projectDetail = $searchResultsPanel->openResultOnIndex(0);
$projectDetailHeader = $projectDetail->getHeader();
$this->assertSame('symfony/symfony', $projectDetailHeader);
}
}
This is the same test case scenario, but rewritten to use page objects.
Source code of the file on GitHub
<?php
namespace MyPanelGithub;
use LmcStewardComponentAbstractComponent;
class NavigationPanel extends AbstractComponent
{
const SEARCH_INPUT_SELECTOR = '.header-search-input';
/**
* @param string $query
* @return SearchResultsPanel
*/
public function submitSearchWithQuery($query)
{
$this->findByCss(self::SEARCH_INPUT_SELECTOR)
->sendKeys($query)
->submit();
$this->waitForTitle('Search · ' . $query . ' · GitHub');
return new SearchResultsPanel($this->tc);
}
}
An example of NavigationPanel page object.
Source code of the file on GitHub
Continuous integration
&
Continuous deployment
Functional tests are also a necessary part of continuous integration and should not be missing in your
continuous deployment pipeline. As you know – the faster you find your bugs, the faster and cheaper
is to fix them!
Summary
Not everything could be covered by unit tests
Test pyramid should not be missing its top
Functional tests may help you sleep better
It is easy to start!
Selenium & Steward
Continuous integration & deployment
 github.com/lmc-eu/steward
 examples source code
 Ondřej Machulda
 ondrejmachulda.cz
 @OndraM

More Related Content

What's hot

Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript TestingScott Becker
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Sam Becker
 
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Fwdays
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016Gavin Pickin
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!Eric Wendelin
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.Javier López
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP applicationJavier López
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTudor Barbu
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemAndres Almiray
 
Google在Web前端方面的经验
Google在Web前端方面的经验Google在Web前端方面的经验
Google在Web前端方面的经验yiditushe
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with JestMichał Pierzchała
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and ClientHow do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and ClientColdFusionConference
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Deutsche Post
 

What's hot (20)

Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 
Maven 3.0 at Øredev
Maven 3.0 at ØredevMaven 3.0 at Øredev
Maven 3.0 at Øredev
 
Test your modules
Test your modulesTest your modules
Test your modules
 
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
Google在Web前端方面的经验
Google在Web前端方面的经验Google在Web前端方面的经验
Google在Web前端方面的经验
 
Sxsw 20090314
Sxsw 20090314Sxsw 20090314
Sxsw 20090314
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and ClientHow do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and Client
 
Code ceptioninstallation
Code ceptioninstallationCode ceptioninstallation
Code ceptioninstallation
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 

Similar to Selenium & PHPUnit made easy with Steward (Berlin, April 2017)

Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With SeleniumJodie Miners
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Puneet Kala
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011Yuriy Gerasimov
 
Selenium Automation in Java Using HttpWatch Plug-in
 Selenium Automation in Java Using HttpWatch Plug-in  Selenium Automation in Java Using HttpWatch Plug-in
Selenium Automation in Java Using HttpWatch Plug-in Sandeep Tol
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialAlan Richardson
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaSandeep Tol
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. ASumanth krishna
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With SeleniumMarakana Inc.
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Yuriy Gerasimov
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaAgile Testing Alliance
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersAjit Jadhav
 

Similar to Selenium & PHPUnit made easy with Steward (Berlin, April 2017) (20)

Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Selenium
SeleniumSelenium
Selenium
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Selenium
SeleniumSelenium
Selenium
 
Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Automation in Java Using HttpWatch Plug-in
 Selenium Automation in Java Using HttpWatch Plug-in  Selenium Automation in Java Using HttpWatch Plug-in
Selenium Automation in Java Using HttpWatch Plug-in
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver Tutorial
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
 
Selenium
SeleniumSelenium
Selenium
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 

More from Ondřej Machulda

Selenium a WebDriver - přítomnost a budoucnost
 Selenium a WebDriver - přítomnost a budoucnost  Selenium a WebDriver - přítomnost a budoucnost
Selenium a WebDriver - přítomnost a budoucnost Ondřej Machulda
 
JSON API: Možná nepotřebujete GraphQL
JSON API: Možná nepotřebujete GraphQLJSON API: Možná nepotřebujete GraphQL
JSON API: Možná nepotřebujete GraphQLOndřej Machulda
 
Trendy a nové možnosti test automation
Trendy a nové možnosti test automationTrendy a nové možnosti test automation
Trendy a nové možnosti test automationOndřej Machulda
 
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)Ondřej Machulda
 
Automatické testování webů v praxi - Barcamp Ostrava 2015
Automatické testování webů v praxi - Barcamp Ostrava 2015Automatické testování webů v praxi - Barcamp Ostrava 2015
Automatické testování webů v praxi - Barcamp Ostrava 2015Ondřej Machulda
 
Jak jsme přepisovali Jobs.cz na Symfony
Jak jsme přepisovali Jobs.cz na SymfonyJak jsme přepisovali Jobs.cz na Symfony
Jak jsme přepisovali Jobs.cz na SymfonyOndřej Machulda
 
OAuth 2.0 a Zend Framework
OAuth 2.0 a Zend FrameworkOAuth 2.0 a Zend Framework
OAuth 2.0 a Zend FrameworkOndřej Machulda
 
Optimistic/Pessimistic Offline Lock
Optimistic/Pessimistic Offline LockOptimistic/Pessimistic Offline Lock
Optimistic/Pessimistic Offline LockOndřej Machulda
 
Hlavní problémy systému on-line rezervace vstupenek do O2 Areny
Hlavní problémy systému on-line rezervace vstupenek do O2 ArenyHlavní problémy systému on-line rezervace vstupenek do O2 Areny
Hlavní problémy systému on-line rezervace vstupenek do O2 ArenyOndřej Machulda
 
Testování systému pro on-line rezervaci vstupenek do O2 Areny
Testování systému pro on-line rezervaci vstupenek do O2 ArenyTestování systému pro on-line rezervaci vstupenek do O2 Areny
Testování systému pro on-line rezervaci vstupenek do O2 ArenyOndřej Machulda
 
Pionýr - stručná historie organizace
Pionýr - stručná historie organizacePionýr - stručná historie organizace
Pionýr - stručná historie organizaceOndřej Machulda
 

More from Ondřej Machulda (12)

Selenium a WebDriver - přítomnost a budoucnost
 Selenium a WebDriver - přítomnost a budoucnost  Selenium a WebDriver - přítomnost a budoucnost
Selenium a WebDriver - přítomnost a budoucnost
 
JSON API: Možná nepotřebujete GraphQL
JSON API: Možná nepotřebujete GraphQLJSON API: Možná nepotřebujete GraphQL
JSON API: Možná nepotřebujete GraphQL
 
Trendy a nové možnosti test automation
Trendy a nové možnosti test automationTrendy a nové možnosti test automation
Trendy a nové možnosti test automation
 
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)
Funkční testování – chybějící vrchol pyramidy (WebExpo 2016)
 
Automatické testování webů v praxi - Barcamp Ostrava 2015
Automatické testování webů v praxi - Barcamp Ostrava 2015Automatické testování webů v praxi - Barcamp Ostrava 2015
Automatické testování webů v praxi - Barcamp Ostrava 2015
 
Jak jsme přepisovali Jobs.cz na Symfony
Jak jsme přepisovali Jobs.cz na SymfonyJak jsme přepisovali Jobs.cz na Symfony
Jak jsme přepisovali Jobs.cz na Symfony
 
OAuth 2.0 a Zend Framework
OAuth 2.0 a Zend FrameworkOAuth 2.0 a Zend Framework
OAuth 2.0 a Zend Framework
 
Optimistic/Pessimistic Offline Lock
Optimistic/Pessimistic Offline LockOptimistic/Pessimistic Offline Lock
Optimistic/Pessimistic Offline Lock
 
Hlavní problémy systému on-line rezervace vstupenek do O2 Areny
Hlavní problémy systému on-line rezervace vstupenek do O2 ArenyHlavní problémy systému on-line rezervace vstupenek do O2 Areny
Hlavní problémy systému on-line rezervace vstupenek do O2 Areny
 
Testování systému pro on-line rezervaci vstupenek do O2 Areny
Testování systému pro on-line rezervaci vstupenek do O2 ArenyTestování systému pro on-line rezervaci vstupenek do O2 Areny
Testování systému pro on-line rezervaci vstupenek do O2 Areny
 
Pionýr - stručná historie organizace
Pionýr - stručná historie organizacePionýr - stručná historie organizace
Pionýr - stručná historie organizace
 
Raid
RaidRaid
Raid
 

Recently uploaded

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Automation Ops Series: Session 3 - Solutions management
Automation Ops Series: Session 3 - Solutions managementAutomation Ops Series: Session 3 - Solutions management
Automation Ops Series: Session 3 - Solutions managementDianaGray10
 
Transport in Open Pits______SM_MI10415MI
Transport in Open Pits______SM_MI10415MITransport in Open Pits______SM_MI10415MI
Transport in Open Pits______SM_MI10415MIRomil Mishra
 
Women in Automation 2024: Career session - explore career paths in automation
Women in Automation 2024: Career session - explore career paths in automationWomen in Automation 2024: Career session - explore career paths in automation
Women in Automation 2024: Career session - explore career paths in automationDianaGray10
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Introduction-to-Wazuh-and-its-integration.pptx
Introduction-to-Wazuh-and-its-integration.pptxIntroduction-to-Wazuh-and-its-integration.pptx
Introduction-to-Wazuh-and-its-integration.pptxmprakaash5
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Arti Languages Pre Seed Pitchdeck 2024.pdf
Arti Languages Pre Seed Pitchdeck 2024.pdfArti Languages Pre Seed Pitchdeck 2024.pdf
Arti Languages Pre Seed Pitchdeck 2024.pdfwill854175
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfROWELL MARQUINA
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 

Recently uploaded (20)

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Automation Ops Series: Session 3 - Solutions management
Automation Ops Series: Session 3 - Solutions managementAutomation Ops Series: Session 3 - Solutions management
Automation Ops Series: Session 3 - Solutions management
 
Transport in Open Pits______SM_MI10415MI
Transport in Open Pits______SM_MI10415MITransport in Open Pits______SM_MI10415MI
Transport in Open Pits______SM_MI10415MI
 
Women in Automation 2024: Career session - explore career paths in automation
Women in Automation 2024: Career session - explore career paths in automationWomen in Automation 2024: Career session - explore career paths in automation
Women in Automation 2024: Career session - explore career paths in automation
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Introduction-to-Wazuh-and-its-integration.pptx
Introduction-to-Wazuh-and-its-integration.pptxIntroduction-to-Wazuh-and-its-integration.pptx
Introduction-to-Wazuh-and-its-integration.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Arti Languages Pre Seed Pitchdeck 2024.pdf
Arti Languages Pre Seed Pitchdeck 2024.pdfArti Languages Pre Seed Pitchdeck 2024.pdf
Arti Languages Pre Seed Pitchdeck 2024.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 

Selenium & PHPUnit made easy with Steward (Berlin, April 2017)

  • 1. Selenium & PHPUnit made easy with Steward Berlin PHP Usergroup 4th April 2017 Ondřej Machulda @OndraM Annotated slides
  • 2. Source: https://commons.wikimedia.org/wiki/File:Bicycle_diagram-unif.svg, author Fiestoforo, licence CC BY 3.0 Web app is a machine – like a bicycle. Lots of different parts in different layers, which needs to fit together to accomplish the one ultimate purpose of the machine – so you can ride the bike.
  • 3. Source: http://shop.toddmclellan.com/product/disassembled-bike UNIT TESTS FOR EVERYTHING! But we usually do test the machine disassembled on smallest piceses. Why? Becase it is easy to test them - you can easily define their behavior and you can usually easily and fast validate it! Like inputs/outputs of method and its beavior in edge cases. However, this it not always enough...
  • 4. Functional system testing („end-to-end tests“ / „UI tests“) Source: http://www.gianlucagimini.it/prototypes/velocipedia.html, author Gianluca Gimini If you want to make sure the assembled machine works and everything fits together (eg. you can really drive & steew the bike), you will test the main business critical scenarios from customer point of view. Thats why these kind of tests is unreplaceable – its your output quality control. Next one in the QA chain is usually only the customer, and thats too late :-).
  • 5. Test pyramid 5 % 15 % 80 % Test pyramid is a visual guide showing how much time you should be investing in which layer of tests. Why approx. this ratio? The higher layer, the harder is to write and maintain the tests and the slower feedback you have from them. Unit-tests are fast to write and run, stable and helps with code design – so as a developer you want to primary write them. But remember the bicycle – you could miss a lot without functional tests.
  • 6. (WebDriver) The tool you need is Selenium - open-source library for browser automation. You tell it what actions in browser should be done and it executes them. The WebDriver protcol is also W3C draft standard and it is implemented in almost all browsers.
  • 7. Start Selenium server $ docker run -p 4444:4444 selenium/standalone-firefox-debug OR $ java -jar selenium-server-standalone-3.3.1.jar &  localhost:4444 Selenium requires practically zero-config installation. You may start it using Docker or local jar file. Using any of the examples above will start Selenium server listening on port 4444.
  • 8. Selenium server is platform and language independent (it just listens on the port), and there is a lot of libraries for many languages – inlcuding PHP. There are also multiple ways how to run tests in PHP, however we wanted to use PHPUnit, because we are already using it for our unit tests. And besides a different domain languguage the other tools (like Codeception, Behat...) has, we were also missing some key features we needed.
  • 9. Install Steward $ mkdir selenium-tests $ composer require lmc-eu/steward PHPUnit + facebook/php-webdriver =  So here comes Steward, an open-source tool built on top of PHPUnit and Symfony components. It is a test-runner (controlled from CLI) and also extension for PHPUnit, integrating the php-webdriver library. The installation is quite easy, actually, nothing else is needed to start writing tests. https://github.com/lmc-eu/steward
  • 10. <?php namespace My; use LmcStewardTestAbstractTestCase; class GithubSearchTest extends AbstractTestCase { public function testShouldSubmitSearchFromHeaderAndShowResults() { $this->wd->get('https://github.com/'); $searchInput = $this->findByCss('.header-search-input'); $searchInput->sendKeys('symfony') ->submit(); $this->waitForTitle('Search · symfony · GitHub'); $firstItem = $this->findByCss('ul h3 a'); $this->assertSame('symfony/symfony', $firstItem->getText()); $firstItem->click(); $this->waitForTitle('GitHub - symfony/symfony: The Symfony PHP framework'); $headerText = $this->findByCss('h1')->getText(); $this->assertSame('symfony/symfony', $headerText); } } Here you can see some examples of what Selenium is capable of: load URL, locate elements, write to inputs, read meta titles, read text from elements, click on element etc. And even more complex actions like chaning the browser window size, executing javascript, navigating back in the history and so on.
  • 11. Live Demo Repository with examples: https://github.com/OndraM/steward-bephpug Clone the GitHub repository and run the tests like this: $ cd selenium-tests $ ./vendor/bin/steward run prod firefox -vv See the repository for more description and more examples how to start the test execution.
  • 12. Parallelization While unit-tests are executed in a matter of seconds, functional tests can take minutes or even more. To keep their execution time somehow reasonable, you have to parallelize and run multiple tests at once – what is one of the features Steward provides.
  • 13. Error reporting When some test fails, Steward gathers PNG screenshot from the browser and also saves HTML snapshot of the DOM state of the webpage, so you can debug it later. It also provides results overview of the test execution progress – using generated webpage or CLI command.
  • 14. Example of results.xml file as seen in browser. The test status is generated and updated during the whole run, so you can also watch the progress here.
  • 15. Example output of `steward results` command – this is CLI equivalent of the reports.xml file.
  • 16. Page Object Pattern Page Object is a design pattern from Martin Fowler, which suggest interacting with the webpage UI through an abstraction – ie. an object with methods mapping the UI structure and UI interactions. Because in the tests scenario you want to interact with the UI, not with its HTML implementation. Page objects are also a way how to make your functional tests maintainable in a long-term.
  • 17. <?php namespace My; use LmcStewardTestAbstractTestCase; class GithubSearchTest extends AbstractTestCase { public function testShouldSubmitSearchFromHeaderAndShowResults() { $this->wd->get('https://github.com/'); $searchInput = $this->findByCss('.header-search-input'); $searchInput->sendKeys('symfony') ->submit(); $this->waitForTitle('Search · symfony · GitHub'); $firstItem = $this->findByCss('ul h3 a'); $this->assertSame('symfony/symfony', $firstItem->getText()); $firstItem->click(); $this->waitForTitle('GitHub - symfony/symfony: The Symfony PHP framework'); $headerText = $this->findByCss('h1')->getText(); $this->assertSame('symfony/symfony', $headerText); } } This is the original test as shown before, without using page objects. Source code of the file on GitHub
  • 18. <?php namespace My; use LmcStewardTestAbstractTestCase; class GithubSearchUsingPageObjectTest extends AbstractTestCase { public function testShouldSubmitSearchFormAndShowSearchResults() { $this->wd->get('https://github.com/'); $navigationPanel = new NavigationPanel($this); $searchResultsPanel = $navigationPanel->submitSearchWithQuery('symfony'); $foundItems = $searchResultsPanel->getFoundItems(); $this->assertSame('symfony/symfony', $foundItems[0]); $projectDetail = $searchResultsPanel->openResultOnIndex(0); $projectDetailHeader = $projectDetail->getHeader(); $this->assertSame('symfony/symfony', $projectDetailHeader); } } This is the same test case scenario, but rewritten to use page objects. Source code of the file on GitHub
  • 19. <?php namespace MyPanelGithub; use LmcStewardComponentAbstractComponent; class NavigationPanel extends AbstractComponent { const SEARCH_INPUT_SELECTOR = '.header-search-input'; /** * @param string $query * @return SearchResultsPanel */ public function submitSearchWithQuery($query) { $this->findByCss(self::SEARCH_INPUT_SELECTOR) ->sendKeys($query) ->submit(); $this->waitForTitle('Search · ' . $query . ' · GitHub'); return new SearchResultsPanel($this->tc); } } An example of NavigationPanel page object. Source code of the file on GitHub
  • 20. Continuous integration & Continuous deployment Functional tests are also a necessary part of continuous integration and should not be missing in your continuous deployment pipeline. As you know – the faster you find your bugs, the faster and cheaper is to fix them!
  • 21. Summary Not everything could be covered by unit tests Test pyramid should not be missing its top Functional tests may help you sleep better It is easy to start! Selenium & Steward Continuous integration & deployment
  • 22.  github.com/lmc-eu/steward  examples source code  Ondřej Machulda  ondrejmachulda.cz  @OndraM