UNPKG

7.57 kBMarkdownView Raw
1# 📸+👦🏼 [Creevey](https://harrypotter.fandom.com/wiki/Colin_Creevey)
2
3Cross-browser screenshot testing tool for [Storybook](https://storybook.js.org/) with fancy UI Runner.
4
5[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
6
7![Creevey Demo](https://user-images.githubusercontent.com/6397708/100863723-cd6b8500-34b6-11eb-94e1-849590bc8066.gif)
8
9## Core features
10
11- 📚 Integrates with Storybook
12- 📜 Uses stories as tests
13- ✏️ Allows write interaction tests
14- ✨ Has fancy UI Runner
15- 🐳 Supports Docker
16- ⚔️ Cross-browsers testing
17- 🔥 Tests hot-reloading
18- ⚙️ CI Ready
19
20It named after [Colin Creevey](https://harrypotter.fandom.com/wiki/Colin_Creevey) character from the Harry Potter universe.
21
22## Contents
23
24- [Pre-requisites](#pre-requisites)
25- [How to Start](#how-to-start)
26- [Comparison with other tools](#comparison-with-other-tools)
27- [Config/Options](docs/config.md)
28- Advanced usage
29 - [Write tests](docs/tests.md)
30 - [Use your Selenium Grid (BrowserStack/SauceLabs/etc)](docs/grid.md)
31- [Future plans](#future-plans)
32- [Known issues](#known-issues)
33- [Used by](#used-by)
34
35## Pre-requisites
36
37- Make sure you have installed [Docker](https://www.docker.com/products/docker-desktop). But if you going to use your own separate Selenium Grid, you don't need `Docker`.
38
39## How to start
40
41- Install `creevey` package
42
43```bash
44yarn add -D creevey
45```
46
47- Add addon `creevey` into your storybook config
48
49```js
50// .storybook/main.js
51module.exports = {
52 stories: [
53 /* ... */
54 ],
55 addons: [
56 /* ... */
57 'creevey',
58 ],
59};
60```
61
62- Start storybook and then start Creevey UI Runner in separate terminal. (To start tests from CLI, run Creevey without `--ui` flag)
63
64```bash
65yarn start-storybook -p 6006
66yarn creevey --ui
67```
68
69And that's it.
70
71**NOTE:** In first run you may noticed, that all your tests are failing, it because you don't have source screenshot images yet. If you think, that all images are acceptable, you may approve them all in one command `yarn creevey --update`.
72
73**NOTE:** Creevey captures screenshot of the `#root` element and sometimes you need to capture a whole browser viewport. To achieve this you could define `captureElement` Creevey parameter for story or kind. Or you may pass any different css selector.
74
75```tsx
76// stories/MyModal.stories.tsx
77
78// NOTE: Define parameter for all stories
79export default {
80 title: 'MyModal',
81 parameters: { creevey: { captureElement: null } },
82};
83
84// NOTE: Or define it for specific one
85
86export const MyModalStory = () => <MyModal />;
87MyModalStory.parameters = { creevey: { captureElement: null } };
88```
89
90## Comparison with other tools
91
92| Features\Tools | Creevey | Loki | Storyshots | Hermione | BackstopJS | Percy/Happo | Chromatic |
93| --------------------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
94| Easy-to-Setup | :heavy_check_mark: | :heavy_check_mark: | :warning: | :no_entry: | :no_entry: | :heavy_check_mark: | :heavy_check_mark: |
95| Storybook Support | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :no_entry: | :no_entry: | :heavy_check_mark: | :heavy_check_mark: |
96| Run tests from Storybook UI | :heavy_check_mark: | :no_entry: | :no_entry: | :no_entry: | :no_entry: | :no_entry: | :no_entry: |
97| Cross-browser | :heavy_check_mark: | :warning: | :no_entry: | :heavy_check_mark: | :no_entry: | :heavy_check_mark: | :heavy_check_mark: |
98| Test Interaction | :heavy_check_mark: | :no_entry: | :warning: | :heavy_check_mark: | :heavy_check_mark: | :no_entry: | :no_entry: |
99| UI Test Runner | :heavy_check_mark: | :no_entry: | :no_entry: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
100| Built-in Docker | :heavy_check_mark: | :heavy_check_mark: | :no_entry: | :no_entry: | :heavy_check_mark: | :warning: | :warning: |
101| Tests hot-reload | :heavy_check_mark: | :no_entry: | :no_entry: | :no_entry: | :no_entry: | :no_entry: | :no_entry: |
102| OSS/SaaS | OSS | OSS | OSS | OSS | OSS | SaaS | SaaS |
103
104## Future plans
105
106- Allow use different webdrivers not only `selenium`, but also `puppeteer` or `playwright`.
107- Add ability to ignore elements.
108- Allow to define different viewport sizes for specific stories or capture story with different args.
109- And more, check [TODO](TODO.md) for more details. Also feel free to ask about feature that you want
110
111## Known issues
112
113### Creevey is trying to build storybook but fail or tests don't work
114
115This might happens because Creevey patches storybook webpack config and build nodejs bundle with stories meta information. And in some cases Creevey couldn't properly remove all unnecessary code cause of side-effects in stories files or you create stories dynamically. Try to rewrite such places. If it still doesn't help, [send to me](mailto:creevey@kich.dev) bundle that Creevey created (it located in `node_modules/creevey/.cache/creevey/storybook/main.js`)
116
117A little bit later I'll add possibility to run tests without building that bundle, so it fixes this issue.
118
119### Docker-in-Docker
120
121Currently it's not possible to run Creevey in this configuration. I'll fix this in later versions.
122If you use `CircleCI` or another CI that use docker to run jobs. Try to configure to use virtual machine executor
123
124**Update** I added support to use local browsers. So it should be possible run Creevey inside docker.
125The only issue, that you need to find or build docker image with node, browser and selenium-webdriver. I'll add special images for Creevey later.
126
127### Chrome webdriver + 1px border with border-radius.
128
129This cause to flaky screenshots. Possible solutions:
130
131- Increase threshold ratio in Creevey config `diffOptions: { threshold: 0.1 }`
132- Replace border to box-shadow `border: 1px solid red` -> `box-shadow: 0 0 0 1px red`
133- Set max retries to more than 5
134
135### You can't directly import `selenium-webdriver` package in story file
136
137Because tests defined in story parameters and `selenium-webdriver` depends on nodejs builtin packages. Storybook may fail to build browser bundle. To avoid import use these workarounds:
138
139- `.findElement(By.css('#root'))` -> `.findElement({ css: '#root' })`
140- `.sendKeys(Keys.ENTER)` -> `.sendKeys(this.keys.ENTER)`
141
142## Used by
143
144| [![Whisk](https://raw.githubusercontent.com/wKich/creevey/master/.github/images/whisk.svg)](https://whisk.com/) | [![SKB Kontur](https://kontur.ru/Files/userfiles/image/brandbook/logo-skb-kontur-eng.png)](https://kontur.ru/) | [![ABBYY](https://raw.githubusercontent.com/wKich/creevey/master/.github/images/abbyy.svg)](https://www.abbyy.com/) |
145| --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |