SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
WordPress Acceptance
Testing: Solved!
https://github.com/10up/wpacceptance
What Is the Purpose of Automated
Testing?
• Testing helps us reduce bugs/regressions and
ensures our application meets requirements.
• Manual testing, while also useful and important,
is slow, expensive, and prone to human error.
• Automated testing can be integrated such that it
is run continuously e.g. part of a development
and delivery pipeline.
Types of Automated Testing
• There are many different types of automated
testing: unit, functional, performance,
acceptance/end-to-end, integration, etc.
• WordPress bundles integration/unit tests as well
as end to end tests for certain features.
Automated Testing Tools
• WordPress PHPUnit Test Suite - the framework used
by core and one you can include in plugins/themes to
write integration tests. Based on PHPUnit.
• WP Mock - a project started by 10up for writing true
unit tests for WordPress. Also based on PHPUnit.
• A number of acceptance testing frameworks e.g.
Codeception. Custom built ones e.g. Gutenberg’s
end-to-end testing system.
• JS testing frameworks
What Is Acceptance Testing?
• Acceptance testing is testing that an application
behaves as expected.
• In the web application world, this usually means
simulating a real user interacting with a web
application via a browser.
The Problem
• Acceptance testing is challenging because
everyone and every system (CI) running the
tests must be running the tests against the same
codebase, environment, and database.
The Problem (cont.)
• Codeception is a popular PHP framework for writing acceptance
tests. The framework does not bundle any functionality around the
environment or database sharing.
• Different engineers on the team often run different local
environments leading to test inconsistencies.
• When an engineer runs the tests on their local, the tests are run
against their local database. Different members of the
engineering team have different local databases and it is tough
to keep everyone in sync.
• To make this work with CI you’d have to create a way for your CI
tool to start a web environment and pass it predefined database
exports.
https://codeception.com
WP Acceptance Overview
• WP Acceptance is a toolkit that empowers
developers and CI pipelines to test codebases
using version controlled acceptance tests and
sharable environments.
https://github.com/10up/wpacceptance
What Makes WP Acceptance Powerful?
• WP Acceptance lets you create environment
instructions to be version controlled with your
tests. Every time you, a team member, or a CI
pipeline run the tests, an environment will be
created from those instructions guaranteeing the
same results for everyone.
Environment Instructions
• Environment instructions look like this:

install wordpress where version is latest and url is http://url.test



activate plugin where name is safe-redirect-manager

install theme where name is twentynineteen



create post where title is Test and content is “Test content”
Read about supported instructions: https://github.com/10up/wpinstructions
wpacceptance.json
• All WP Acceptance projects contain a file named
wpacceptance.json. Here’s an example:
{
"name": "10up-experience",
"exclude": [
"node_modules"
],
"tests": [
"./tests/wpa/*.php"
],
"enforce_clean_db": false,
"project_path": "%WP_ROOT%/wp-content/plugins/10up-experience",
[
"install wordpress where url is http://10upexperience.test",
"activate plugin where name is 10up-experience",
"install theme where name is twentynineteen"
]
]
}
Snapshots
• Sometimes you need to test in a complex
environment e.g. you are building a site with 30
plugins and large database for a client.
• For this, you will want to use a Snapshot. WP
Acceptance lets you run your tests on
Environment Instructions or Snapshot(s).
• Snapshots are based on the WP Snapshots
project: https://github.com/10up/wpsnapshots
Snapshots (cont.)
• In the snapshot workflow you will need to prepare a
“primary” snapshot for the development team to use.
• You can run WPA against your local environment and save
the snapshot:

