Selenium/How-to/Debug with browser.debug()
Environments
[edit]This tip works if you're targeting:
- a local MediaWiki
- a remote wiki
Make the browser visible
[edit]To speed up the debugging, you will probably want to run make the browser visible. See Selenium/How-to/Make the browser visible.
Environment variables
[edit]By default, Mocha (testing framework) will abort the test suite if it takes more than 60 seconds. (If you need more information about Mocha testing framework, see Selenium/Explanation/Stack.) That is usually plenty when you're just running tests, but it's usually not enough when you're debugging. To extend the timeout to 60 minutes, set DEBUG
environment variable.
Either run this manually from the terminal or, to make it easier for next time, set them from shell configuration file (~/.bash_profile
, ~/.zshrc
...) which means the variables are always available from any terminal session:
export DEBUG=true
If you prefer, you can create an .env
file instead (in MediaWiki Core folder), with this contents.
DEBUG=true
browser.debug()
[edit]Put await browser.debug();
at a place you want to debug.
Run Selenium tests
[edit]To speed up the debugging, you will probably want to run only one test. See Selenium/How-to/Run a subset of a test suite. Test suite will stop when it reaches browser.debug()
.
npm run selenium-test
...
The execution has stopped!
You can now go into the browser or use the command line as REPL
(To exit, press ^C again or type .exit)
...
Use the browser developer tools and WebdriverIO REPL interface to debug.
Examples
[edit]For example, you can ask for browser URL.
[0-0] âș browser.getUrl()
'http://localhost:8080/w/index.php?title=Special:UserLogin'
Or, if an element with ID pt-login
is displayed.
[0-0] âș $('#pt-login-1').isDisplayed()
false
[0-0] âș $('#pt-login-2').isDisplayed()
true