|
2 | 2 | sidebar_position: 3 |
3 | 3 | --- |
4 | 4 |
|
5 | | -# Running Tests |
| 5 | +# Running and Debugging Tests |
6 | 6 |
|
7 | | -Use the `npx testplane` command to run all tests in your project. |
| 7 | +## Running tests |
8 | 8 |
|
9 | | -## Running a Specific File {#running_a_specific_file} |
| 9 | +To run tests, use the following command: |
10 | 10 |
|
11 | | -If you want to run a whole group of tests located in a specific file, specify the path to this file as an input parameter for testplane: |
| 11 | +```bash |
| 12 | +npx testplane |
| 13 | +``` |
| 14 | + |
| 15 | +You can also run tests in `gui` mode. To do this, execute the command: |
| 16 | + |
| 17 | +```bash |
| 18 | +npx testplane gui |
| 19 | +``` |
| 20 | + |
| 21 | +### Running a specific test |
| 22 | + |
| 23 | +Consider the following set of tests: |
| 24 | + |
| 25 | +```javascript |
| 26 | +const assert = require("assert"); |
| 27 | + |
| 28 | +describe("tests", () => { |
| 29 | + it("Checking the display of the main page", async ({ browser }) => { |
| 30 | + await browser.url("https://testplane.io/ru/"); |
| 31 | + const title = await browser.getTitle(); |
| 32 | + assert.ok(title.includes("Testplane")); |
| 33 | + }); |
| 34 | + |
| 35 | + it("Checking for the presence of a search field", async ({ browser }) => { |
| 36 | + await browser.url("https://testplane.io/ru/"); |
| 37 | + const searchButton = await browser.$("button.DocSearch"); |
| 38 | + const isExisting = await searchButton.isExisting(); |
| 39 | + assert.strictEqual(isExisting, true); |
| 40 | + }); |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +If you want to run just one of them, use `--grep` option: |
12 | 45 |
|
13 | 46 | ```bash |
14 | | -npx testplane src/features/Reviews/Reviews.test/MyReview/MyReview.a11y@touch-phone.testplane.js |
| 47 | +testplane --grep "Checking for the presence of a search field" |
15 | 48 | ``` |
16 | 49 |
|
17 | | -## The `--grep` Option {#the_grep_option} |
| 50 | +You can pass the whole test name, some part of it or regex pattern to run only those tests whose names will match. |
| 51 | + |
| 52 | +### Running tests in specific browsers |
| 53 | + |
| 54 | +By default, tests run in the browsers specified in the `testplane.config.ts` file. |
18 | 55 |
|
19 | | -If you want to run a specific test, use the `--grep` option by providing the full name of the test as its value: |
| 56 | +```bash |
| 57 | +browsers: ["chrome", "firefox"]; |
| 58 | +``` |
| 59 | + |
| 60 | +When you run the `npx testplane` command, tests will run in Google Chrome and Mozilla Firefox. |
20 | 61 |
|
21 | 62 | ```bash |
22 | | -npx testplane --grep "Accessibility Leaving a review" |
| 63 | +# Run in all browsers (default) |
| 64 | +testplane |
23 | 65 | ``` |
24 | 66 |
|
25 | | -## The `.only` Directive {#the_only_directive} |
| 67 | +To run tests in a specific browser, use the command: |
26 | 68 |
|
27 | | -You can also use the `.only` directive for a suite of tests (`describe`) or a specific test (`it`), similar to what is implemented in `mocha` (see the [exclusive tests](https://mochajs.org/#exclusive-tests) section): |
| 69 | +```bash |
| 70 | +# Run only in Chrome |
| 71 | +testplane --browser chrome |
| 72 | +``` |
28 | 73 |
|
29 | | -For example: |
| 74 | +You can also specify a specific browser for use within the test body. |
30 | 75 |
|
31 | 76 | ```javascript |
32 | | -describe.only("Accessibility", function () { |
33 | | - // Test suite... |
| 77 | +// tests/browser-specific.test.js |
| 78 | +describe("Browser specific tests", () => { |
| 79 | + it("should work in all browsers", async ({ browser }) => { |
| 80 | + await browser.url("https://example.com"); |
| 81 | + }); |
| 82 | + |
| 83 | + // Skip the test in Safari |
| 84 | + testplane.skip.in("safari", "Feature not supported in Safari"); |
| 85 | + it("should work only in Chrome and Firefox", async ({ browser }) => { |
| 86 | + await browser.url("https://example.com"); |
| 87 | + // ... test body |
| 88 | + }); |
| 89 | + |
| 90 | + // Run only in Chrome |
| 91 | + testplane.only.in("chrome"); |
| 92 | + it("should work only in Chrome", async ({ browser }) => { |
| 93 | + await browser.url("https://example.com"); |
| 94 | + // ... test body |
| 95 | + }); |
34 | 96 | }); |
35 | 97 | ``` |
36 | 98 |
|
37 | | -or |
| 99 | +### Running a test from a specific file |
| 100 | + |
| 101 | +To run tests from a specific file, execute the command: |
| 102 | + |
| 103 | +```bash |
| 104 | +# Running a specific file |
| 105 | +testplane ../testplane-tests/example.testplane.ts |
| 106 | +``` |
| 107 | + |
| 108 | +Where `../testplane-tests/example.testplane.ts` is the path to the test file. |
| 109 | + |
| 110 | +### User interface mode |
| 111 | + |
| 112 | +In Testplane, you can work with tests in UI format using Testplane UI. |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +You can read about the installation and setup processes for Testplane UI in the [UI.](..//html-reporter//overview.mdx) section. |
| 117 | + |
| 118 | +## Debugging |
| 119 | + |
| 120 | +It’s very easy to track the test execution process if you run tests in `gui` mode. In this mode, the HTML reporter will show which tests were executed successfully, which ones have errors, and what kind of errors they are. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +### Browser.debug() |
| 125 | + |
| 126 | +Testplane has a built‑in debugging tool — `browser.debug`. |
38 | 127 |
|
39 | 128 | ```javascript |
40 | | -it.only("Leaving a review", async function () { |
41 | | - // Test code... |
| 129 | +it("debugging with a pause", async ({ browser }) => { |
| 130 | + // Open the page being tested |
| 131 | + await browser.url("/page"); |
| 132 | + |
| 133 | + // browser.debug() stops test execution |
| 134 | + // and opens an interactive console (REPL — Read-Eval-Print Loop) |
| 135 | + await browser.debug(); |
| 136 | + |
| 137 | + // After calling debug(), the test pauses |
| 138 | + // In the console, you can enter WebdriverIO commands in real time: |
| 139 | + |
| 140 | + // Examples of commands you can enter in REPL: |
| 141 | + // > await browser.$('.button').click() - click the button |
| 142 | + // > await browser.getTitle() - get the page title |
| 143 | + // > await browser.$$('.items') - find all elements |
| 144 | + // > .exit - exit debug mode |
| 145 | + |
| 146 | + // This code will run only after exiting debug() |
| 147 | + await browser.$(".button").click(); |
42 | 148 | }); |
43 | 149 | ``` |
44 | 150 |
|
45 | | -## Running a Test N Times {#running_tests_multiple_times} |
| 151 | +### Debugging via Testplane UI |
46 | 152 |
|
47 | | -You might want to run the same test multiple times, for example, to check test stability. Use the [@testplane/test-repeater][testplane-test-repeater] plugin to run tests a specified number of times. |
| 153 | +The most convenient way to debug tests is using the UI mode, where you can observe test execution in real time. |
48 | 154 |
|
49 | | -After installing and enabling the plugin, you can run the test multiple times like this: |
| 155 | + |
50 | 156 |
|
51 | | -```bash |
52 | | -npx testplane --test-repeater-repeat 5 --grep 'Test name' |
53 | | -``` |
| 157 | +You can find unstable, slow tests, or other issues using the «sorting» and «grouping» options. |
54 | 158 |
|
55 | | -[testplane-test-repeater]: ../../plugins/testplane-test-repeater |
| 159 | + |
0 commit comments