Skip to content

Commit

Permalink
Merge pull request #1063 from ferranrecio/MDL-81885-main
Browse files Browse the repository at this point in the history
[docs] Improve generator tool using behat - MDL-81885
  • Loading branch information
sarjona authored Jul 5, 2024
2 parents 161f1d7 + 9130e74 commit d5cb6dc
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions general/development/tools/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,39 @@ Before executing the behat generators, you need a `feature` file you want to exe

The tool does not use `selenium` or any other browser wrapper. It reads the feature file and executes specific steps in it.

This means:

1. The tool will only execute a few steps, which are generators and set config values. If any other type of step is present in the `feature` file, it will show a parsing error.
1. For now, the tool can only execute normal scenarios. It does not support background, or outline scenarios.

:::

This means:
:::tip Example

1. The tool will only execute generator steps. If any other type of step is present in the `feature` file, it will show a parsing error.
1. For now, the tool can only execute normal scenarios. It does not support background, outline, or scenario outline scenarios.
Some example Behat generator files can be found in [`admin/tool/generator/tests/fixtures/`](https://github.com/moodle/moodle/blob/main/admin/tool/generator/tests/fixtures/). For instance, [`testscenario/scenario.feature`](https://github.com/moodle/moodle/blob/main/admin/tool/generator/tests/fixtures/testscenario/scenario.feature) creates a course with two assignment activities and enrols one teacher along with five students.

:::

To execute the behat generators via the web interface, go to `Site administration > Development > Create testing scenarios`. Once there, you can upload the `feature` file you want to execute and see the the execution results.
### Execute a testing scenario behat file

To execute the behat generators via CLI, you can use the following command:
Before running a testing scenario, you need to install all behat dependencies. If you already execute some behat on the instance you can skip this step. Otherwise, you need to install the dependencies by running the following command:

```bash
php admin/tool/generator/cli/runtestscenario.php --feature=/path/to/some/testing/scenario.feature
php admin/tool/generator/cli/runtestscenario.php
```

:::tip Example
There are two ways to run a testing scenario using a behat file: via the web interface or the CLI.

Some example Behat generator files can be found in [`admin/tool/generator/tests/fixtures/`](https://github.com/moodle/moodle/blob/main/admin/tool/generator/tests/fixtures/). For instance, [`testscenario/scenario.feature`](https://github.com/moodle/moodle/blob/main/admin/tool/generator/tests/fixtures/testscenario/scenario.feature) creates a course with two assignment activities and enrols one teacher along with five students.
To run via web interface:

:::
1. Go to `Site administration > Development > Create testing scenarios`.
1. Upload the `feature` file you want to execute and submit the form.

To run via CLI:

1. Copy the `feature` file you want to execute to some server location. You will need the full path to the file.
1. Run the following command:

```bash
php admin/tool/generator/cli/runtestscenario.php --feature=/path/to/some/testing/scenario.feature
```

0 comments on commit d5cb6dc

Please sign in to comment.