User talk:Rajesh Taneja
Acceptance testing
Introduction
This page describes how we describe Moodle's functionalities and automatically test them.
Behat is a behavioural driven development (BDD) tool written in PHP, it can parse a human-readable list of sentences (called steps) and execute actions in a browser using Selenium or other tools to simulate user interactions.
For technical info: Behat integration
Quick start
This is a quick introduction to run a functional test (acceptance tests) using steps in a development/testing site, please DON'T USE THIS IN A PRODUCTION SITE.
Requirements
Moodle requirements
We put following requirement on behat run, to ensure acceptance site don't change data of existing moodle site.
- 1. Different wwwroot
- A Moodle instance running on a webserver which you can connect to, just like you use for development and manual testing. To set different wwwroot to your 'normal' moodle install, you will need to configure apache to listen on two urls for the same moodle checkout. e.g.
$CFG->wwwroot = 'http://test.moodle.local/'
$CFG->behat_wwwroot = 'http://127.0.0.1/'
- 2. Separate database
- To use different database for acceptance testing set following.
$CFG->behat_prefix = 'behat_'; // Different then $CFG->prefix;
- 3. Separate dataroot
- To use different dataroot for acceptance testing set following.
$CFG->behat_dataroot = '/PATH/FOR/BEHAT_DATAROOT'; // Different then $CFG->dataroot;
Third party requirements
Following are required to execute Behat
- 1. Selenium server running in background
- Download Latest version of selenium-server-standalone-x.xx.x.jar and use following command to run it. (where x.xx.x is the version number)
- java -jar selenium-server-standalone-x.xx.x.jar
- 2. Behat environment initialise
- Behat should be installed from composer and moodel site should be initilaised. Admin tool will attempt to do this.
- php admin/tool/behat/cli/init.php
- If above fails then you can install latest composer and execute following from terminal.
- php composer.phar install
- php admin/tool/behat/cli/init.php
Executing
Run the behat command which "php admin/tool/behat/cli/init.php" tells you to do
vendor/bin/behat --config /PATH/FOR/BEHAT_DATAROOT/behat/behat.yml
Advanced usage
- [Running behat using parallel run]
- [Run options]
- Test filters
- Output formats
- Run behat using different browsers
Troubleshooting
- Selenium server not running :
- Ensure you have selenium server running in another window
- Enter http://localhost:4444/wd/hub in browser and ensure page gets loaded
- Check config.php for wd_host and make sure it's set to proper port
- Not a behat site
- From your browser go to $CFG->behat_wwwroot value and ensure site is accessible.
Contributing
You can contribute the effort to automatically test all of Moodle's functionalities, as described in the guide to contributing automated tests. Here you can find information about how to write new features and how to write new step definitions if your changes requires a base change in the Moodle behat extension you can find here how to do it following the integration workflow: Acceptance_testing/Contributing_to_Moodle_behat_extension.
Browser specific fixes
If you are interested in running behat in other browsers you might be interested on https://docs.moodle.org/dev/Acceptance_testing/Browsers
When running acceptance tests in conjunction with Selenium there is a fix for the navigation bar that gets applied in order to avoid errors arising from a bug in the webdrivers for those browsers.
The issue: When an acceptance test goes to interact with an element on the page it first ensures that the element in the view-port and if not scrolls the browser to get the element into the view-port. The browser scrolls the element only just inside the view-port. It doesn't however allow for any fixed position elements such as the navigation bar. What happens: In some situations these browsers scroll up to reach a button, however not enough as the button ends up behind the navigation bar and cannot be interacted with.
Our solution: We can not change browser driver behaviour so we have integrated a work around. When running acceptance tests we change the position attribute of the navigation bar from fixed to absolute. This is not ideal as it is not how the user experiences the site, however it allows us to run the full acceptance test suite against all browsers so we allowed it. A notice will be displayed when you start an acceptance test run if the browser specific fixes have been applied. See MDL-51881 / MDL-47734 / MDL-45231 for more details.
References
Rajesh Taneja (talk) 12:13, 3 March 2016 (AWST)