Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

General use steps definitions.

Copyright: 2012 David MonllaĆ³
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 2315 lines (97 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 1 file
 lib/behat/behat_base.php

Defines 1 class

behat_general:: (88 methods):
  i_am_on_homepage()
  i_am_on_site_homepage()
  i_am_on_course_index()
  reload()
  i_wait_to_be_redirected()
  switch_to_iframe()
  switch_to_the_main_frame()
  switch_to_window()
  switch_to_second_window()
  switch_to_the_main_window()
  i_close_all_opened_windows()
  accept_currently_displayed_alert_dialog()
  dismiss_currently_displayed_alert_dialog()
  click_link()
  i_wait_seconds()
  wait_until_the_page_is_ready()
  wait_until_exists()
  wait_until_does_not_exists()
  i_hover()
  i_hover_in_the()
  i_click_on()
  i_take_focus_off_field()
  i_click_on_confirming_the_dialogue()
  i_click_on_dismissing_the_dialogue()
  i_click_on_in_the()
  i_drag_and_i_drop_it_in()
  should_be_visible()
  should_not_be_visible()
  in_the_should_be_visible()
  in_the_should_not_be_visible()
  assert_page_contains_text()
  assert_page_not_contains_text()
  assert_element_contains_text()
  assert_element_not_contains_text()
  should_appear_before()
  should_appear_after()
  check_element_order()
  the_element_should_be_disabled()
  the_element_should_be_enabled()
  the_element_should_be_readonly()
  the_element_should_not_be_readonly()
  should_exist()
  should_not_exist()
  edit_mode_should_be_available()
  is_edit_mode_available()
  i_trigger_cron()
  i_run_the_scheduled_task()
  i_run_all_adhoc_tasks()
  should_exist_in_the()
  should_not_exist_in_the()
  i_change_window_size_to()
  the_attribute_of_should_be_set()
  the_attribute_of_should_contain()
  the_attribute_of_should_not_contain()
  row_column_of_table_should_contain()
  row_column_of_table_should_not_contain()
  following_should_exist_in_the_table()
  following_should_not_exist_in_the_table()
  download_file_from_link()
  following_should_download_bytes()
  following_should_download_between_and_bytes()
  the_image_at_should_be_identical_to()
  i_start_watching_to_see_if_a_new_page_loads()
  a_new_page_should_have_loaded_since_i_started_watching()
  a_new_page_should_not_have_loaded_since_i_started_watching()
  get_page_load_xpath()
  i_pause_scenario_execution()
  i_press_in_the_browser()
  i_type()
  i_press_named_key()
  i_press_key_in_element()
  i_post_tab_key_in_element()
  database_family_used_is_one_of_the_following()
  plugin_is_installed()
  the_focused_element_is()
  the_focused_element_is_in_the()
  i_manually_press_tab()
  i_click_on_skipping_visibility_check()
  i_should_see_occurrences_of_in_element()
  i_manually_press_enter()
  i_visit()
  i_mark_this_test_as_long_running()
  i_click_on_the_dynamic_tab()
  i_enable_plugin()
  the_default_editor_is_set_to()
  the_site_is_running_moodle_version_or_higher()
  the_site_is_running_moodle_version_or_lower()
  the_page_title_should_contain()


Class: behat_general  - X-Ref

Cross component steps definitions.

Basic web application definitions from MinkExtension and
BehatchExtension. Definitions modified according to our needs
when necessary and including only the ones we need to avoid
overlapping and confusion.

i_am_on_homepage()   X-Ref
Opens Moodle homepage.


i_am_on_site_homepage()   X-Ref
Opens Moodle site homepage.


i_am_on_course_index()   X-Ref
Opens course index page.


reload()   X-Ref
Reloads the current page.


i_wait_to_be_redirected()   X-Ref
Follows the page redirection. Use this step after any action that shows a message and waits for a redirection


switch_to_iframe($name)   X-Ref
Switches to the specified iframe.

param: string $name The name of the iframe

switch_to_the_main_frame()   X-Ref
No description

switch_to_window($windowname)   X-Ref
Switches to the specified window. Useful when interacting with popup windows.

param: string $windowname

switch_to_second_window()   X-Ref
Switches to a second window.


switch_to_the_main_window()   X-Ref
Switches to the main Moodle window. Useful when you finish interacting with popup windows.


i_close_all_opened_windows()   X-Ref
Closes all extra windows opened during the navigation.

This assumes all popups are opened by the main tab and you will now get back.


accept_currently_displayed_alert_dialog()   X-Ref
Accepts the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental.


dismiss_currently_displayed_alert_dialog()   X-Ref
Dismisses the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental.


click_link($link)   X-Ref
Clicks link with specified id|title|alt|text.

param: string $link

i_wait_seconds($seconds)   X-Ref
Waits X seconds. Required after an action that requires data from an AJAX request.

param: int $seconds

wait_until_the_page_is_ready()   X-Ref
Waits until the page is completely loaded. This step is auto-executed after every step.


wait_until_exists($element, $selectortype)   X-Ref
Waits until the provided element selector exists in the DOM

Using the protected method as this method will be usually
called by other methods which are not returning a set of
steps and performs the actions directly, so it would not
be executed if it returns another step.
param: string $element
param: string $selector
return: void

wait_until_does_not_exists($element, $selectortype)   X-Ref
Waits until the provided element does not exist in the DOM

Using the protected method as this method will be usually
called by other methods which are not returning a set of
steps and performs the actions directly, so it would not
be executed if it returns another step.
param: string $element
param: string $selector
return: void

i_hover($element, $selectortype)   X-Ref
Generic mouse over action. Mouse over a element of the specified type.

param: string $element Element we look for
param: string $selectortype The type of what we look for

i_hover_in_the(string $element, $selectortype, string $containerelement, $containerselectortype)   X-Ref
Generic mouse over action. Mouse over a element of the specified type.

param: string $element Element we look for
param: string $selectortype The type of what we look for
param: string $containerelement Element we look for
param: string $containerselectortype The type of what we look for

i_click_on($element, $selectortype)   X-Ref
Generic click action. Click on the element of the specified type.

param: string $element Element we look for
param: string $selectortype The type of what we look for

i_take_focus_off_field($element, $selectortype)   X-Ref
Sets the focus and takes away the focus from an element, generating blur JS event.

param: string $element Element we look for
param: string $selectortype The type of what we look for

i_click_on_confirming_the_dialogue($element, $selectortype)   X-Ref
Clicks the specified element and confirms the expected dialogue.

param: string $element Element we look for
param: string $selectortype The type of what we look for

i_click_on_dismissing_the_dialogue($element, $selectortype)   X-Ref
Clicks the specified element and dismissing the expected dialogue.

param: string $element Element we look for
param: string $selectortype The type of what we look for

i_click_on_in_the($element, $selectortype, $nodeelement, $nodeselectortype)   X-Ref
Click on the element of the specified type which is located inside the second element.

param: string $element Element we look for
param: string $selectortype The type of what we look for
param: string $nodeelement Element we look in
param: string $nodeselectortype The type of selector where we look in

i_drag_and_i_drop_it_in($source, $sourcetype, $target, $targettype)   X-Ref
Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental.

The steps definitions calling this step as part of them should
manage the wait times by themselves as the times and when the
waits should be done depends on what is being dragged & dropper.

param: string $element
param: string $selectortype
param: string $containerelement
param: string $containerselectortype

should_be_visible($element, $selectortype)   X-Ref
Checks, that the specified element is visible. Only available in tests using Javascript.

param: string $element
param: string $selectortype
return: void

should_not_be_visible($element, $selectortype)   X-Ref
Checks, that the existing element is not visible. Only available in tests using Javascript.

As a "not" method, it's performance could not be good, but in this
case the performance is good because the element must exist,
otherwise there would be a ElementNotFoundException, also here we are
not spinning until the element is visible.

param: string $element
param: string $selectortype
return: void

in_the_should_be_visible($element, $selectortype, $nodeelement, $nodeselectortype)   X-Ref
Checks, that the specified element is visible inside the specified container. Only available in tests using Javascript.

param: string $element Element we look for
param: string $selectortype The type of what we look for
param: string $nodeelement Element we look in
param: string $nodeselectortype The type of selector where we look in

in_the_should_not_be_visible($element, $selectortype, $nodeelement, $nodeselectortype)   X-Ref
Checks, that the existing element is not visible inside the existing container. Only available in tests using Javascript.

As a "not" method, it's performance could not be good, but in this
case the performance is good because the element must exist,
otherwise there would be a ElementNotFoundException, also here we are
not spinning until the element is visible.

param: string $element Element we look for
param: string $selectortype The type of what we look for
param: string $nodeelement Element we look in
param: string $nodeselectortype The type of selector where we look in

assert_page_contains_text($text)   X-Ref
Checks, that page contains specified text. It also checks if the text is visible when running Javascript tests.

param: string $text

assert_page_not_contains_text($text)   X-Ref
No description

assert_element_contains_text($text, $element, $selectortype)   X-Ref
No description

assert_element_not_contains_text($text, $element, $selectortype)   X-Ref
No description

should_appear_before(string $preelement,string $preselectortype,string $postelement,string $postselectortype,?string $containerelement = null,?string $containerselectortype = null)   X-Ref
No description

should_appear_after(string $postelement,string $postselectortype,string $preelement,string $preselectortype,?string $containerelement = null,?string $containerselectortype = null)   X-Ref
Checks, that the first specified element appears after the second one.

param: string $postelement The locator of the latest element
param: string $postselectortype The selector type of the latest element
param: string $preelement The locator of the preceding element
param: string $preselectortype The selector type of the preceding element
param: string $containerelement
param: string $containerselectortype

check_element_order(?string $containerelement,?string $containerselectortype,string $preelement,string $preselectortype,string $postelement,string $postselectortype,string $msg)   X-Ref
Shared code to check whether an element is before or after another one.

param: string $containerelement
param: string $containerselectortype
param: string $preelement The locator of the preceding element
param: string $preselectortype The locator of the preceding element
param: string $postelement The locator of the following element
param: string $postselectortype The selector type of the following element
param: string $msg Message to output if this fails

the_element_should_be_disabled($element, $selectortype)   X-Ref
Checks, that element of specified type is disabled.

param: string $element Element we look in
param: string $selectortype The type of element where we are looking in.

the_element_should_be_enabled($element, $selectortype)   X-Ref
Checks, that element of specified type is enabled.

param: string $element Element we look on
param: string $selectortype The type of where we look

the_element_should_be_readonly($element, $selectortype)   X-Ref
Checks the provided element and selector type are readonly on the current page.

param: string $element Element we look in
param: string $selectortype The type of element where we are looking in.

the_element_should_not_be_readonly($element, $selectortype)   X-Ref
Checks the provided element and selector type are not readonly on the current page.

param: string $element Element we look in
param: string $selectortype The type of element where we are looking in.

should_exist($element, $selectortype)   X-Ref
Checks the provided element and selector type exists in the current page.

This step is for advanced users, use it if you don't find anything else suitable for what you need.

param: string $element The locator of the specified selector
param: string $selectortype The selector type

should_not_exist($element, $selectortype)   X-Ref
Checks that the provided element and selector type not exists in the current page.

This step is for advanced users, use it if you don't find anything else suitable for what you need.

param: string $element The locator of the specified selector
param: string $selectortype The selector type

edit_mode_should_be_available(bool $not = false)   X-Ref
Ensure that edit mode is (not) available on the current page.

param: bool $not

is_edit_mode_available()   X-Ref
Check whether edit mode is available on the current page.

return: bool

i_trigger_cron()   X-Ref
This step triggers cron like a user would do going to admin/cron.php.


i_run_the_scheduled_task($taskname)   X-Ref
Runs a scheduled task immediately, given full class name.

This is faster and more reliable than running cron (running cron won't
work more than once in the same test, for instance). However it is
a little less 'realistic'.

While the task is running, we suppress mtrace output because it makes
the Behat result look ugly.

Note: Most of the code relating to running a task is based on
admin/cli/scheduled_task.php.

param: string $taskname Name of task e.g. 'mod_whatever\task\do_something'

i_run_all_adhoc_tasks()   X-Ref
Runs all ad-hoc tasks in the queue.

This is faster and more reliable than running cron (running cron won't
work more than once in the same test, for instance). However it is
a little less 'realistic'.

While the task is running, we suppress mtrace output because it makes
the Behat result look ugly.


should_exist_in_the($element, $selectortype, $containerelement, $containerselectortype)   X-Ref
Checks that an element and selector type exists in another element and selector type on the current page.

This step is for advanced users, use it if you don't find anything else suitable for what you need.

param: string $element The locator of the specified selector
param: string $selectortype The selector type
param: NodeElement|string $containerelement The locator of the container selector
param: string $containerselectortype The container selector type

should_not_exist_in_the($element, $selectortype, $containerelement, $containerselectortype)   X-Ref
Checks that an element and selector type does not exist in another element and selector type on the current page.

This step is for advanced users, use it if you don't find anything else suitable for what you need.

param: string $element The locator of the specified selector
param: string $selectortype The selector type
param: NodeElement|string $containerelement The locator of the container selector
param: string $containerselectortype The container selector type

i_change_window_size_to($windowviewport, $windowsize)   X-Ref
Change browser window size

Allowed sizes:
- mobile: 425x750
- tablet: 768x1024
- small: 1024x768
- medium: 1366x768
- large: 2560x1600
- custom: widthxheight

Example: I change window size to "small" or I change window size to "1024x768"
or I change viewport size to "800x600". The viewport option is useful to guarantee that the
browser window has same viewport size even when you run Behat on multiple operating systems.

param: string $windowsize size of the window (mobile|tablet|small|medium|large|wxh).

the_attribute_of_should_be_set($attribute, $element, $selectortype, $not = null)   X-Ref
Checks whether there the specified attribute is set or not.

param: string $attribute Name of attribute
param: string $element The locator of the specified selector
param: string $selectortype The selector type
param: string $not

the_attribute_of_should_contain($attribute, $element, $selectortype, $text)   X-Ref
Checks whether there is an attribute on the given element that contains the specified text.

param: string $attribute Name of attribute
param: string $element The locator of the specified selector
param: string $selectortype The selector type
param: string $text Expected substring

the_attribute_of_should_not_contain($attribute, $element, $selectortype, $text)   X-Ref
Checks that the attribute on the given element does not contain the specified text.

param: string $attribute Name of attribute
param: string $element The locator of the specified selector
param: string $selectortype The selector type
param: string $text Expected substring

row_column_of_table_should_contain($row, $column, $table, $value)   X-Ref
Checks the provided value exists in specific row/column of table.

param: string $row row text which will be looked in.
param: string $column column text to search (or numeric value for the column position)
param: string $table table id/class/caption
param: string $value text to check.

row_column_of_table_should_not_contain($row, $column, $table, $value)   X-Ref
Checks the provided value should not exist in specific row/column of table.

param: string $row row text which will be looked in.
param: string $column column text to search
param: string $table table id/class/caption
param: string $value text to check.

following_should_exist_in_the_table($table, TableNode $data)   X-Ref
Checks that the provided value exist in table.

First row may contain column headers or numeric indexes of the columns
(syntax -1- is also considered to be column index). Column indexes are
useful in case of multirow headers and/or presence of cells with colspan.

param: string $table name of table
param: TableNode $data table with first row as header and following values

following_should_not_exist_in_the_table($table, TableNode $data)   X-Ref
Checks that the provided values do not exist in a table.

param: string $table name of table
param: TableNode $data table with first row as header and following values

download_file_from_link($link)   X-Ref
Given the text of a link, download the linked file and return the contents.

This is a helper method used by {@link following_should_download_bytes()}
and {@link following_should_download_between_and_bytes()}

param: string $link the text of the link.
return: string the content of the downloaded file.

following_should_download_bytes($link, $expectedsize)   X-Ref
Downloads the file from a link on the page and checks the size.

Only works if the link has an href attribute. Javascript downloads are
not supported. Currently, the href must be an absolute URL.

param: string $link the text of the link.
param: number $expectedsize the expected file size in bytes.

following_should_download_between_and_bytes($link, $minexpectedsize, $maxexpectedsize)   X-Ref
No description

the_image_at_should_be_identical_to($element, $selectortype, $filepath)   X-Ref
No description

i_start_watching_to_see_if_a_new_page_loads()   X-Ref
Prepare to detect whether or not a new page has loaded (or the same page reloaded) some time in the future.


a_new_page_should_have_loaded_since_i_started_watching()   X-Ref
Verify that a new page has loaded (or the same page has reloaded) since the
last "I start watching to see if a new page loads" step.


a_new_page_should_not_have_loaded_since_i_started_watching()   X-Ref
Verify that a new page has not loaded (or the same page has reloaded) since the
last "I start watching to see if a new page loads" step.


get_page_load_xpath()   X-Ref
Helper used by {@link a_new_page_should_have_loaded_since_i_started_watching}
and {@link a_new_page_should_not_have_loaded_since_i_started_watching}

return: string xpath expression.

i_pause_scenario_execution()   X-Ref
Wait unit user press Enter/Return key. Useful when debugging a scenario.


i_press_in_the_browser($button)   X-Ref
Presses a given button in the browser.
NOTE: Phantomjs and goutte driver reloads page while navigating back and forward.

param: string $button the button to press.

i_type(string $keys)   X-Ref
Send key presses to the browser without first changing focusing, or applying the key presses to a specific
element.

Example usage of this step:
When I type "Penguin"

param: string $keys The key, or list of keys, to type

i_press_named_key(string $modifiers, string $key)   X-Ref
Press a named or character key with an optional set of modifiers.

Supported named keys are:
- up
- down
- left
- right
- pageup|page_up
- pagedown|page_down
- home
- end
- insert
- delete
- backspace
- escape
- enter
- tab

You can also use a single character for the key name e.g. 'Ctrl C'.

Supported moderators are:
- shift
- ctrl
- alt
- meta

Example usage of this new step:
When I press the up key
When I press the space key
When I press the shift tab key

Multiple moderator keys can be combined using the '+' operator, for example:
When I press the ctrl+shift enter key
When I press the ctrl + shift enter key

param: string $modifiers A list of keyboard modifiers, separated by the `+` character
param: string $key The name of the key to press

i_press_key_in_element($key, $element, $selectortype)   X-Ref
Trigger a keydown event for a key on a specific element.

param: string $key either char-code or character itself,
param: string $element Element we look for
param: string $selectortype The type of what we look for

i_post_tab_key_in_element($element, $selectortype)   X-Ref
Press tab key on a specific element.

param: string $element Element we look for
param: string $selectortype The type of what we look for

database_family_used_is_one_of_the_following(TableNode $databasefamilies)   X-Ref
Checks if database family used is using one of the specified, else skip. (mysql, postgres, mssql, oracle, etc.)

param: TableNode $databasefamilies list of database.
return: void.

plugin_is_installed(string $plugin)   X-Ref
Checks if given plugin is installed, and skips the current scenario if not.

param: string $plugin frankenstyle plugin name, e.g. 'filter_embedquestion'.

the_focused_element_is($not, $nodeelement, $nodeselectortype)   X-Ref
Checks focus is with the given element.

param: string $not optional step verifier
param: string $nodeelement Element identifier
param: string $nodeselectortype Element type

the_focused_element_is_in_the($not, $element, $selectortype, $nodeelement, $nodeselectortype)   X-Ref
Checks focus is with the given element.

param: string $not string optional step verifier
param: string $element Element identifier
param: string $selectortype Element type
param: string $nodeelement Element we look in
param: string $nodeselectortype The type of selector where we look in

i_manually_press_tab($shift = '')   X-Ref
Manually press tab key.

param: string $shift string optional step verifier

i_click_on_skipping_visibility_check($element, $selectortype)   X-Ref
Trigger click on node via javascript instead of actually clicking on it via pointer.
This function resolves the issue of nested elements.

param: string $element
param: string $selectortype

i_should_see_occurrences_of_in_element($elementscount, $text, $element, $selectortype)   X-Ref
Checks, that the specified element contains the specified text a certain amount of times.
When running Javascript tests it also considers that texts may be hidden.

param: int    $elementscount How many occurrences of the element we look for.
param: string $text
param: string $element Element we look in.
param: string $selectortype The type of element where we are looking in.

i_manually_press_enter()   X-Ref
Manually press enter key.


i_visit($localurl)   X-Ref
Visit a local URL relative to the behat root.

param: string|moodle_url $localurl The URL relative to the behat_wwwroot to visit.

i_mark_this_test_as_long_running(int $factor = 2)   X-Ref
Increase the webdriver timeouts.

This should be reset between scenarios, or can be called again to decrease the timeouts.


i_click_on_the_dynamic_tab(string $tabname)   X-Ref
Click on a dynamic tab to load its content

param: string $tabname

i_enable_plugin($plugin, $plugintype)   X-Ref
Enable an specific plugin.

param: string $plugin Plugin we look for
param: string $plugintype The type of the plugin

the_default_editor_is_set_to(string $editor)   X-Ref
Set the default text editor to the named text editor.

param: string $editor

the_site_is_running_moodle_version_or_higher(string $minversion)   X-Ref
Allow to check for minimal Moodle version.

param: string $minversion The minimum version of Moodle required (inclusive).

the_site_is_running_moodle_version_or_lower(string $maxversion)   X-Ref
Allow to check for maximum Moodle version.

param: string $maxversion The maximum version of Moodle required (inclusive).

the_page_title_should_contain(string $title)   X-Ref
Check that the page title contains a given string.

param: string $title The string that should be present on the page title.