Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 178a51e

Browse files
committed
feat: add Cypress.grep method
1 parent 44a6c41 commit 178a51e

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,17 @@ it('works', { tags: '@smoke @fast' }, () => ...)
173173

174174
## DevTools console
175175

176-
Watch [this video](https://youtu.be/Sp1NfcLPpwg) to see how to run only one or some tagged tests without editing the spec source files!
176+
You can set the grep string from the DevTools Console. This plugin adds method `Cypress.grep` to set the grep string and restart the tests
177177

178-
- from the browser, open the DevTools console
179-
- if you want to run tests with specific tag or tag expression, enter the command to set the grep value like `Cypress.env('grep', '@tag1')` for example and then click the reload button or press "r" key. The tests should re-run and the grep value should be applied.
180-
181-
![Run-time grep from DevTools console](./images/grep-tag.gif)
182-
183-
- if you want to run just a test with a title, copy the test title and use an array with just the test title `Cypress.env('grep', ['test title here'])` and re-run the test
184-
185-
![Run a single test by title from the DevTools console](./images/test-title-grep.gif)
178+
```js
179+
// use grep "@tag1"
180+
Cypress.grep('@tag1')
181+
// run the test with substring "hello world"
182+
// without parsing separate words as tags
183+
Cypress.grep(['hello world'])
184+
```
186185

187-
- to remove the grep string, enter `Cypress.env('grep', null)`
186+
- to remove the grep string, enter `Cypress.grep()`
188187

189188
## Debugging
190189

images/debug.png

-227 KB
Binary file not shown.

images/grep-tag.gif

-202 KB
Binary file not shown.

images/test-title-grep.gif

-339 KB
Binary file not shown.

src/support.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,15 @@ function cypressGrep() {
9292
describe.skip = _describe.skip
9393
}
9494

95+
if (!Cypress.grep) {
96+
// expose a utility method to set the grep and run the tests
97+
Cypress.grep = function grep(s) {
98+
Cypress.env('grep', s)
99+
debug('set new grep to "%s", restarting', s)
100+
setTimeout(() => {
101+
window.top.document.querySelector('.reporter .restart').click()
102+
}, 0)
103+
}
104+
}
105+
95106
module.exports = cypressGrep

0 commit comments

Comments
 (0)