wpacceptance run --local --save_snapshot
• This will update your wpacceptance.json file with the new
snapshot ID so other developers/CI can use that
snapshot.
• When major changes are made to the site e.g. new
content types, you will want to create a new snapshot.
wpacceptance.json
• Here’s a wpacceptance.json file using WP
Snapshots:
{
“name": "distributor",
"exclude": [
"./node_modules"
],
"tests": [
"tests/wpacceptance/*Test.php"
],
"snapshots": [
{
"snapshot_name": "WordPress 5.1.1",
"snapshot_id": "fec81ac24227af6554c93d28d9af2bdf"
}
],
"enforce_clean_db": true,
"bootstrap": "tests/wpacceptance/bootstrap.php",
"repository": "10up"
}
Install and Usage
• WP Acceptance is added to a project via
Composer. You can use it on a theme, plugin, or
in any WordPress application.
• Step 1: composer require 10up/wpacceptance
• Step 2: Create your wpacceptance.json file (or
run ./vendor/bin/wpacceptance init)
• Step 3: ./vendor/bin/wpacceptance run
A Simple Test
You can see a test lets us
interact with the website as
a user.
If “Modal Title” is not visible
after clicking .modal-link,
the test will fail.
$I = $this->openBrowserPage();

$I->moveTo( '/' );

$I->click( 'a.modal-link' );

$I->seeText( 'Modal Title' );
Testing the Admin
$I = $this->openBrowserPage();

$I->login();

$I->moveTo( '/wp-admin/profile.php' );

$I->waitUntilElementVisible( '#wpadminbar' );

$I->fillField( '#first_name', 'Test Name' );

$I->click( '#submit' );

$I->waitUntilElementVisible( '#wpadminbar' );

$I->seeValueInAttribute( '#first_name', 'value', 'Test Name',
'Profile field did not update.' );
Saving a Post
$I = $this->openBrowserPage();
$I->loginAs( 'admin' );
$I->moveTo( 'wp-admin/post-new.php?post_type=redirect_rule' );
$I->fillField( '#srm_redirect_rule_from', '/test' );
$I->fillField( '#srm_redirect_rule_to', '/test2' );
$I->fillField( '#srm_redirect_rule_notes', 'Notes' );
$I->click( '#publish' );
$I->waitUntilElementVisible( '.updated' );
$I->seeValueInProperty( '#srm_redirect_rule_from', 'value', '/test' );
$I->seeValueInProperty( '#srm_redirect_rule_to', 'value', '/test2' );
$I->seeValueInProperty( '#srm_redirect_rule_notes', 'value', 'Notes' );
(From Safe Redirect Manager)
Standard Test Suite
• WP Acceptance includes standard tests that you
can include in any test suite
• The standard tests ensure basic functionality is
working. This is useful as often times while
building plugins and themes we can break
things and not know about it.
Standard Test Suite
• Test the front end loads properly.
• Test that an admin can create a post.
• Test the admin bar is showing.
• Test users can update their profile.
• Test users can update general settings.
• Etc.
Standard Test Suite
class MyTests extends WPAcceptancePHPUnitTestCase {
/**
* @testdox I can log in.
*/
public function testLogin() {
parent::_testLogin();
}
}
Continuous Integration
• WP Acceptance works great in Travis. Here’s an
example .travis.yml file:
language: php
php:
- 7.2
before_script:
- composer install
script:
- ./vendor/bin/wpacceptance run
sudo: required
services: docker
Debugging
• WP Acceptance provides tools for debugging
problematic tests locally.
• Use verbose flag(s):

wpacceptance run -v
• Watch the browser as tests run:

wpacceptance run --show_browser
• Run the tests slower:

wpacceptance run --slowmo=500
Examples
• https://github.com/10up/distributor
• https://github.com/10up/safe-redirect-manager
• https://github.com/10up/10up-experience
Extensive Documentation
https://wpacceptance.readthedocs.io/en/latest/
Questions?
taylor.lovett@10up.com

@tlovett12

10up.com

Contenu connexe

Tendances

Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David TorroijaDavid Torroija
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousaEmma Armstrong
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumBrian Jordan
 
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
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberKMS Technology
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
JavaLand - Integration Testing How-to
JavaLand - Integration Testing How-toJavaLand - Integration Testing How-to
JavaLand - Integration Testing How-toNicolas Fränkel
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorCubet Techno Labs
 

Tendances (20)

Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David Torroija
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousa
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Maven
MavenMaven
Maven
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS Curriculum
 
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
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
 
Maven
MavenMaven
Maven
 
ASP.NET MVC Extensibility
ASP.NET MVC ExtensibilityASP.NET MVC Extensibility
ASP.NET MVC Extensibility
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
JavaLand - Integration Testing How-to
JavaLand - Integration Testing How-toJavaLand - Integration Testing How-to
JavaLand - Integration Testing How-to
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 

Similaire à WordPress Acceptance Testing, Solved!

The WP Engine Developer Experience. Increased agility, improved efficiency.
The WP Engine Developer Experience. Increased agility, improved efficiency.The WP Engine Developer Experience. Increased agility, improved efficiency.
The WP Engine Developer Experience. Increased agility, improved efficiency.WP Engine
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudCarlos Sanchez
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Drupalcon Paris
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIWP Engine
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsPablo Godel
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command LineKelly Dwan
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build PipelineSamuel Brown
 
Hands On with Selenium and WebDriver
Hands On with Selenium and WebDriverHands On with Selenium and WebDriver
Hands On with Selenium and WebDriverTechWell
 
Azure DevOps Deployment Group
Azure DevOps Deployment GroupAzure DevOps Deployment Group
Azure DevOps Deployment GroupRiwut Libinuko
 
Structured Functional Automated Web Service Testing
Structured Functional Automated Web Service TestingStructured Functional Automated Web Service Testing
Structured Functional Automated Web Service Testingrdekleijn
 
Better Testing With PHP Unit
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unitsitecrafting
 
Andreas Grabner - Performance as Code, Let's Make It a Standard
Andreas Grabner - Performance as Code, Let's Make It a StandardAndreas Grabner - Performance as Code, Let's Make It a Standard
Andreas Grabner - Performance as Code, Let's Make It a StandardNeotys_Partner
 
PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Workerjungkees
 
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsDevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsAmazon Web Services
 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf
 

Similaire à WordPress Acceptance Testing, Solved! (20)

The WP Engine Developer Experience. Increased agility, improved efficiency.
The WP Engine Developer Experience. Increased agility, improved efficiency.The WP Engine Developer Experience. Increased agility, improved efficiency.
The WP Engine Developer Experience. Increased agility, improved efficiency.
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command Line
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
 
Hands On with Selenium and WebDriver
Hands On with Selenium and WebDriverHands On with Selenium and WebDriver
Hands On with Selenium and WebDriver
 
FV04_MostoviczT_RAD
FV04_MostoviczT_RADFV04_MostoviczT_RAD
FV04_MostoviczT_RAD
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
Azure DevOps Deployment Group
Azure DevOps Deployment GroupAzure DevOps Deployment Group
Azure DevOps Deployment Group
 
Structured Functional Automated Web Service Testing
Structured Functional Automated Web Service TestingStructured Functional Automated Web Service Testing
Structured Functional Automated Web Service Testing
 
Better Testing With PHP Unit
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unit
 
Andreas Grabner - Performance as Code, Let's Make It a Standard
Andreas Grabner - Performance as Code, Let's Make It a StandardAndreas Grabner - Performance as Code, Let's Make It a Standard
Andreas Grabner - Performance as Code, Let's Make It a Standard
 
Maven advanced
Maven advancedMaven advanced
Maven advanced
 
19servlets
19servlets19servlets
19servlets
 
PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Worker
 
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsDevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
 
WinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release PipelinesWinOps Conf 2016 - Michael Greene - Release Pipelines
WinOps Conf 2016 - Michael Greene - Release Pipelines
 

Plus de Taylor Lovett

Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Taylor Lovett
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterpriseTaylor Lovett
 
Wordpress search-elasticsearch
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearchTaylor Lovett
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
 
What You Missed in Computer Science
What You Missed in Computer ScienceWhat You Missed in Computer Science
What You Missed in Computer ScienceTaylor Lovett
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLITaylor Lovett
 

Plus de Taylor Lovett (10)

Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
 
Wordpress search-elasticsearch
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearch
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
What You Missed in Computer Science
What You Missed in Computer ScienceWhat You Missed in Computer Science
What You Missed in Computer Science
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLI
 

Dernier

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 

Dernier (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 

WordPress Acceptance Testing, Solved!

  • 2. What Is the Purpose of Automated Testing? • Testing helps us reduce bugs/regressions and ensures our application meets requirements. • Manual testing, while also useful and important, is slow, expensive, and prone to human error. • Automated testing can be integrated such that it is run continuously e.g. part of a development and delivery pipeline.
  • 3. Types of Automated Testing • There are many different types of automated testing: unit, functional, performance, acceptance/end-to-end, integration, etc. • WordPress bundles integration/unit tests as well as end to end tests for certain features.
  • 4. Automated Testing Tools • WordPress PHPUnit Test Suite - the framework used by core and one you can include in plugins/themes to write integration tests. Based on PHPUnit. • WP Mock - a project started by 10up for writing true unit tests for WordPress. Also based on PHPUnit. • A number of acceptance testing frameworks e.g. Codeception. Custom built ones e.g. Gutenberg’s end-to-end testing system. • JS testing frameworks
  • 5. What Is Acceptance Testing? • Acceptance testing is testing that an application behaves as expected. • In the web application world, this usually means simulating a real user interacting with a web application via a browser.
  • 6.
  • 7. The Problem • Acceptance testing is challenging because everyone and every system (CI) running the tests must be running the tests against the same codebase, environment, and database.
  • 8. The Problem (cont.) • Codeception is a popular PHP framework for writing acceptance tests. The framework does not bundle any functionality around the environment or database sharing. • Different engineers on the team often run different local environments leading to test inconsistencies. • When an engineer runs the tests on their local, the tests are run against their local database. Different members of the engineering team have different local databases and it is tough to keep everyone in sync. • To make this work with CI you’d have to create a way for your CI tool to start a web environment and pass it predefined database exports. https://codeception.com
  • 9. WP Acceptance Overview • WP Acceptance is a toolkit that empowers developers and CI pipelines to test codebases using version controlled acceptance tests and sharable environments. https://github.com/10up/wpacceptance
  • 10. What Makes WP Acceptance Powerful? • WP Acceptance lets you create environment instructions to be version controlled with your tests. Every time you, a team member, or a CI pipeline run the tests, an environment will be created from those instructions guaranteeing the same results for everyone.
  • 11. Environment Instructions • Environment instructions look like this:
 install wordpress where version is latest and url is http://url.test
 
 activate plugin where name is safe-redirect-manager
 install theme where name is twentynineteen
 
 create post where title is Test and content is “Test content” Read about supported instructions: https://github.com/10up/wpinstructions
  • 12. wpacceptance.json • All WP Acceptance projects contain a file named wpacceptance.json. Here’s an example: { "name": "10up-experience", "exclude": [ "node_modules" ], "tests": [ "./tests/wpa/*.php" ], "enforce_clean_db": false, "project_path": "%WP_ROOT%/wp-content/plugins/10up-experience", [ "install wordpress where url is http://10upexperience.test", "activate plugin where name is 10up-experience", "install theme where name is twentynineteen" ] ] }
  • 13. Snapshots • Sometimes you need to test in a complex environment e.g. you are building a site with 30 plugins and large database for a client. • For this, you will want to use a Snapshot. WP Acceptance lets you run your tests on Environment Instructions or Snapshot(s). • Snapshots are based on the WP Snapshots project: https://github.com/10up/wpsnapshots
  • 14. Snapshots (cont.) • In the snapshot workflow you will need to prepare a “primary” snapshot for the development team to use. • You can run WPA against your local environment and save the snapshot:
 wpacceptance run --local --save_snapshot • This will update your wpacceptance.json file with the new snapshot ID so other developers/CI can use that snapshot. • When major changes are made to the site e.g. new content types, you will want to create a new snapshot.
  • 15. wpacceptance.json • Here’s a wpacceptance.json file using WP Snapshots: { “name": "distributor", "exclude": [ "./node_modules" ], "tests": [ "tests/wpacceptance/*Test.php" ], "snapshots": [ { "snapshot_name": "WordPress 5.1.1", "snapshot_id": "fec81ac24227af6554c93d28d9af2bdf" } ], "enforce_clean_db": true, "bootstrap": "tests/wpacceptance/bootstrap.php", "repository": "10up" }
  • 16. Install and Usage • WP Acceptance is added to a project via Composer. You can use it on a theme, plugin, or in any WordPress application. • Step 1: composer require 10up/wpacceptance • Step 2: Create your wpacceptance.json file (or run ./vendor/bin/wpacceptance init) • Step 3: ./vendor/bin/wpacceptance run
  • 17. A Simple Test You can see a test lets us interact with the website as a user. If “Modal Title” is not visible after clicking .modal-link, the test will fail. $I = $this->openBrowserPage();
 $I->moveTo( '/' );
 $I->click( 'a.modal-link' );
 $I->seeText( 'Modal Title' );
  • 18. Testing the Admin $I = $this->openBrowserPage();
 $I->login();
 $I->moveTo( '/wp-admin/profile.php' );
 $I->waitUntilElementVisible( '#wpadminbar' );
 $I->fillField( '#first_name', 'Test Name' );
 $I->click( '#submit' );
 $I->waitUntilElementVisible( '#wpadminbar' );
 $I->seeValueInAttribute( '#first_name', 'value', 'Test Name', 'Profile field did not update.' );
  • 19. Saving a Post $I = $this->openBrowserPage(); $I->loginAs( 'admin' ); $I->moveTo( 'wp-admin/post-new.php?post_type=redirect_rule' ); $I->fillField( '#srm_redirect_rule_from', '/test' ); $I->fillField( '#srm_redirect_rule_to', '/test2' ); $I->fillField( '#srm_redirect_rule_notes', 'Notes' ); $I->click( '#publish' ); $I->waitUntilElementVisible( '.updated' ); $I->seeValueInProperty( '#srm_redirect_rule_from', 'value', '/test' ); $I->seeValueInProperty( '#srm_redirect_rule_to', 'value', '/test2' ); $I->seeValueInProperty( '#srm_redirect_rule_notes', 'value', 'Notes' ); (From Safe Redirect Manager)
  • 20. Standard Test Suite • WP Acceptance includes standard tests that you can include in any test suite • The standard tests ensure basic functionality is working. This is useful as often times while building plugins and themes we can break things and not know about it.
  • 21. Standard Test Suite • Test the front end loads properly. • Test that an admin can create a post. • Test the admin bar is showing. • Test users can update their profile. • Test users can update general settings. • Etc.
  • 22. Standard Test Suite class MyTests extends WPAcceptancePHPUnitTestCase { /** * @testdox I can log in. */ public function testLogin() { parent::_testLogin(); } }
  • 23. Continuous Integration • WP Acceptance works great in Travis. Here’s an example .travis.yml file: language: php php: - 7.2 before_script: - composer install script: - ./vendor/bin/wpacceptance run sudo: required services: docker
  • 24. Debugging • WP Acceptance provides tools for debugging problematic tests locally. • Use verbose flag(s):
 wpacceptance run -v • Watch the browser as tests run:
 wpacceptance run --show_browser • Run the tests slower:
 wpacceptance run --slowmo=500