Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
behat_general Class Reference
Inheritance diagram for behat_general:
behat_base behat_session_interface

Public Member Functions

 a_new_page_should_have_loaded_since_i_started_watching ()
 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. More...
 
 a_new_page_should_not_have_loaded_since_i_started_watching ()
 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. More...
 
 accept_currently_displayed_alert_dialog ()
 Accepts the currently displayed alert dialog. More...
 
 assert_element_contains_text ($text, $element, $selectortype)
 Checks, that the specified element contains the specified text. More...
 
 assert_element_not_contains_text ($text, $element, $selectortype)
 Checks, that the specified element does not contain the specified text. More...
 
 assert_page_contains_text ($text)
 Checks, that page contains specified text. More...
 
 assert_page_not_contains_text ($text)
 Checks, that page doesn't contain specified text. More...
 
 click_link ($link)
 Clicks link with specified id|title|alt|text. More...
 
 database_family_used_is_one_of_the_following (TableNode $databasefamilies)
 Checks if database family used is using one of the specified, else skip. More...
 
 dismiss_currently_displayed_alert_dialog ()
 Dismisses the currently displayed alert dialog. More...
 
 download_file_from_link ($link)
 Given the text of a link, download the linked file and return the contents. More...
 
 following_should_download_between_and_bytes ($link, $minexpectedsize, $maxexpectedsize)
 Downloads the file from a link on the page and checks the size is in a given range. More...
 
 following_should_download_bytes ($link, $expectedsize)
 Downloads the file from a link on the page and checks the size. More...
 
 following_should_exist_in_the_table ($table, TableNode $data)
 Checks that the provided value exist in table. More...
 
 following_should_not_exist_in_the_table ($table, TableNode $data)
 Checks that the provided values do not exist in a table. More...
 
 getSession ($name=null)
 Returns the Mink session. More...
 
 i_am_on_course_index ()
 Opens course index page. More...
 
 i_am_on_homepage ()
 Opens Moodle homepage. More...
 
 i_am_on_site_homepage ()
 Opens Moodle site homepage. More...
 
 i_change_window_size_to ($windowviewport, $windowsize)
 Change browser window size small: 640x480, medium: 1024x768, large: 2560x1600, custom: widthxheight. More...
 
 i_click_on ($element, $selectortype)
 Generic click action. More...
 
 i_click_on_confirming_the_dialogue ($element, $selectortype)
 Clicks the specified element and confirms the expected dialogue. More...
 
 i_click_on_dismissing_the_dialogue ($element, $selectortype)
 Clicks the specified element and dismissing the expected dialogue. More...
 
 i_click_on_in_the ($element, $selectortype, $nodeelement, $nodeselectortype)
 Click on the element of the specified type which is located inside the second element. More...
 
 i_click_on_skipping_visibility_check ($element, $selectortype)
 Trigger click on node via javascript instead of actually clicking on it via pointer. More...
 
 i_close_all_opened_windows ()
 Closes all extra windows opened during the navigation. More...
 
 i_drag_and_i_drop_it_in ($source, $sourcetype, $target, $targettype)
 Drags and drops the specified element to the specified container. More...
 
 i_hover ($element, $selectortype)
 Generic mouse over action. More...
 
 i_manually_press_enter ()
 Manually press enter key. More...
 
 i_manually_press_tab ($shift='')
 Manually press tab key. More...
 
 i_mark_this_test_as_long_running (int $factor=2)
 Increase the webdriver timeouts. More...
 
 i_pause_scenario_execution ()
 Wait unit user press Enter/Return key. More...
 
 i_post_tab_key_in_element ($element, $selectortype)
 Press tab key on a specific element. More...
 
 i_press_in_the_browser ($button)
 Presses a given button in the browser. More...
 
 i_press_key_in_element ($key, $element, $selectortype)
 Trigger a keydown event for a key on a specific element. More...
 
 i_press_named_key (string $modifiers, string $key)
 Press a named or character key with an optional set of modifiers. More...
 
 i_run_all_adhoc_tasks ()
 Runs all ad-hoc tasks in the queue. More...
 
 i_run_the_scheduled_task ($taskname)
 Runs a scheduled task immediately, given full class name. More...
 
 i_should_see_occurrences_of_in_element ($elementscount, $text, $element, $selectortype)
 Checks, that the specified element contains the specified text a certain amount of times. More...
 
 i_start_watching_to_see_if_a_new_page_loads ()
 Prepare to detect whether or not a new page has loaded (or the same page reloaded) some time in the future. More...
 
 i_take_focus_off_field ($element, $selectortype)
 Sets the focus and takes away the focus from an element, generating blur JS event. More...
 
 i_trigger_cron ()
 This step triggers cron like a user would do going to admin/cron.php. More...
 
 i_type (string $keys)
 Send key presses to the browser without first changing focusing, or applying the key presses to a specific element. More...
 
 i_visit ($localurl)
 Visit a local URL relative to the behat root. More...
 
 i_wait_seconds ($seconds)
 Waits X seconds. More...
 
 i_wait_to_be_redirected ()
 Follows the page redirection. More...
 
 in_the_should_be_visible ($element, $selectortype, $nodeelement, $nodeselectortype)
 Checks, that the specified element is visible inside the specified container. More...
 
 in_the_should_not_be_visible ($element, $selectortype, $nodeelement, $nodeselectortype)
 Checks, that the existing element is not visible inside the existing container. More...
 
 reload ()
 Reloads the current page. More...
 
 row_column_of_table_should_contain ($row, $column, $table, $value)
 Checks the provided value exists in specific row/column of table. More...
 
 row_column_of_table_should_not_contain ($row, $column, $table, $value)
 Checks the provided value should not exist in specific row/column of table. More...
 
 should_appear_after (string $postelement, string $postselectortype, string $preelement, string $preselectortype, ?string $containerelement=null, ?string $containerselectortype=null)
 Checks, that the first specified element appears after the second one. More...
 
 should_appear_before (string $preelement, string $preselectortype, string $postelement, string $postselectortype, ?string $containerelement=null, ?string $containerselectortype=null)
 Checks, that the first specified element appears before the second one. More...
 
 should_be_visible ($element, $selectortype)
 Checks, that the specified element is visible. More...
 
 should_exist ($element, $selectortype)
 Checks the provided element and selector type exists in the current page. More...
 
 should_exist_in_the ($element, $selectortype, $containerelement, $containerselectortype)
 Checks that an element and selector type exists in another element and selector type on the current page. More...
 
 should_not_be_visible ($element, $selectortype)
 Checks, that the existing element is not visible. More...
 
 should_not_exist ($element, $selectortype)
 Checks that the provided element and selector type not exists in the current page. More...
 
 should_not_exist_in_the ($element, $selectortype, $containerelement, $containerselectortype)
 Checks that an element and selector type does not exist in another element and selector type on the current page. More...
 
 switch_to_iframe ($name)
 Switches to the specified iframe. More...
 
 switch_to_the_main_frame ()
 Switches to the main Moodle frame. More...
 
 switch_to_the_main_window ()
 Switches to the main Moodle window. More...
 
 switch_to_window ($windowname)
 Switches to the specified window. More...
 
 the_attribute_of_should_be_set ($attribute, $element, $selectortype, $not=null)
 Checks whether there the specified attribute is set or not. More...
 
 the_attribute_of_should_contain ($attribute, $element, $selectortype, $text)
 Checks whether there is an attribute on the given element that contains the specified text. More...
 
 the_attribute_of_should_not_contain ($attribute, $element, $selectortype, $text)
 Checks that the attribute on the given element does not contain the specified text. More...
 
 the_element_should_be_disabled ($element, $selectortype)
 Checks, that element of specified type is disabled. More...
 
 the_element_should_be_enabled ($element, $selectortype)
 Checks, that element of specified type is enabled. More...
 
 the_element_should_be_readonly ($element, $selectortype)
 Checks the provided element and selector type are readonly on the current page. More...
 
 the_element_should_not_be_readonly ($element, $selectortype)
 Checks the provided element and selector type are not readonly on the current page. More...
 
 the_focused_element_is ($not, $nodeelement, $nodeselectortype)
 Checks focus is with the given element. More...
 
 the_focused_element_is_in_the ($not, $element, $selectortype, $nodeelement, $nodeselectortype)
 Checks focus is with the given element. More...
 
 the_image_at_should_be_identical_to ($element, $selectortype, $filepath)
 Checks that the image on the page is the same as one of the fixture files. More...
 
 wait_until_does_not_exists ($element, $selectortype)
 Waits until the provided element does not exist in the DOM. More...
 
 wait_until_exists ($element, $selectortype)
 Waits until the provided element selector exists in the DOM. More...
 
 wait_until_the_page_is_ready ()
 Waits until the page is completely loaded. More...
 

Public Attributes

const EXTENDED_TIMEOUT = 10
 And extended timeout for specific cases. More...
 
string const MAIN_WINDOW_NAME = '__moodle_behat_main_window_name'
 used by switch_to_window() and switch_to_the_main_window() to work-around a Chrome browser issue.
 
string const PAGE_LOAD_DETECTION_STRING = 'new_page_not_loaded_since_behat_started_watching'
 when we want to check whether or not a new page has loaded, we first write this unique string into the page. More...
 
const PAGE_READY_JS
 The JS code to check that the page is ready. More...
 
const REDUCED_TIMEOUT = 2
 Small timeout. More...
 
const TIMEOUT = 6
 The timeout for each Behat step (load page, wait for an element to load...). More...
 

Protected Member Functions

 check_element_order (?string $containerelement, ?string $containerselectortype, string $preelement, string $preselectortype, string $postelement, string $postselectortype, string $msg)
 Shared code to check whether an element is before or after another one. More...
 
 get_page_load_xpath ()
 Helper used by a_new_page_should_have_loaded_since_i_started_watching and a_new_page_should_not_have_loaded_since_i_started_watching. More...
 

Member Function Documentation

◆ a_new_page_should_have_loaded_since_i_started_watching()

behat_general::a_new_page_should_have_loaded_since_i_started_watching ( )

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.

@Given /^a new page should have loaded since I started watching$/

◆ a_new_page_should_not_have_loaded_since_i_started_watching()

behat_general::a_new_page_should_not_have_loaded_since_i_started_watching ( )

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.

@Given /^a new page should not have loaded since I started watching$/

◆ accept_currently_displayed_alert_dialog()

behat_general::accept_currently_displayed_alert_dialog ( )

Accepts the currently displayed alert dialog.

This step does not work in all the browsers, consider it experimental. @Given /^I accept the currently displayed dialog$/

◆ assert_element_contains_text()

behat_general::assert_element_contains_text (   $text,
  $element,
  $selectortype 
)

Checks, that the specified element contains the specified text.

When running Javascript tests it also considers that texts may be hidden.

@Then /^I should see "(?P<text_string>(?:[^"]|::")*)" in the "(?P<element_string>(?:[^"]|")*)" "(?P<text_selector_string>[^"]*)"$/

Exceptions
ElementNotFoundException
ExpectationException
Parameters
string$text
string$elementElement we look in.
string$selectortypeThe type of element where we are looking in.

◆ assert_element_not_contains_text()

behat_general::assert_element_not_contains_text (   $text,
  $element,
  $selectortype 
)

Checks, that the specified element does not contain the specified text.

When running Javascript tests it also considers that texts may be hidden.

@Then /^I should not see "(?P<text_string>(?:[^"]|::")*)" in the "(?P<element_string>(?:[^"]|")*)" "(?P<text_selector_string>[^"]*)"$/

Exceptions
ElementNotFoundException
ExpectationException
Parameters
string$text
string$elementElement we look in.
string$selectortypeThe type of element where we are looking in.

◆ assert_page_contains_text()

behat_general::assert_page_contains_text (   $text)

Checks, that page contains specified text.

It also checks if the text is visible when running Javascript tests.

@Then /^I should see "(?P<text_string>(?:[^"]|::")*)"$/

Exceptions
ExpectationException
Parameters
string$text

◆ assert_page_not_contains_text()

behat_general::assert_page_not_contains_text (   $text)

Checks, that page doesn't contain specified text.

When running Javascript tests it also considers that texts may be hidden.

@Then /^I should not see "(?P<text_string>(?:[^"]|::")*)"$/

Exceptions
ExpectationException
Parameters
string$text

◆ check_element_order()

behat_general::check_element_order ( ?string  $containerelement,
?string  $containerselectortype,
string  $preelement,
string  $preselectortype,
string  $postelement,
string  $postselectortype,
string  $msg 
)
protected

Shared code to check whether an element is before or after another one.

Parameters
string$containerelement
string$containerselectortype
string$preelementThe locator of the preceding element
string$preselectortypeThe locator of the preceding element
string$postelementThe locator of the following element
string$postselectortypeThe selector type of the following element
string$msgMessage to output if this fails

◆ click_link()

behat_general::click_link (   $link)

Clicks link with specified id|title|alt|text.

@When /^I follow "(?P<link_string>(?:[^"]|::")*)"$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$link

◆ database_family_used_is_one_of_the_following()

behat_general::database_family_used_is_one_of_the_following ( TableNode  $databasefamilies)

Checks if database family used is using one of the specified, else skip.

(mysql, postgres, mssql, oracle, etc.)

@Given /^database family used is one of the following:$/

Parameters
TableNode$databasefamilieslist of database.
Return values
void.
Exceptions
Moodle::BehatExtension::Exception::SkippedException

◆ dismiss_currently_displayed_alert_dialog()

behat_general::dismiss_currently_displayed_alert_dialog ( )

Dismisses the currently displayed alert dialog.

This step does not work in all the browsers, consider it experimental. @Given /^I dismiss the currently displayed dialog$/

◆ download_file_from_link()

behat_general::download_file_from_link (   $link)

Given the text of a link, download the linked file and return the contents.

This is a helper method used by following_should_download_bytes() and following_should_download_between_and_bytes()

Parameters
string$linkthe text of the link.
Return values
stringthe content of the downloaded file.

◆ following_should_download_between_and_bytes()

behat_general::following_should_download_between_and_bytes (   $link,
  $minexpectedsize,
  $maxexpectedsize 
)

Downloads the file from a link on the page and checks the size is in a given range.

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

The range includes the endpoints. That is, a 10 byte file in considered to be between "5" and "10" bytes, and between "10" and "20" bytes.

@Then /^following "(?P<link_string>[^"]*)" should download between "(?P<min_bytes>::d+)" and "(?P<max_bytes>\d+)" bytes$/

Exceptions
ExpectationException
Parameters
string$linkthe text of the link.
number$minexpectedsizethe minimum expected file size in bytes.
number$maxexpectedsizethe maximum expected file size in bytes.

◆ following_should_download_bytes()

behat_general::following_should_download_bytes (   $link,
  $expectedsize 
)

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.

@Then /^following "(?P<link_string>[^"]*)" should download "(?P<expected_bytes>::d+)" bytes$/

Exceptions
ExpectationException
Parameters
string$linkthe text of the link.
number$expectedsizethe expected file size in bytes.

◆ following_should_exist_in_the_table()

behat_general::following_should_exist_in_the_table (   $table,
TableNode  $data 
)

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.

@Then /^the following should exist in the "(?P<table_string>[^"]*)" table:$/

Exceptions
ExpectationException
Parameters
string$tablename of table
TableNode$datatable with first row as header and following values | Header 1 | Header 2 | Header 3 | | Value 1 | Value 2 | Value 3|

◆ following_should_not_exist_in_the_table()

behat_general::following_should_not_exist_in_the_table (   $table,
TableNode  $data 
)

Checks that the provided values do not exist in a table.

@Then /^the following should not exist in the "(?P<table_string>[^"]*)" table:$/

Exceptions
ExpectationException
Parameters
string$tablename of table
TableNode$datatable with first row as header and following values | Header 1 | Header 2 | Header 3 | | Value 1 | Value 2 | Value 3|

◆ get_page_load_xpath()

behat_general::get_page_load_xpath ( )
protected

◆ getSession()

behat_session_interface::getSession (   $name = null)
inherited

Returns the Mink session.

Parameters
string | null$namename of the session OR active session will be used
Return values
Behat::Mink::Session

Implemented in behat_form_field.

◆ i_am_on_course_index()

behat_general::i_am_on_course_index ( )

Opens course index page.

@Given /^I am on course index$/

◆ i_am_on_homepage()

behat_general::i_am_on_homepage ( )

Opens Moodle homepage.

@Given /^I am on homepage$/

◆ i_am_on_site_homepage()

behat_general::i_am_on_site_homepage ( )

Opens Moodle site homepage.

@Given /^I am on site homepage$/

◆ i_change_window_size_to()

behat_general::i_change_window_size_to (   $windowviewport,
  $windowsize 
)

Change browser window size small: 640x480, medium: 1024x768, 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.

Exceptions
ExpectationException@Then /^I change (window|viewport) size to "(small|medium|large|d+x::d+)"$/ @Then /^I change the (window|viewport) size to "(small|medium|large|d+x::d+)"$/
Parameters
string$windowsizesize of the window (small|medium|large|wxh).

◆ i_click_on()

behat_general::i_click_on (   $element,
  $selectortype 
)

Generic click action.

Click on the element of the specified type.

@When /^I click on "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)"$/

Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for

◆ i_click_on_confirming_the_dialogue()

behat_general::i_click_on_confirming_the_dialogue (   $element,
  $selectortype 
)

Clicks the specified element and confirms the expected dialogue.

@When /^I click on "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" confirming the dialogue$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for

◆ i_click_on_dismissing_the_dialogue()

behat_general::i_click_on_dismissing_the_dialogue (   $element,
  $selectortype 
)

Clicks the specified element and dismissing the expected dialogue.

@When /^I click on "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" dismissing the dialogue$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for

◆ i_click_on_in_the()

behat_general::i_click_on_in_the (   $element,
  $selectortype,
  $nodeelement,
  $nodeselectortype 
)

Click on the element of the specified type which is located inside the second element.

@When /^I click on "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" in the "(?P<element_container_string>(?:[^"]|::")*)" "(?P<text_selector_string>[^"]*)"$/

Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for
string$nodeelementElement we look in
string$nodeselectortypeThe type of selector where we look in

◆ i_click_on_skipping_visibility_check()

behat_general::i_click_on_skipping_visibility_check (   $element,
  $selectortype 
)

Trigger click on node via javascript instead of actually clicking on it via pointer.

This function resolves the issue of nested elements.

@When /^I click on "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" skipping visibility check$/

Parameters
string$element
string$selectortype

◆ i_close_all_opened_windows()

behat_general::i_close_all_opened_windows ( )

Closes all extra windows opened during the navigation.

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

@Given /^I close all opened windows$/

Exceptions
DriverExceptionIf there aren't exactly 1 tabs open when finish or no javascript running

◆ i_drag_and_i_drop_it_in()

behat_general::i_drag_and_i_drop_it_in (   $source,
  $sourcetype,
  $target,
  $targettype 
)

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.

@Given /^I drag "(?P<element_string>(?:[^"]|::")*)" "(?P<selector1_string>(?:[^"]|")*)" and I drop it in "(?P<container_element_string>(?:[^"]|::")*)" "(?P<selector2_string>(?:[^"]|\")*)"$/

Parameters
string$element
string$selectortype
string$containerelement
string$containerselectortype

◆ i_hover()

behat_general::i_hover (   $element,
  $selectortype 
)

Generic mouse over action.

Mouse over a element of the specified type.

@When /^I hover "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)"$/

Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for

◆ i_manually_press_enter()

behat_general::i_manually_press_enter ( )

Manually press enter key.

@When /^I press enter/

Exceptions
DriverException

◆ i_manually_press_tab()

behat_general::i_manually_press_tab (   $shift = '')

Manually press tab key.

@When /^I press( shift)? tab$/

Parameters
string$shiftstring optional step verifier
Exceptions
DriverException

◆ i_mark_this_test_as_long_running()

behat_general::i_mark_this_test_as_long_running ( int  $factor = 2)

Increase the webdriver timeouts.

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

@Given I mark this test as slow setting a timeout factor of :factor

◆ i_pause_scenario_execution()

behat_general::i_pause_scenario_execution ( )

Wait unit user press Enter/Return key.

Useful when debugging a scenario.

@Then /^(?:|I )pause(?:| scenario execution)$/

◆ i_post_tab_key_in_element()

behat_general::i_post_tab_key_in_element (   $element,
  $selectortype 
)

Press tab key on a specific element.

@When /^I press tab key in "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)"$/

Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for
Exceptions
DriverException
ExpectationException

◆ i_press_in_the_browser()

behat_general::i_press_in_the_browser (   $button)

Presses a given button in the browser.

NOTE: Phantomjs and goutte driver reloads page while navigating back and forward.

@Then /^I press the "(back|forward|reload)" button in the browser$/

Parameters
string$buttonthe button to press.
Exceptions
ExpectationException

◆ i_press_key_in_element()

behat_general::i_press_key_in_element (   $key,
  $element,
  $selectortype 
)

Trigger a keydown event for a key on a specific element.

@When /^I press key "(?P<key_string>(?:[^"]|::")*)" in "(?P<element_string>(?:[^"]|")*)" "(?P<selector_string>[^"]*)"$/

Parameters
string$keyeither char-code or character itself, may optionally be prefixed with ctrl-, alt-, shift- or meta-
string$elementElement we look for
string$selectortypeThe type of what we look for
Exceptions
DriverException
ExpectationException

◆ i_press_named_key()

behat_general::i_press_named_key ( string  $modifiers,
string  $key 
)

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

@When /^I press the (?P<modifiers_string>.* )?(?P<key_string>.*) key$/

Parameters
string$modifiersA list of keyboard modifiers, separated by the + character
string$keyThe name of the key to press

◆ i_run_all_adhoc_tasks()

behat_general::i_run_all_adhoc_tasks ( )

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.

@Given /^I run all adhoc tasks$/

Exceptions
DriverException

◆ i_run_the_scheduled_task()

behat_general::i_run_the_scheduled_task (   $taskname)

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/tool/task/cli/schedule_task.php.

@Given /^I run the scheduled task "(?P<task_name>[^"]+)"$/

Parameters
string$tasknameName of task e.g. 'mod_whatever::task::do_something'

◆ i_should_see_occurrences_of_in_element()

behat_general::i_should_see_occurrences_of_in_element (   $elementscount,
  $text,
  $element,
  $selectortype 
)

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.

@Then /^I should see "(?P<elementscount_number>::d+)" occurrences of "(?P<text_string>(?:[^"]|")*)" in the "(?P<element_string>(?:[^"]|::")*)" "(?P<text_selector_string>[^"]*)"$/

Exceptions
ElementNotFoundException
ExpectationException
Parameters
int$elementscountHow many occurrences of the element we look for.
string$text
string$elementElement we look in.
string$selectortypeThe type of element where we are looking in.

◆ i_start_watching_to_see_if_a_new_page_loads()

behat_general::i_start_watching_to_see_if_a_new_page_loads ( )

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

@Given /^I start watching to see if a new page loads$/

◆ i_take_focus_off_field()

behat_general::i_take_focus_off_field (   $element,
  $selectortype 
)

Sets the focus and takes away the focus from an element, generating blur JS event.

@When /^I take focus off "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)"$/

Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for

◆ i_trigger_cron()

behat_general::i_trigger_cron ( )

This step triggers cron like a user would do going to admin/cron.php.

@Given /^I trigger cron$/

◆ i_type()

behat_general::i_type ( string  $keys)

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"

@When I type :keys

Parameters
string$keysThe key, or list of keys, to type

◆ i_visit()

behat_general::i_visit (   $localurl)

Visit a local URL relative to the behat root.

@When I visit :localurl

Parameters
string | moodle_url$localurlThe URL relative to the behat_wwwroot to visit.

◆ i_wait_seconds()

behat_general::i_wait_seconds (   $seconds)

Waits X seconds.

Required after an action that requires data from an AJAX request.

@Then /^I wait "(?P<seconds_number>::d+)" seconds$/

Parameters
int$seconds

◆ i_wait_to_be_redirected()

behat_general::i_wait_to_be_redirected ( )

Follows the page redirection.

Use this step after any action that shows a message and waits for a redirection

@Given /^I wait to be redirected$/

◆ in_the_should_be_visible()

behat_general::in_the_should_be_visible (   $element,
  $selectortype,
  $nodeelement,
  $nodeselectortype 
)

Checks, that the specified element is visible inside the specified container.

Only available in tests using Javascript.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" in the "(?P<element_container_string>(?:[^"]|::")*)" "(?P<text_selector_string>[^"]*)" should be visible$/

Exceptions
ElementNotFoundException
DriverException
ExpectationException
Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for
string$nodeelementElement we look in
string$nodeselectortypeThe type of selector where we look in

◆ in_the_should_not_be_visible()

behat_general::in_the_should_not_be_visible (   $element,
  $selectortype,
  $nodeelement,
  $nodeselectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" in the "(?P<element_container_string>(?:[^"]|::")*)" "(?P<text_selector_string>[^"]*)" should not be visible$/

Exceptions
ElementNotFoundException
ExpectationException
Parameters
string$elementElement we look for
string$selectortypeThe type of what we look for
string$nodeelementElement we look in
string$nodeselectortypeThe type of selector where we look in

◆ reload()

behat_general::reload ( )

Reloads the current page.

@Given /^I reload the page$/

◆ row_column_of_table_should_contain()

behat_general::row_column_of_table_should_contain (   $row,
  $column,
  $table,
  $value 
)

Checks the provided value exists in specific row/column of table.

@Then /^"(?P<row_string>[^"]*)" row "(?P<column_string>[^"]*)" column of "(?P<table_string>[^"]*)" table should contain "(?P<value_string>[^"]*)"$/

Exceptions
ElementNotFoundException
Parameters
string$rowrow text which will be looked in.
string$columncolumn text to search (or numeric value for the column position)
string$tabletable id/class/caption
string$valuetext to check.

◆ row_column_of_table_should_not_contain()

behat_general::row_column_of_table_should_not_contain (   $row,
  $column,
  $table,
  $value 
)

Checks the provided value should not exist in specific row/column of table.

@Then /^"(?P<row_string>[^"]*)" row "(?P<column_string>[^"]*)" column of "(?P<table_string>[^"]*)" table should not contain "(?P<value_string>[^"]*)"$/

Exceptions
ElementNotFoundException
Parameters
string$rowrow text which will be looked in.
string$columncolumn text to search
string$tabletable id/class/caption
string$valuetext to check.

◆ should_appear_after()

behat_general::should_appear_after ( string  $postelement,
string  $postselectortype,
string  $preelement,
string  $preselectortype,
?string  $containerelement = null,
?string  $containerselectortype = null 
)

Checks, that the first specified element appears after the second one.

@Then :postelement :postselectortype should appear after :preelement :preselectortype @Then :postelement :postselectortype should appear after :preelement :preselectortype in the :containerelement :containerselectortype

Exceptions
ExpectationException
Parameters
string$postelementThe locator of the latest element
string$postselectortypeThe selector type of the latest element
string$preelementThe locator of the preceding element
string$preselectortypeThe selector type of the preceding element
string$containerelement
string$containerselectortype

◆ should_appear_before()

behat_general::should_appear_before ( string  $preelement,
string  $preselectortype,
string  $postelement,
string  $postselectortype,
?string  $containerelement = null,
?string  $containerselectortype = null 
)

Checks, that the first specified element appears before the second one.

@Then :preelement :preselectortype should appear before :postelement :postselectortype @Then :preelement :preselectortype should appear before :postelement :postselectortype in the :containerelement :containerselectortype

Exceptions
ExpectationException
Parameters
string$preelementThe locator of the preceding element
string$preselectortypeThe selector type of the preceding element
string$postelementThe locator of the latest element
string$postselectortypeThe selector type of the latest element
string$containerelement
string$containerselectortype

◆ should_be_visible()

behat_general::should_be_visible (   $element,
  $selectortype 
)

Checks, that the specified element is visible.

Only available in tests using Javascript.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>(?:[^"]|")*)" should be visible$/

Exceptions
ElementNotFoundException
ExpectationException
DriverException
Parameters
string$element
string$selectortype
Return values
void

◆ should_exist()

behat_general::should_exist (   $element,
  $selectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should exist$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$elementThe locator of the specified selector
string$selectortypeThe selector type

◆ should_exist_in_the()

behat_general::should_exist_in_the (   $element,
  $selectortype,
  $containerelement,
  $containerselectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should exist in the "(?P<element2_string>(?:[^"]|::")*)" "(?P<selector2_string>[^"]*)"$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$elementThe locator of the specified selector
string$selectortypeThe selector type
string$containerelementThe container selector type
string$containerselectortypeThe container locator

◆ should_not_be_visible()

behat_general::should_not_be_visible (   $element,
  $selectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>(?:[^"]|")*)" should not be visible$/

Exceptions
ElementNotFoundException
ExpectationException
Parameters
string$element
string$selectortype
Return values
void

◆ should_not_exist()

behat_general::should_not_exist (   $element,
  $selectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should not exist$/

Exceptions
ExpectationException
Parameters
string$elementThe locator of the specified selector
string$selectortypeThe selector type

◆ should_not_exist_in_the()

behat_general::should_not_exist_in_the (   $element,
  $selectortype,
  $containerelement,
  $containerselectortype 
)

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.

@Then /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should not exist in the "(?P<element2_string>(?:[^"]|::")*)" "(?P<selector2_string>[^"]*)"$/

Exceptions
ExpectationException
Parameters
string$elementThe locator of the specified selector
string$selectortypeThe selector type
string$containerelementThe container selector type
string$containerselectortypeThe container locator

◆ switch_to_iframe()

behat_general::switch_to_iframe (   $name)

Switches to the specified iframe.

@Given /^I switch to "(?P<iframe_name_string>(?:[^"]|::")*)" iframe$/ @Given /^I switch to "(?P<iframe_name_string>(?:[^"]|::")*)" class iframe$/

Parameters
string$nameThe name of the iframe

◆ switch_to_the_main_frame()

behat_general::switch_to_the_main_frame ( )

Switches to the main Moodle frame.

@Given /^I switch to the main frame$/

◆ switch_to_the_main_window()

behat_general::switch_to_the_main_window ( )

Switches to the main Moodle window.

Useful when you finish interacting with popup windows.

@Given /^I switch to the main window$/

◆ switch_to_window()

behat_general::switch_to_window (   $windowname)

Switches to the specified window.

Useful when interacting with popup windows.

@Given /^I switch to "(?P<window_name_string>(?:[^"]|::")*)" window$/

Parameters
string$windowname

◆ the_attribute_of_should_be_set()

behat_general::the_attribute_of_should_be_set (   $attribute,
  $element,
  $selectortype,
  $not = null 
)

Checks whether there the specified attribute is set or not.

@Then the :attribute attribute of :element :selectortype should be set @Then the :attribute attribute of :element :selectortype should :not be set

Exceptions
ExpectationException
Parameters
string$attributeName of attribute
string$elementThe locator of the specified selector
string$selectortypeThe selector type
string$not

◆ the_attribute_of_should_contain()

behat_general::the_attribute_of_should_contain (   $attribute,
  $element,
  $selectortype,
  $text 
)

Checks whether there is an attribute on the given element that contains the specified text.

@Then /^the "(?P<attribute_string>[^"]*)" attribute of "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should contain "(?P<text_string>(?:[^"]|::")*)"$/

Exceptions
ExpectationException
Parameters
string$attributeName of attribute
string$elementThe locator of the specified selector
string$selectortypeThe selector type
string$textExpected substring

◆ the_attribute_of_should_not_contain()

behat_general::the_attribute_of_should_not_contain (   $attribute,
  $element,
  $selectortype,
  $text 
)

Checks that the attribute on the given element does not contain the specified text.

@Then /^the "(?P<attribute_string>[^"]*)" attribute of "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should not contain "(?P<text_string>(?:[^"]|::")*)"$/

Exceptions
ExpectationException
Parameters
string$attributeName of attribute
string$elementThe locator of the specified selector
string$selectortypeThe selector type
string$textExpected substring

◆ the_element_should_be_disabled()

behat_general::the_element_should_be_disabled (   $element,
  $selectortype 
)

Checks, that element of specified type is disabled.

@Then /^the "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should be disabled$/

Exceptions
ExpectationExceptionThrown by behat_base::find
Parameters
string$elementElement we look in
string$selectortypeThe type of element where we are looking in.

◆ the_element_should_be_enabled()

behat_general::the_element_should_be_enabled (   $element,
  $selectortype 
)

Checks, that element of specified type is enabled.

@Then /^the "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should be enabled$/

Exceptions
ExpectationExceptionThrown by behat_base::find
Parameters
string$elementElement we look on
string$selectortypeThe type of where we look

◆ the_element_should_be_readonly()

behat_general::the_element_should_be_readonly (   $element,
  $selectortype 
)

Checks the provided element and selector type are readonly on the current page.

@Then /^the "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should be readonly$/

Exceptions
ExpectationExceptionThrown by behat_base::find
Parameters
string$elementElement we look in
string$selectortypeThe type of element where we are looking in.

◆ the_element_should_not_be_readonly()

behat_general::the_element_should_not_be_readonly (   $element,
  $selectortype 
)

Checks the provided element and selector type are not readonly on the current page.

@Then /^the "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should not be readonly$/

Exceptions
ExpectationExceptionThrown by behat_base::find
Parameters
string$elementElement we look in
string$selectortypeThe type of element where we are looking in.

◆ the_focused_element_is()

behat_general::the_focused_element_is (   $not,
  $nodeelement,
  $nodeselectortype 
)

Checks focus is with the given element.

@Then /^the focused element is( not)? "(?P<node_string>(?:[^"]|::")*)" "(?P<node_selector_string>[^"]*)"$/

Parameters
string$notoptional step verifier
string$nodeelementElement identifier
string$nodeselectortypeElement type
Exceptions
DriverExceptionIf not using JavaScript
ExpectationException

◆ the_focused_element_is_in_the()

behat_general::the_focused_element_is_in_the (   $not,
  $element,
  $selectortype,
  $nodeelement,
  $nodeselectortype 
)

Checks focus is with the given element.

@Then /^the focused element is( not)? "(?P<n>(?:[^"]|::")*)" "(?P<ns>[^"]*)" in the "(?P<c>(?:[^"]|::")*)" "(?P<cs>[^"]*)"$/

Parameters
string$notstring optional step verifier
string$elementElement identifier
string$selectortypeElement type
string$nodeelementElement we look in
string$nodeselectortypeThe type of selector where we look in
Exceptions
DriverExceptionIf not using JavaScript
ExpectationException

◆ the_image_at_should_be_identical_to()

behat_general::the_image_at_should_be_identical_to (   $element,
  $selectortype,
  $filepath 
)

Checks that the image on the page is the same as one of the fixture files.

@Then /^the image at "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should be identical to "(?P<filepath_string>(?:[^"]|::")*)"$/

Exceptions
ExpectationException
Parameters
string$elementThe locator of the image
string$selectortypeThe selector type
string$filepathpath to the fixture file

◆ wait_until_does_not_exists()

behat_general::wait_until_does_not_exists (   $element,
  $selectortype 
)

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.

@Given /^I wait until "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" does not exist$/

Parameters
string$element
string$selector
Return values
void

◆ wait_until_exists()

behat_general::wait_until_exists (   $element,
  $selectortype 
)

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.

@Given /^I wait until "(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" exists$/

Parameters
string$element
string$selector
Return values
void

◆ wait_until_the_page_is_ready()

behat_general::wait_until_the_page_is_ready ( )

Waits until the page is completely loaded.

This step is auto-executed after every step.

@Given /^I wait until the page is ready$/

Member Data Documentation

◆ EXTENDED_TIMEOUT

const behat_session_interface::EXTENDED_TIMEOUT = 10
inherited

And extended timeout for specific cases.

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_extended_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_extended_timeout()

◆ PAGE_LOAD_DETECTION_STRING

string const behat_general::PAGE_LOAD_DETECTION_STRING = 'new_page_not_loaded_since_behat_started_watching'

when we want to check whether or not a new page has loaded, we first write this unique string into the page.

Then later, by checking whether it is still there, we can tell if a new page has been loaded.

◆ PAGE_READY_JS

const behat_session_interface::PAGE_READY_JS
inherited
Initial value:
= "document.readyState === 'complete' && " .
"(typeof M !== 'object' || typeof M.util !== 'object' || " .
"typeof M.util.pending_js === 'undefined' || M.util.pending_js.length === 0)"

The JS code to check that the page is ready.

The document must be complete and either M.util.pending_js must be empty, or it must not be defined at all.

◆ REDUCED_TIMEOUT

const behat_session_interface::REDUCED_TIMEOUT = 2
inherited

Small timeout.

A reduced timeout for cases where self::TIMEOUT is too much and a simple $this->getSession()->getPage()->find() could not be enough.

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_reduced_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_reduced_timeout()

◆ TIMEOUT

const behat_session_interface::TIMEOUT = 6
inherited

The timeout for each Behat step (load page, wait for an element to load...).

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_timeout()

The documentation for this class was generated from the following file: