Skip to content

Commit dd8e032

Browse files
Zearinchristian-bromann
authored andcommitted
Update OrganizingTestSuites.md (webdriverio#4437)
Lots of small edits and tweaks, aiming for clarity and conciseness.
1 parent 9e02346 commit dd8e032

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

docs/OrganizingTestSuites.md

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ id: organizingsuites
33
title: Organizing Test Suite
44
---
55

6-
While your project is growing you will inevitably add more and more integration tests. This will increase your build time and will also slow down your productivity. To prevent this you should start to run your tests in parallel. You might have already recognised that WebdriverIO creates for each spec (or feature file in cucumber) a single WebDriver session. In general, you should try to test a single feature in your app in one spec file. Try to not have too many or too few tests in one file. However, there is no golden rule about that.
6+
As projects grow, inevitably more and more integration tests are added. This increases build time and slows productivity.
77

8-
Once you get more and more spec files you should start running them concurrently. To do so you can adjust the `maxInstances` property in your config file. WebdriverIO allows you to run your tests with maximum concurrency meaning that no matter how many files and tests you have, they could run all in parallel. Though there are certain limits (computer CPU, concurrency restrictions).
8+
To prevent this, you should run your tests in parallel. WebdriverIO already tests each spec (or <dfn>feature file</dfn> in Cucumber) in parallel within a single session. In general, try to test a only a single feature per spec file. Try to not have too many or too few tests in one file. (However, there is no golden rule here.)
99

10-
> Let's say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have set maxInstances to 1, the wdio test runner will spawn 3 processes. Therefore, if you have 10 spec files and you set maxInstances to 10; all spec files will get tested at the same time and 30 processes will get spawned.
10+
Once your tests have several spec files, you should start running your tests concurrently. To do this, adjust the `maxInstances` property in your config file. WebdriverIO allows you to run your tests with maximum concurrency—meaning that no matter how many files and tests you have, they can run all in parallel. (Certain limits still apply, like your computer’s CPU, concurrency restrictions, etc.)
1111

12-
You can define the `maxInstance` property globally to set the attribute for all browser. If you run your own WebDriver grid it could be that you have more capacity for one browser than for an other one. In this case you can limit the `maxInstance` in your capability object:
12+
> Let's say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have set `maxInstances` to `1`. The wdio test runner will spawn 3 processes. Therefore, if you have 10 spec files and you set `maxInstances` to `10`, _all_ spec files will get tested simultaneously, and 30 processes will get spawned.
13+
14+
You can define the `maxInstances` property globally to set the attribute for all browsers. If you run your own WebDriver grid, you may (for example) have more capacity for one browser than another. In this case, you can _limit_ the `maxInstances` in your capability object:
1315

1416
```js
1517
// wdio.conf.js
@@ -32,7 +34,9 @@ exports.config = {
3234

3335
## Inherit From Main Config File
3436

35-
If you run your test suite in multiple environments (e.g. dev and integration) it could be helpful to have multiple configuration files to keep them easy manageable. Similar to the [page object concept](PageObjects.md) you first create a main config file. It contains all configurations you share across environments. Then for each environment you can create a file and supplement the information from the main config file with environment specific ones:
37+
If you run your test suite in multiple environments (e.g., dev and integration) it may help to use multiple configuration files to keep things manageable.
38+
39+
Similar to the [page object concept](PageObjects.md), the first thing you’ll need is a main config file. It contains all configurations you share across environments. Then create another config file for each environment, and supplement the the main config with the environment-specific ones:
3640

3741
```js
3842
// wdio.dev.config.js
@@ -56,9 +60,11 @@ exports.config = merge(wdioConf.config, {
5660
exports.config.reporters.push('allure');
5761
```
5862

59-
## Group Test Specs
63+
## Grouping Test Specs
64+
65+
You can easily group test specs in suites and run single specific suites instead of all of them.
6066

61-
You can easily group test specs in suites and run single specific suites instead of all of them. To do so you first need to define your suites in your wdio config:
67+
First, define your suites in your wdio config:
6268

6369
```js
6470
// wdio.conf.js
@@ -80,67 +86,81 @@ exports.config = {
8086
}
8187
```
8288

83-
Now, if you want to only run a single suite, you can pass the suite name as cli argument like:
89+
Now, if you want to only run a single suite, you can pass the suite name as a CLI argument:
8490

8591
```sh
8692
wdio wdio.conf.js --suite login
8793
```
8894

89-
or run multiple suites at once:
95+
Or, run multiple suites at once:
9096

9197
```sh
9298
wdio wdio.conf.js --suite login --suite otherFeature
9399
```
94100

95101
## Run Selected Tests
96102

97-
In some cases, you may wish to only execute a single test or a subset of your suites. With the `--spec` parameter you can specify which suite (Mocha, Jasmine) or feature (Cucumber) should be run. For example if you only want to run your login test, do:
103+
In some cases, you may wish to only execute a single test (or subset of tests) of your suites.
104+
105+
With the `--spec` parameter, you can specify which _suite_ (Mocha, Jasmine) or _feature_ (Cucumber) should be run.
106+
107+
For example, to run only your login test:
98108

99109
```sh
100110
wdio wdio.conf.js --spec ./test/specs/e2e/login.js
101111
```
102112

103-
or run multiple specs at once:
113+
Or run multiple specs at once:
104114

105115
```sh
106116
wdio wdio.conf.js --spec ./test/specs/signup.js --spec ./test/specs/forgot-password.js
107117
```
108118

109-
If the spec passed in is not a path to a spec file, it is used as a filter for the spec file names defined in your configuration file. To run all specs with the word 'dialog' in the spec file names, you could use:
119+
If the `--spec` given does not point to a particular spec file, it is used as a filter for the spec filenames defined in your configuration.
120+
121+
To run all specs with the word 'dialog' in the spec file names, you could use:
110122

111123
```sh
112124
wdio wdio.conf.js --spec dialog
113125
```
114126

115-
Note that each test file is running in a single test runner process. Since we don't scan files in advance (see the next section for information on piping filenames to `wdio`) you _can't_ use for example `describe.only` at the top of your spec file to say Mocha to only run that suite. This feature will help you though to do that in the same way.
127+
Note that each test file is running in a single test runner process. Since we don't scan files in advance (see the next section for information on piping filenames to `wdio`), you _can't_ use (for example) `describe.only` at the top of your spec file to instruct Mocha to run only that suite. This feature will help you to accomplish the same goal.
116128

117129
## Exclude Selected Tests
118130

119-
When needed, if you need to exclude particular spec file(s) from a run, you can use the `--exclude` parameter (Mocha, Jasmine) or feature (Cucumber). For example if you want to exclude your login
120-
test from the test run, do:
121-
```sh
131+
When needed, if you need to exclude particular spec file(s) from a run, you can use the `--exclude` parameter (Mocha, Jasmine) or feature (Cucumber).
132+
133+
For example, to exclude your login test from the test run:
134+
135+
```sh
122136
wdio wdio.conf.js --exclude ./test/specs/e2e/login.js
123137
```
124-
or exclude multiple spec files:
138+
139+
Or, exclude multiple spec files:
140+
125141
```sh
126142
wdio wdio.conf.js --exclude ./test/specs/signup.js --exclude ./test/specs/forgot-password.js
127143
```
128-
or exclude a spec file when filtering using a suite:
129-
```sh
144+
145+
Or, exclude a spec file when filtering using a suite:
146+
147+
```sh
130148
wdio wdio.conf.js --suite login --exclude ./test/specs/e2e/login.js
131149
```
132150

133151
## Run Suites and Test Specs
134152

135-
This will allow you to run an entire suite along with individual spec's.
153+
Run an entire suite along with individual specs.
136154

137155
```sh
138156
wdio wdio.conf.js --suite login --spec ./test/specs/signup.js
139157
```
140158

141159
## Run Multiple, Specific Test Specs
142160

143-
It is sometimes necessary&mdash;in the context of continuous integration and otherwise&mdash;to specify multiple sets of specs to be run at runtime. WebdriverIO's `wdio` command line utility will accept piped input in the form of filenames (from `find`, `grep`, or others). These filenames will override the list of glob patterns or filenames specified in the configuration file's `spec` list.
161+
It is sometimes necessary&mdash;in the context of continuous integration and otherwise&mdash;to specify multiple sets of specs to run. WebdriverIO's `wdio` command line utility accepts piped-in filenames (from `find`, `grep`, or others).
162+
163+
Piped-in filenames override the list of globs or filenames specified in the configuration's `spec` list.
144164

145165
```sh
146166
grep -r -l --include "*.js" "myText" | wdio wdio.conf.js
@@ -150,6 +170,10 @@ _**Note:** This will_ not _override the `--spec` flag for running a single spec.
150170

151171
## Stop testing after failure
152172

153-
With the `bail` option you can specify when WebdriverIO should stop the test run after test failures. This can be helpful when you have a big test suite and want to avoid long test runs when you already know that your build will break. The option expects a number that specifies after how many spec failures it should stop the whole test run. The default is `0` meaning that it always runs all tests specs it can find.
173+
With the `bail` option, you can tell WebdriverIO to stop testing after any test fails.
174+
175+
This is helpful with large test suites when you already know that your build will break, but you want to avoid the lenghty wait of a full testing run.
176+
177+
The `bail` option expects a number, which specifies how many test failures can occur before WebDriver stop the entire testing run. The default is `0`, meaning that it always runs all tests specs it can find.
154178

155179
Please see [Options Page](Options.md) for additional information on the bail configuration.

0 commit comments

Comments
 (0)