2018-04-10 21:19:08 +00:00
# Selenium tests
2021-08-16 06:52:56 +00:00
For more information see https://www.mediawiki.org/wiki/Selenium
2018-04-10 21:19:08 +00:00
## Setup
2021-08-16 06:52:56 +00:00
See https://www.mediawiki.org/wiki/MediaWiki-Docker/MinervaNeue
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
## Run all specs
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
npm run selenium-test
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
## Run specific tests
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
Filter by file name:
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME]
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
Filter by file name and test name:
2018-04-10 21:19:08 +00:00
2020-02-18 16:49:55 +00:00
npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME] --mochaOpts.grep [TEST-NAME]
2019-04-05 21:09:47 +00:00
# Migrating a test from Ruby to Node.js
Currently we are in the midst of porting our Ruby tests to Node.js.
When the tests/browser/features folder is empty, we are done and the whole tests/browser folder can be removed.
This is a slow process (porting a single test can take an entire afternoon).
## Step 1 - move feature file
Move the feature you want to port to Node.js
```
mv tests/browser/features/< name > .feature tests/selenium/features/
```
Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/1/tests/selenium/features/editor_wikitext_saving.feature
## Step 2 - add boilerplate for missing steps
Run the feature in cucumber
```
2019-04-08 21:11:33 +00:00
npm run selenium-test-cucumber -- --spec tests/selenium/features/< name > .feature
2019-04-05 21:09:47 +00:00
```
You will get warnings such as:
```
Step "I go to a page that has languages" is not defined. You can ignore this error by setting cucumberOpts.ignoreUndefinedDefinitions as true.
```
For each missing step define them as one liners inside selenium/features/step_definitions/index.js
Create functions with empty bodies for each step.
2020-02-18 16:49:55 +00:00
Function names should be camel case without space, for example, `I go to a page that has languages` becomes `iGoToAPageThatHasLanguages` . Each function should be imported from a step file inside the features/step_definitions folder.
2019-04-05 21:09:47 +00:00
2020-02-18 16:49:55 +00:00
Rerun the test. If done correctly this should now pass.
2019-04-05 21:09:47 +00:00
Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/1..2
## Step 3 - copy across Ruby function bodies
Copy across the body of the Ruby equivalent inside each function body in tests/browser/features/step_definitions as comments.
Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/2..3
## Step 4 - rewrite Ruby to Node.js
Sadly there is no shortcut here. Reuse as much as you can. Work with the knowledge that the parts you are adding will aid the next browser test migration.
The docs are your friend: http://v4.webdriver.io/api/utility/waitForVisible.html
Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/2..4
## Step 5 - Make it work without Cucumber
Now the tests should be passing when run the browser tests using wdio.conf.cucumber.js or `npm run selenium-test-cucumber`
The final step involves making these run with
`npm run selenium-test`
This is relatively straightforward and mechanical.
1) Copy the feature file to the specs folder
```
cp tests/selenium/features/editor_wikitext_saving.feature tests/selenium/specs/editor_wikitext_saving.js
```
2) Convert indents to tabs
3) Add `//` before any tags
4) Replace `Scenario: <name>` with `it( '<name>', () => {`
5) Add closing braces for all scenarios: ` } );`
6) Replace `Feature: <feature>` with `describe('<feature>)', () => {` and add closing brace.
7) Replace `Background:` with `beforeEach( () => {` and add closing brace.
2020-02-18 16:49:55 +00:00
8) Find and replace `Given ` , `When ` , `And ` , `Then ` with empty strings.
2019-04-05 21:09:47 +00:00
9) At top of file copy and paste imports from `selenium/features/step_definitions/index.js` to top of your new file and rewrite their paths.
10) Relying on autocomplete (VisualStudio Code works great) replace all the lines with the imports
11) Drop unused imports from the file.