You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Set up browser tests using the Mediawiki docker set up

From Wikitech-static
Revision as of 09:34, 5 November 2020 by imported>Noa wmde
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Before your start

- If you wish to continue using the mw-docker-dev setup in parallel to this one, start by backing up the LocalSettings.php file in your Mediawilki repo (by renaming or copying elsewhere).
- Switching between the two set ups is possible and requires switching to the corresponding LocalSettings.php for each set up.
- Note: the two set ups need different MW_DOCKER_PORT ports in order to be run without stepping on each other’s toes. (see .env contents)

Files required in your Mediawiki home directory

1) browsertest.sh

#!/bin/sh
set -eu
# create user needed for certain edit actions (only has effect on the first go)

docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.browsertest.yml \
run --rm mediawiki php //var/www/html/w/maintenance/createAndPromote.php --bureaucrat --sysop --bot lil-seleni test123456!
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.browsertest.yml \
run --rm seleniumtests npm i
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.browsertest.yml \
run --rm seleniumtests node_modules/.bin/wdio tests/selenium/wdio.conf.js --waitforTimeout=60000 --mochaOpts.timeout=60000 --hostname selenium \
--spec /app/extensions/Wikibase/repo/tests/selenium/specs/blocked.js
#--mochaOpts.grep 'can create lexeme with language item not bearing language code'

NOTE: if you have an older version of Mediawiki, the path might not include “/w” part. Look into the ‘working_dir’ key of your docker-compose.yml in your mediawiki home directory.

2) Docker-compose.browsertest.yml

version: '3.7'
services:
  seleniumtests:
      image: "docker-registry.wikimedia.org/nodejs10-devel"
      environment:
          - "MW_SERVER=http://mediawiki:8080"
          - "MW_SCRIPT_PATH=/"
          - "MEDIAWIKI_USER=lil-seleni"
          - "MEDIAWIKI_PASSWORD=test123456!"
          - "MEDIAWIKI_SECRET_KEY=a5dca55190e1c3927e098c317dd74e85c7eced36f959275114773b188fbabdbc"
          - NODE_DEBUG
      command: echo 'invoke me through ./browsertest'
      working_dir: /app
      volumes:
          - "${DOCKER_MW_PATH}:/app"
          - "${SELENIUM_LOG_PATH}:/app/tests/selenium/log"
      depends_on:
          - seleniu
  selenium:
      image: selenium/standalone-chrome
      shm_size: '2gb'
      depends_on:
          - mediawiki


3) Your .env file should look like this:

 MW_DOCKER_UID=1000                                                                                                                                                                                     
 MW_DOCKER_GID=1000
 MW_DOCKER_PORT=8081        
 MW_SCRIPT_PATH=/w          
 DOCKER_MW_PATH=./          
 SELENIUM_LOG_PATH=./log    
 MW_SERVER=http://localhost:8081
 MEDIAWIKI_USER=Admin       
 MEDIAWIKI_PASSWORD=dockerpass
 XDEBUG_CONFIG=

Then, follow the setup instructions here. Note: for this specific test set up there is no need to use the Fresh container

Run the tests

Tests are run by executing ./browsertest.sh in your Mediawiki home directory. You can tell it which test to run inside the file (the path after “--spec”).

Note: Your newly created LocalSettings.php should include:

  • $wgServer = WebRequest::detectServer();
  • header( 'content-encoding: gzip' ); (to avoid gzip compression issues)
  • Load any extension you want to test. E.g. Wikibase repo:
    • wfLoadExtension( 'WikibaseRepository', "$IP/extensions/Wikibase/extension-repo.json" );
    • require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";