SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

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