You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Automating your QA with Visual Regression Testing Example Repository
2
+
3
+
This repository is an example for my talk [Automating your QA with Visual Regression Testing](https://2019.europe.wordcamp.org/session/automating-your-qa-with-visual-regression-testing/) at WordCamp Europe 2019. It uses [BackstopJS](https://github.com/garris/BackstopJS/) and [Node JS](https://nodejs.org/) to automate visual QA. The slides for the talk can be found [here](https://goo.gl/V7QtNw).
4
+
5
+
## Prerequisites
6
+
7
+
You will need:
8
+
9
+
* A local development environment with [Node JS/NPM](https://docs.npmjs.com/getting-started/installing-node)
10
+
*[Google Chrome](https://www.google.com/chrome/)
11
+
* A live, web-accessible WordPress site
12
+
* Another environment of the WordPress site above (e.g. local, staging, etc.)
13
+
14
+
### Getting The Code
15
+
16
+
Either clone this repository using Git or download the [`master` branch `.zip` file](https://github.com/ataylorme/wordcamp-europe-2019-visual-regression-testing-workshop/archive/master.zip).
17
+
18
+
## Instructions
19
+
20
+
After setting up the repository locally (see above) you will need to:
21
+
22
+
1. Run the command `npm install` to download dependencies
23
+
1. Run the command `npm run start`
24
+
* Type the number of a site from the list or enter _all_ to test all sites in `src/sitesToTest.js`
25
+
1. Check out the results from the sample test
26
+
* They should open in your browser automatically
27
+
1. Edit `src/sitesToTest.js`
28
+
* This is where the list of sites to test is stored
29
+
* Try changing to one (or more) of your sites
30
+
*`BackstopReferenceBaseUrl` is your non-production environment (local, staging, etc.) URL
31
+
*`BackstopTestUrl` is your production site URL
32
+
* Adjust `pathsToTest`, which is the array of URIs to test for each site
33
+
1. Edit `src/backstopConfig.js` to adjust viewports, delay, hidden selectors, etc.
34
+
1. Run the command `npm run build`.
35
+
* This command needs to be run anytime you edit items in `src`
36
+
1. Run the command `npm run start`.
37
+
* To test a single site, enter its number from the list, or enter `all` to test all sites in `src/sitesToTest.js`
38
+
39
+
**Troubleshooting**
40
+
If you are having issues with the script hanging or BackstopJS taking a long time there may be headless Chrome instances that didn't close properly.
41
+
42
+
Try `pkill -f "(chrome)?(--headless)"` on Mac/Linux or `Get-CimInstance Win32_Process -Filter "Name = 'chrome.exe' AND CommandLine LIKE '%--headless%'" | %{Stop-Process $_.ProcessId}` in Windows PowerShell.
(0,_fancyLog.default)(_ansiColors.default.yellow(`Testing site ${i} of ${siteCount}...`));// https://nodejs.org/docs/latest/api/child_process.html#child_process_child_process_execsync_command_options
(0,_throwError.default)(_ansiColors.default.red(`${_ansiColors.default.gray(siteToTest)} is not a valid site. Check the name you entered against the ${_ansiColors.default.gray('sitesToTest.js')} config file`));
(0,_fancyLog.default)(`Running Backstop tests for ${site.label}`);
45
+
(0,_backstopjs.default)('reference',{
46
+
config: currentConfig
47
+
}).then(()=>{
48
+
(0,_fancyLog.default)(`Backstop JS reference complete for ${site.label}! Starting tests.`);
49
+
(0,_backstopjs.default)('test',{
50
+
config: currentConfig
51
+
}).then(()=>{
52
+
(0,_fancyLog.default)(_ansiColors.default.yellow(`Report saved to ${_ansiColors.default.gray(`${rootDir}/backstop_data/${site.name}/html_report/index.html`)}`));
53
+
(0,_fancyLog.default)(_ansiColors.default.green(`Backstop JS tests passed for ${site.label}!`));
54
+
}).catch(()=>{
55
+
(0,_fancyLog.default)(`Report saved to "${rootDir}/backstop_data/${site.name}/html_report/index.html"`);
56
+
(0,_throwError.default)(_ansiColors.default.red(`Backstop JS tests failed for ${_ansiColors.default.gray(site.label)}!`));
57
+
});
58
+
}).catch(()=>{
59
+
(0,_throwError.default)(_ansiColors.default.red(`Backstop JS reference failed for ${_ansiColors.default.gray(site.label)}! Please check the BackstopReferenceBaseUrl`));
0 commit comments