mediawiki-skins-MinervaNeue/tests/selenium
Umherirrender 791cb1081a selenium: Ensure .waitForDisplayed() before .click()
Avoid time outs
Error in "Opening and closing the reference drawer.Opening a nested
reference"
Error: waitUntil condition timed out after 5000ms
    at Browser.<anonymous>
(/workspace/src/skins/MinervaNeue/node_modules/@wdio/utils/build/shim.js:270:24)
    at iShouldSeeDrawerWithText
(/workspace/src/skins/MinervaNeue/tests/selenium/features/step_definitions/reference_steps.js:25:10)
    at Context.<anonymous>
(/workspace/src/skins/MinervaNeue/tests/selenium/specs/references.js:44:3)
FAILED in chrome - /tests/selenium/specs/references.js

Change-Id: Ia5d493fba4995c1122721b76ae98d6ba60399238
2022-02-03 21:18:02 +01:00
..
config build: Update eslint-config-wikimedia to 0.16.0 2020-06-04 08:39:32 -07:00
features selenium: Ensure .waitForDisplayed() before .click() 2022-02-03 21:18:02 +01:00
pageobjects Minerva uses core page title handling 2021-12-20 19:39:42 +00:00
specs [Selenium] Skip failing test 2021-09-16 14:57:03 +00:00
.eslintrc.json build: Update eslint-config-wikimedia to 0.16.0 2020-06-04 08:39:32 -07:00
README.md selenium: Update README.md file 2021-08-16 12:23:20 +05:30
wdio.conf.cucumber.js build: Update eslint-config-wikimedia to 0.16.0 2020-06-04 08:39:32 -07:00
wdio.conf.js selenium: run tests concurrently 2022-01-05 16:44:12 +00:00

Selenium tests

For more information see https://www.mediawiki.org/wiki/Selenium

Setup

See https://www.mediawiki.org/wiki/MediaWiki-Docker/MinervaNeue

Run all specs

npm run selenium-test

Run specific tests

Filter by file name:

npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME]

Filter by file name and test name:

npm run selenium-test -- --spec tests/selenium/specs/[FILE-NAME] --mochaOpts.grep [TEST-NAME]

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

npm run selenium-test-cucumber -- --spec tests/selenium/features/<name>.feature

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.

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.

Rerun the test. If done correctly this should now pass.

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
  1. Convert indents to tabs
  2. Add // before any tags
  3. Replace Scenario: <name> with it( '<name>', () => {
  4. Add closing braces for all scenarios: } );
  5. Replace Feature: <feature> with describe('<feature>)', () => { and add closing brace.
  6. Replace Background: with beforeEach( () => { and add closing brace.
  7. Find and replace Given , When , And , Then with empty strings.
  8. 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.
  9. Relying on autocomplete (VisualStudio Code works great) replace all the lines with the imports
  10. Drop unused imports from the file.