Skip to content

Commit

Permalink
Merge pull request #270 from ilyatregubov/behatpage
Browse files Browse the repository at this point in the history
[docs] migrate Behat page
  • Loading branch information
sarjona authored Jul 8, 2022
2 parents 25440c5 + e723a65 commit e9300cb
Show file tree
Hide file tree
Showing 17 changed files with 2,529 additions and 16 deletions.
15 changes: 15 additions & 0 deletions data/migratedPages.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
AMOS_manual:
- filePath: "/general/development/process/translation/amos.md"
slug: "/general/development/process/translation/amos"
Acceptance_testing/Browsers:
- filePath: "/general/development/tools/behat/browsers/index.md"
slug: "/general/development/tools/behat/browsers/"
Acceptance_testing/Browsers/Working_combinations_of_OS+Browser+selenium:
- filePath: "/general/development/tools/behat/browsers/supportedbrowsers.md"
slug: "/general/development/tools/behat/browsers/supportedbrowsers"
Acceptance_testing_for_the_Moodle_App:
- filePath: "/docs/moodleapp/development/testing/acceptance-testing.md"
slug: "/docs/moodleapp/development/testing/acceptance-testing"
Expand Down Expand Up @@ -34,6 +40,9 @@ Automated_Manipulation_of_Strings_2.0:
Automated_code_review:
- filePath: "/general/development/tools/cibot.md"
slug: "/general/development/tools/cibot"
Behat_integration:
- filePath: "/general/development/tools/behat/index.md"
slug: "/general/development/tools/behat/"
Blocks:
- filePath: "/docs/apis/plugintypes/blocks/index.md"
slug: "/docs/apis/plugintypes/blocks"
Expand Down Expand Up @@ -1455,6 +1464,9 @@ Roadmap:
Roles:
- filePath: "/docs/apis/subsystems/roles.md"
slug: "/docs/apis/subsystems/roles"
Running_acceptance_test:
- filePath: "/general/development/tools/behat/running.md"
slug: "/general/development/tools/behat/running"
SQL_coding_style:
- filePath: "/general/development/policies/codingstyle/sql.md"
slug: "/general/development/policies/codingstyle/sql"
Expand Down Expand Up @@ -1587,6 +1599,9 @@ Upgrade_notes:
Using_the_Moodle_App_in_a_browser:
- filePath: "/docs/moodleapp/development/setup/app-in-browser.md"
slug: "/docs/moodleapp/development/setup/app-in-browser"
Writing_acceptance_tests:
- filePath: "/general/development/tools/behat/writing.md"
slug: "/general/development/tools/behat/writing"
jQuery:
- filePath: "/docs/guides/javascript/jquery/index.md"
slug: "/docs/guides/javascript/jquery/"
Expand Down
2 changes: 1 addition & 1 deletion docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The [Time API](./apis/subsystems/time/index.md) takes care of translating and di

### Testing API (test)

The testing API contains the Unit test API ([PHPUnit](https://docs.moodle.org/dev/PHPUnit)) and Acceptance test API ([Acceptance testing](https://docs.moodle.org/dev/Acceptance_testing)). Ideally all new code should have unit tests written FIRST.
The testing API contains the Unit test API ([PHPUnit](/general/development/tools/phpunit)) and Acceptance test API ([Acceptance testing](/general/development/tools/behat)). Ideally all new code should have unit tests written FIRST.

### User-related APIs (user)

Expand Down
2 changes: 1 addition & 1 deletion docs/apis/subsystems/check/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags:
- API
---

A _Check_ is a runtime test to make sure that something is working well. You can think of Checks as similar and complimentary to the [PHPUnit](https://docs.moodle.org/dev/PHPUnit) and [Acceptance testing](https://docs.moodle.org/dev/Acceptance_testing) but the next layer around them, and performed at run time rather than development, or build time.
A _Check_ is a runtime test to make sure that something is working well. You can think of Checks as similar and complimentary to the [PHPUnit](/general/development/tools/phpunit) and [Acceptance testing](/general/development/tools/behat) but the next layer around them, and performed at run time rather than development, or build time.

Like other forms of testing the tests themselves should be easy to read, to reason about, and to confirm as valid.

Expand Down
6 changes: 3 additions & 3 deletions docs/moodleapp/development/testing/acceptance-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags:
- Moodle App
---

In order to run tests that carry out automated functionality testing for the Moodle App, you can write [Acceptance tests](https://docs.moodle.org/dev/Acceptance_testing). This can be useful if you want to test plugins that are compatible with the app, or you're contributing to the app core. Behat tests for the app work the same way as tests for Moodle core, but they are not run as part of a normal Behat execution and there are some differences that we'll go through in this page.
In order to run tests that carry out automated functionality testing for the Moodle App, you can write [Acceptance tests](/general/development/tools/behat). This can be useful if you want to test plugins that are compatible with the app, or you're contributing to the app core. Behat tests for the app work the same way as tests for Moodle core, but they are not run as part of a normal Behat execution and there are some differences that we'll go through in this page.

A key point is that these tests are run using the Moodle Behat infrastructure, and don't depend only on the app codebase. Therefore, you will need a Moodle development setup as described in [Setting up development environment](/general/development/gettingstarted).

Expand Down Expand Up @@ -52,7 +52,7 @@ $CFG->behat_ionic_wwwroot = 'http://localhost:8100';

The url you use here must be reachable by your Moodle site, and the application needs to be served at this url when running tests and also when you initialise the Behat environment.

The Moodle App [only works in Chromium-based browsers](../setup/app-in-browser), so mobile tests will be ignored if you are using any other browser. You can learn how to configure the browser used in your tests in the [Running acceptance test](https://docs.moodle.org/dev/Running_acceptance_test) page.
The Moodle App [only works in Chromium-based browsers](../setup/app-in-browser), so mobile tests will be ignored if you are using any other browser. You can learn how to configure the browser used in your tests in the [Running acceptance test](/general/development/tools/behat/running) page.

If everything is configured properly, you should see "Configured app tests for version X.X.X" after running `admin/tool/behat/cli/init.php`.

Expand All @@ -64,7 +64,7 @@ It is OK to combine mobile and web tests in the same run.

## Writing tests

This page assumes you already know all about [Writing acceptance tests](https://docs.moodle.org/dev/Writing_acceptance_tests) in general.
This page assumes you already know all about [Writing acceptance tests](/general/development/tools/behat/writing) in general.

### Test structure

Expand Down
2 changes: 1 addition & 1 deletion general/development/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ PHPUnit covers mostly the internal implementation of functions and classes, the

:::info

For more about this, see [Acceptance testing](https://docs.moodle.org/dev/Acceptance_testing).
For more about this, see [Acceptance testing](/general/development/tools/behat).

:::

Expand Down
2 changes: 1 addition & 1 deletion general/development/policies/codingstyle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ This tag is valid and can be used optionally to indicate the method or function

There are some tags that are only allowed within some contexts and not globally. More precisely:

- `@Given`, `@When`, `@Then`, within the [behat steps definitions](https://docs.moodle.org/dev/Acceptance_testing#Adding_steps_definitions).
- `@Given`, `@When`, `@Then`, within the [behat steps definitions](/general/development/tools/behat/writing#writing-new-acceptance-test-step-definitions).
- `@covers`, `@coversDefaultClass`, `@coversNothing`, `@uses` to better control coverage within [unit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests#Generators).
- `@dataProvider` and `@testWith`, to provide example data and expectations, within [unit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests#Generators).
- `@depends`, to express dependencies between tests, where each producer returned data in passed to consumers. See [`@depends` examples](https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#writing-tests-for-phpunit-examples-stacktest2-php) for more information.
Expand Down
4 changes: 2 additions & 2 deletions general/development/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ The process of [new feature development](#new-feature-development) is described

### Testing

During development, as new code is integrated, automated testing conducted at the [code](https://docs.moodle.org/dev/PHPUnit) and [interface](https://docs.moodle.org/dev/Acceptance_testing) levels, to make sure there are no regressions caused by new features.
During development, as new code is integrated, automated testing conducted at the [code](/general/development/tools/phpunit) and [interface](/general/development/tools/behat) levels, to make sure there are no regressions caused by new features.

In the last month before the release, a feature freeze is called (no new features can be added) and volunteer testers from the Moodle community perform manual [QA testing](/general/development/process/testing/qa) of Moodle features. The current set of functional tests is listed in [MDLQA-1](https://tracker.moodle.org/browse/MDLQA-1). The list of tests is extended as new features are added, though we're also trying to reduce the number as more automated [acceptance tests](https://docs.moodle.org/dev/Acceptance_testing) are developed.
In the last month before the release, a feature freeze is called (no new features can be added) and volunteer testers from the Moodle community perform manual [QA testing](/general/development/process/testing/qa) of Moodle features. The current set of functional tests is listed in [MDLQA-1](https://tracker.moodle.org/browse/MDLQA-1). The list of tests is extended as new features are added, though we're also trying to reduce the number as more automated [acceptance tests](/general/development/tools/behat) are developed.

There is also a set of tests for manually testing any major theme changes - [MDLQA-11592](https://tracker.moodle.org/browse/MDLQA-11592).

Expand Down
8 changes: 4 additions & 4 deletions general/development/process/testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ We recommend that you follow [PHPUnit integration](https://docs.moodle.org/dev/P

Moodle uses a framework called Behat to automatically test the user-interface. Tests can be written for each plugin, and for Moodle core.

- To run the existing tests, read [Running acceptance test](https://docs.moodle.org/dev/Running_acceptance_test). You really need to do this first.
- To write new tests, read [Writing acceptance tests](https://docs.moodle.org/dev/Writing_acceptance_tests).
- To define new steps that can you used when writing tests, see [Writing new acceptance test step definitions](https://docs.moodle.org/dev/Writing_new_acceptance_test_step_definitions).
- To run the existing tests, read [Running acceptance test](/general/development/tools/behat/running). You really need to do this first.
- To write new tests, read [Writing acceptance tests](/general/development/tools/behat/writing).
- To define new steps that can you used when writing tests, see [Writing new acceptance test step definitions](/general/development/tools/behat/writing#writing-new-acceptance-test-step-definitions).

:::tip
Because Behat tests work through the Moodle user interface, they are a bit slow. Therefore, you should probably also use PHPUnit to test the detailed edge cases in your code.
Expand All @@ -93,7 +93,7 @@ Every day, an automated build in a test server runs a large number of tests conc
These tests must pass completely before a new release can be made.

- [Unit tests](https://docs.moodle.org/dev/Unit_tests) using the PHPUnit framework
- [Acceptance testing](https://docs.moodle.org/dev/Acceptance_testing) using the Behat framework
- [Acceptance testing](/general/development/tools/behat) using the Behat framework
- Performance testing using JMeter.

:::note
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions general/development/tools/behat/browsers/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: Browsers
sidebar_position: 3
tags:
- Behat
- Quality Assurance
---
This page complements [Behat](/general/development/tools/behat) providing info about how to run the acceptance tests suite in different browsers.

## Drivers

There are [Selenium drivers](http://docs.seleniumhq.org/projects/webdriver/) to run acceptance tests in different browsers:

- Firefox - https://code.google.com/p/selenium/wiki/FirefoxDriver
- Chrome - https://code.google.com/p/selenium/wiki/ChromeDriver
- Safari - https://code.google.com/p/selenium/wiki/SafariDriver
- Internet Explorer - https://code.google.com/p/selenium/wiki/InternetExplorerDriver
- Microsoft Edge - https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
- PhantomJS (Webkit) - http://phantomjs.org/
- IPhone - https://code.google.com/p/selenium/wiki/IPhoneDriver

Each driver should be downloaded and Selenium .jar should be started specifying the path to the driver; depending on the driver there could be other requirements.

### PhantomJS

PhantomJS is different as it is a headless browser as it is quite faster than other drivers, it doesn't need a GUI to run and can execute JS, it doesn't even need to be used through Selenium (you can do it though, but it's not officially supported) and you can do it

- Download PhantomJS: http://phantomjs.org/download.html
- Run the following command

```console
/path/to/your/phantomjs/bin/phantomjs --webdriver=4444
```

Note that 4444 is the default port used by Selenium, so you must specify another one if you want to run them together and specify the port in `$CFG->behat_config`.

### Examples

```console title="Selenium in Linux (firefox by default + chrome)"
java -jar /opt/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/opt/chromedriver
```

```console title="Selenium in OSx (firefox & safari by default + chrome)"
java -jar /Users/moodle/Downloads/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/Users/moodle/Downloads/chromedriver
```

```console title="Selenium in Windows (started using git bash) (firefox by default + chrome + internet explorer)"
java -jar /c/seleniumdrivers/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/c/seleniumdrivers/chromedriver.exe -Dwebdriver.ie.driver=/c/seleniumdrivers/IEDriverServer.exe
```

```console title="PhantomJS"
/path/to/your/phantomjs/bin/phantomjs --webdriver=4444
```

## Compatibility

Not all the drivers can execute all of Moodle's step definitions; we tagged the step definitions that are using features not supported by all browsers and also limitations that some browsers have; refer to the following table to know which browsers can run which tags:

<!-- cspell:ignore zerosize -->
| | File uploads (@_file_upload) | Browser dialogs (@_alert) | Switch window (@_switch_window) | Switch frame (@_switch_iframe) | Bugs in chrome (@skip_chrome_zerosize) | Bug in phantomjs (@_bug_phantomjs) |
|------------------------------|-------------------------------------------------------------------|---------------------------------|--------------------------------|----------------------------------------|------------------------------------|
| Firefox | Yes | Yes | Yes | Yes | Yes | Yes |
| Chrome | Yes | Yes | Yes | Yes | No (see [MDL-71108](https://tracker.moodle.org/browse/MDL-71108)) | Yes |
| Internet Explorer | Yes | Yes | No | Yes | Yes | Yes |
| Safari | Yes | No | No | Yes | Yes | Yes |
| PhantomJS | No | No | Yes | Yes | Yes | No |

Note that, to skip some tag, you must prepend it with the <tt>~</tt> (logical NOT) character. Examples:

- Run all tests but `@_alert</tt> ones: <tt>--tags '~@_alert'`
- Run all chrome tests but `@skip_chrome_zerosize` ones: `--tags '@JavaScript&&~@skip_chrome_zerosize'`

## Working combinations of OS+Browser+selenium

As OS, Browsers and Selenium keeps updating, some combination of OS+Browser+Selenium will not work on specific moodle version.

We try to support the latest version of these combinations but they are not always BC and hence may not work with older releases. Please refer to [Working combinations of OS+Browser+selenium](/general/development/tools/behat/browsers/supportedbrowsers) to ensure you have correct combination of them to run acceptance test.
Loading

0 comments on commit e9300cb

Please sign in to comment.