| 1 | # Selenium tests |
| 2 | |
| 3 | For more information see https://www.mediawiki.org/wiki/Selenium |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | See https://www.mediawiki.org/wiki/MediaWiki-Docker/MinervaNeue |
| 8 | |
| 9 | ## Run all specs |
| 10 | |
| 11 | npm run selenium-test |
| 12 | |
| 13 | ## Run specific tests |
| 14 | |
| 15 | Filter by file name: |
| 16 | |
| 17 | npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME] |
| 18 | |
| 19 | Filter by file name and test name: |
| 20 | |
| 21 | npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME] --mochaOpts.grep [TEST-NAME] |
| 22 | |
| 23 | # Migrating a test from Ruby to Node.js |
| 24 | |
| 25 | Currently we are in the midst of porting our Ruby tests to Node.js. |
| 26 | When the tests/browser/features folder is empty, we are done and the whole tests/browser folder can be removed. |
| 27 | |
| 28 | This is a slow process (porting a single test can take an entire afternoon). |
| 29 | |
| 30 | ## Step 1 - move feature file |
| 31 | Move the feature you want to port to Node.js |
| 32 | ``` |
| 33 | mv tests/browser/features/<name>.feature tests/selenium/features/ |
| 34 | ``` |
| 35 | Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/1/tests/selenium/features/editor_wikitext_saving.feature |
| 36 | |
| 37 | ## Step 2 - add boilerplate for missing steps |
| 38 | Run the feature in cucumber |
| 39 | ``` |
| 40 | npm run selenium-test-cucumber -- --spec tests/selenium/features/<name>.feature |
| 41 | ``` |
| 42 | |
| 43 | You will get warnings such as: |
| 44 | ``` |
| 45 | Step "I go to a page that has languages" is not defined. You can ignore this error by setting cucumberOpts.ignoreUndefinedDefinitions as true. |
| 46 | ``` |
| 47 | |
| 48 | For each missing step define them as one liners inside selenium/features/step_definitions/index.js |
| 49 | |
| 50 | Create functions with empty bodies for each step. |
| 51 | |
| 52 | 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. |
| 53 | |
| 54 | Rerun the test. If done correctly this should now pass. |
| 55 | |
| 56 | Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/1..2 |
| 57 | |
| 58 | ## Step 3 - copy across Ruby function bodies |
| 59 | |
| 60 | Copy across the body of the Ruby equivalent inside each function body in tests/browser/features/step_definitions as comments. |
| 61 | |
| 62 | Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/2..3 |
| 63 | |
| 64 | ## Step 4 - rewrite Ruby to Node.js |
| 65 | |
| 66 | 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. |
| 67 | |
| 68 | The docs are your friend: http://v4.webdriver.io/api/utility/waitForVisible.html |
| 69 | |
| 70 | Example: https://gerrit.wikimedia.org/r/#/c/mediawiki/skins/MinervaNeue/+/501792/2..4 |
| 71 | |
| 72 | ## Step 5 - Make it work without Cucumber |
| 73 | |
| 74 | Now the tests should be passing when run the browser tests using wdio.conf.cucumber.js or `npm run selenium-test-cucumber` |
| 75 | |
| 76 | The final step involves making these run with |
| 77 | `npm run selenium-test` |
| 78 | |
| 79 | This is relatively straightforward and mechanical. |
| 80 | |
| 81 | 1) Copy the feature file to the specs folder |
| 82 | ``` |
| 83 | cp tests/selenium/features/editor_wikitext_saving.feature tests/selenium/specs/editor_wikitext_saving.js |
| 84 | ``` |
| 85 | 2) Convert indents to tabs |
| 86 | 3) Add `//` before any tags |
| 87 | 4) Replace `Scenario: <name>` with `it( '<name>', () => {` |
| 88 | 5) Add closing braces for all scenarios: ` } );` |
| 89 | 6) Replace `Feature: <feature>` with `describe('<feature>)', () => {` and add closing brace. |
| 90 | 7) Replace `Background:` with `beforeEach( () => {` and add closing brace. |
| 91 | 8) Find and replace `Given `, `When `, `And `, `Then ` with empty strings. |
| 92 | 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. |
| 93 | 10) Relying on autocomplete (VisualStudio Code works great) replace all the lines with the imports |
| 94 | 11) Drop unused imports from the file. |