Testing Area/Behat Testing/Steps: Difference between revisions
From Mahara Wiki
< Testing Area | Behat Testing
(85 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
= Search for step samples = | |||
If you feel sure behat ''must have a way'' of doing something, but you can't find the step, the underlying methods are documented in the [http://mink.behat.org/en/latest/guides/traversing-pages.html Mink documentation]. It's pretty technical, but useful if you want to search out steps from the code they call, rather than the gherkin. | |||
== Browser == | |||
Use the following path to navigate to a dynamic page of the current behat steps that can be used and also all the places that they are used in: | |||
<code>http://<your mahara url>/testing/frameworks/behat/behat_steps_used.php</code> | |||
<br>Use these steps to create Behat tests | <br>Use these steps to create Behat tests | ||
<br>Copy and paste the steps in the order your need into a text editor (ie gedit or vim) to create your tests. | <br>Copy and paste the steps in the order your need into a text editor (ie gedit or vim) to create your tests. | ||
{{note|Replace the "And" with "Given, When, Then" where necessary. Replace Selectors and Elements with one from the list of [[Testing/Behat_Testing/Selectors_and_Elements| Selectors and Elements]]|reminder}} | {{note|Replace the "And" with "Given, When, Then" where necessary. Replace Selectors and Elements with one from the list of [[Testing/Behat_Testing/Selectors_and_Elements| Selectors and Elements]]|reminder}} | ||
== Command line == | |||
The fastest way to write test is using parts of previous tests. In the terminal type the following command to search through all the feature files for what you are looking for: | The fastest way to write test is using parts of previous tests. In the terminal type the following command to search through all the feature files for what you are looking for: | ||
grep --color=auto -RniP -C 3 --include *.feature '(given|when|then|and).*delete.*activity' * | grep --color=auto -RniP -C 3 --include *.feature '(given|when|then|and).*delete.*activity' * | ||
Line 11: | Line 19: | ||
grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/ | grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/ | ||
There are test steps provided with Behat in the MinkContext.php file and other | There are test steps provided with Behat in the MinkContext.php file and other custom steps written for Mahara. | ||
To get a list of steps and where they're used from your dev instance, go to http://mahara/testing/frameworks/behat/behat_steps_used.php | |||
The following three lines of code will give you a text file of the current steps, but it is not so pretty: | |||
egrep -r '@(Given|When|Then)' ~/code/mahara/external/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php > behat_steps.txt | egrep -r '@(Given|When|Then)' ~/code/mahara/external/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php > behat_steps.txt | ||
egrep -rh '@(Given|When|Then)' ~/code/mahara/htdocs/testing/frameworks/behat/classes >> behat_steps.txt | egrep -rh '@(Given|When|Then)' ~/code/mahara/htdocs/testing/frameworks/behat/classes >> behat_steps.txt | ||
perl -i -pe "s/[?\"\'\*\(\)\[\]^\\]\|\\\\]//g" behat_steps.txt | perl -i -pe "s/[?\"\'\*\(\)\[\]^\\]\|\\\\]//g" behat_steps.txt | ||
This creates a file called behat_steps.txt in your current directory which contains the list. It will confirm for you that a step exists in the code. Variables in the step are indicated by P<> or :. You can ignore / and /$ at the beginnings and ends of lines | This creates a file called behat_steps.txt in your current directory which contains the list. It will confirm for you that a step exists in the code, but it is not an attempt to quantify steps specifically used in Mahara. If the step is not explicitly referenced in code, it won't be in the list. Variables in the step are indicated by P<> or :. You can ignore / and /$ at the beginnings and ends of lines. | ||
=Backgrounds/ Way to create heaps of users, groups, institutions:= | = Available steps = | ||
== Backgrounds/ Way to create heaps of users, groups, institutions:== | |||
Given the following "'''users'''" exist: | Given the following "'''users'''" exist: | ||
| username | password | email | firstname | lastname | institution | authname | role | | | username | password | email | firstname | lastname | institution | authname | role | | ||
| UserA | | | UserA | Kupuh1pa! | [email protected] | Angela | User | mahara | internal | member | | ||
| UserB | | | UserB | Kupuh1pa! | [email protected] | Bob | User | mahara | internal | member | | ||
Given the following "'''groups'''" exist: | Given the following "'''groups'''" exist: | ||
Line 45: | Line 56: | ||
| Page Institution_01 | Institution page 01 | institution | instone | | | Page Institution_01 | Institution page 01 | institution | instone | | ||
| Page Site_01 | Site page 01 | institution | mahara | | | Page Site_01 | Site page 01 | institution | mahara | | ||
Create different block types on a page. | |||
And the following "blocks" exist: | |||
| title | type | page |retractable | data | | |||
| My text 1 | text | Page One | yes | This is some text | | |||
| image jpg | image | Page One | no | attachment=Image1.jpg; width=100 | | |||
| G files 2 | filedownload | Page One | auto | attachments=mahara_about.pdf,Image2.png,testvid3.mp4,mahara.mp3 | | |||
| Rss food | externalfeed | Page One | no | source=http://www.thekitchenmaid.com/feed;count=3 | | |||
| my social | socialprofile | Page One | no | sns=instagram,twitter,facebook,tumblr,pinterest,mysocialmedia | | |||
| gall style1 | gallery | Page One | no | attachments=Image1.jpg,Image3.png,Image3.png,Image2.png;imagesel=2;showdesc=yes;width=75;imagestyle=1;photoframe=1 | | |||
| myfolder | folder | Page One | no | attachments=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png,mahara.mp3;dirname=myfolder | | |||
| my html | html | Page One | yes | attachment=test_html.html | | |||
| my Journal | Journal | Page One | no | copytype=nocopy;count=5;journaltitle=journal1 | | |||
| Jrnalentry | blogpost | Group page | no | copytype=nocopy;journaltitle=journal1;entrytitle=Entry Two | | |||
| Comments | comment | Group page | | | | |||
| PeerAssessmt| peerassessment | Group page | auto | | | |||
| creativecoms| creativecommons| Group page | no | commercialuse=yes;license=3.0;allowmods=no | | |||
| my nav | navigation | Page Two | no | collection=collection one;copytoall=yes | | |||
| my plan | plans | Page Two | no | plans=Plan One,Plan Two;tasksdisplaycount=10 | | |||
| internalm | internalmedia | Page Three | no | attachment=testvid3.mp4 | | |||
| my pdf | pdf | Page Three | no | attachment=mahara_about.pdf | | |||
| recentposts |recentforumposts| Page Three | no | groupname=Group1;maxposts=3 | | |||
| nzslang | externalvideo | Page Three | no | source=https://youtu.be/yRxFm70nOrY | | |||
Note: ''Steps to create a block > Find the file type you want - give it a title, which page you want it on and if it is retractable'' | |||
Create heaps of collections | Create heaps of collections | ||
Line 76: | Line 113: | ||
| celeste | user | Spacefood | Spacefood is kind of gross if you don't cook it right | Mars journal | Mars,food | 0 | | | celeste | user | Spacefood | Spacefood is kind of gross if you don't cook it right | Mars journal | Mars,food | 0 | | ||
=Logging In= | ==Logging In/Out== | ||
Log in as an existing user. The example is the default user on the testing db. | |||
Given I log in as "username" with password "password" | |||
<small>''E.g:<br /> | |||
Given I log in as "admin" with password "Kupuhipa1" | |||
''</small> | |||
Log out. This is only necessary if you need to switch users during a scenario | |||
Given I log out | |||
{{note|The users will be given an automatic PW of Kupuhipa1 and the email account will be [email protected]. | |||
<br>If you want to set a user up with additional admin permissions you have to do that manually.|reminder}} | |||
==Press a key== | |||
mahara.rdaymond.wgtn.cat-it.co.nz | |||
Simulate a key press in a particular field | |||
And I press the key "key_name" in the "node_element" field | |||
<small>''E.g:<br /> | |||
And I press the key "Enter" in the "Search users" field<br /> | |||
''</small> | |||
==Mahara menu navigation== | |||
=Mahara menu navigation= | |||
Choose a main menu item: | Choose a main menu item: | ||
Line 112: | Line 159: | ||
''And I choose "Pages and collections" in "Portfolio" from main menu</small>'' | ''And I choose "Pages and collections" in "Portfolio" from main menu</small>'' | ||
=Mahara pages and blocks= | ==Scroll within pages== | ||
'''NOTE:''' scrolling is only done using ID which is unique | |||
Go to the top of the page | |||
And I scroll to the top | |||
Scroll to the top of an id tag | |||
And I scroll to the id "id" | |||
<small>''E.g: And I scroll to the id "createcustomlayoutpane"<br /> | |||
''</small> | |||
Scroll to the base of an id tag | |||
And I scroll to the base of id "id" | |||
<small>''E.g: And I scroll to the base of id "educationhistoryform"<br /> | |||
''</small> | |||
Scroll to the centre of an id tag | |||
And I scroll to the center of id "id" | |||
<small>''E.g: And I scroll to the center of id "overview-page"<br /> | |||
''</small> | |||
==Mahara pages and blocks== | |||
Open the configuration of a block | Open the configuration of a block | ||
And I configure the block "Block title" | And I configure the block "Block title" | ||
<small>''E.g:<br /> | |||
And I configure the block "Latest changes I can view"<br /> | |||
''</small> | |||
Delete a block | Delete a block | ||
And I delete the block "Block title" | And I delete the block "Block title" | ||
<small>''E.g:<br /> | |||
When I delete the block "1984"<br /> | |||
''</small> | |||
Expanding the blocks when adding content to a page | Expanding the blocks when adding content to a page | ||
Line 128: | Line 203: | ||
And I expand "General" node''</small> | And I expand "General" node''</small> | ||
=Opening/Loading/Closing Pages= | Collapsing content node | ||
And I collapse "text" node | |||
<small>''E.g:<br /> | |||
And I collapse "Text Block 1" node | |||
''</small> | |||
Expanding a node in a given property/css locator | |||
And I expand "text" node in the "property" property | |||
And I expand "text" node in the "element" "selector" //please use the property step above in preference to this. | |||
<small>''E.g:<br /> | |||
And I expand "External" node in the "blocktype sidebar" property<br /> | |||
''</small> | |||
Expand a section of the page | |||
And I expand the section "section_name" | |||
<small>''E.g:<br /> | |||
And I expand the section "Advanced options" | |||
''</small> | |||
Close a named section of the page | |||
And I unexpand the section "section_name" | |||
Expand all fieldsets | |||
And I expand all fieldsets | |||
Deletes a link that points to the named item as well as the item | |||
And I delete the link and resource menu item "link_name" | |||
<small>''E.g:<br /> | |||
And I delete the link and resource menu item "Test Menu Link" | |||
''</small> | |||
==Opening/Loading/Closing Pages== | |||
Line 135: | Line 241: | ||
<small>''E.g:<br /> | <small>''E.g:<br /> | ||
And I should be on "artefact/internal/index.php"''</small> | And I should be on "artefact/internal/index.php"''</small> | ||
Line 143: | Line 246: | ||
And I go to the homepage | And I go to the homepage | ||
And I am on homepage | And I am on homepage | ||
Checks, that current page is the homepage. | Checks, that current page is the homepage. | ||
And I should be on the homepage | And I should be on the homepage | ||
Reloads the current page. | Reloads the current page. | ||
And I reload the page | And I reload the page | ||
Waits until the page is completely loaded. This step is auto-executed after every step. | Waits until the page is completely loaded. This step is auto-executed after every step. | ||
And I wait until the page is ready | And I wait until the page is ready | ||
Take you to a specific page using the relative path: | Take you to a specific page using the relative path: | ||
Line 158: | Line 265: | ||
And I go to "page" | And I go to "page" | ||
<small>''Example: When I go to "admin/site/options.php"'' //opens the admin settings for your site.</small> | <small>''Example: When I go to "admin/site/options.php"'' //opens the admin settings for your site.</small> | ||
Opens user profile. | |||
And I am on user profile | |||
Go to a named portfolio page | |||
And I go to portfolio page "name" | |||
<small>''E.g: <br /> | |||
Given I go to portfolio page "Page UserA_01" | |||
''</small> | |||
Opens named Group page | Opens named Group page | ||
And I go to group "name" | And I go to group "name | ||
<small>''E.g: <br /> | |||
When I go to group "GroupA" | |||
''</small> | |||
Displays the page you are currently editing | |||
And I display the page | |||
Go to named view | |||
And I go to view "name" | |||
Moves backward one page in history. | Moves backward one page in history. | ||
Line 167: | Line 296: | ||
Moves forward one page in history | Moves forward one page in history | ||
And I move forward one page | And I move forward one page | ||
Go to the next page of results of the pagination | |||
And I jump to next page of the list "named_list" | |||
<small>''E.g: <br /> | |||
And I jump to next page of the list "groupviews_pagination"<br /> | |||
''</small> | |||
Go to the previous page of results | |||
And I jump to previous page of the list "named_list" | |||
Go to a numbered page of results | |||
And I jump to page "num" of the list "results" | |||
<small>''E.g: <br /> | |||
And I jump to page "2" of the list "sharedviews_pagination" <br /> | |||
''</small> | |||
Checks, that current page response status is equal to specified. | Checks, that current page response status is equal to specified. | ||
And the response status code should be 404 | And the response status code should be 404 | ||
Line 175: | Line 322: | ||
And the response status code should not be 404 | And the response status code should not be 404 | ||
= | ==Dialogs, frames, windows and popups== | ||
Line 182: | Line 329: | ||
Switches to the specified iframe. | Switches to the specified iframe. | ||
And I switch to "$iframename" iframe | And I switch to "$iframename" iframe | ||
Switches to the main Mahara frame. | Switches to the main Mahara frame. | ||
And I switch to the main frame | And I switch to the main frame | ||
Switches to the specified window. Useful when interacting with popup windows. | Switches to the specified window. Useful when interacting with popup windows. | ||
And I switch to “windowname” | And I switch to “windowname” window | ||
Switches to the main Mahara window. Useful when you finish interacting with popup windows. | Switches to the main Mahara window. Useful when you finish interacting with popup windows. | ||
And I switch to the main window | And I switch to the main window | ||
=Actions Requiring Waiting= | Interacting with popups (these aren't currently used in Mahara, so there are no Mahara-specific examples) | ||
And I accept the alert popup | |||
And I accept the confirm popup | |||
And I cancel the confirm popup | |||
And I fill in "text" for popup | |||
And I should see "text" in popup | |||
Accepts the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental. | |||
And I accept the currently displayed dialog | |||
Close the currently displayed dialog | |||
And I close the dialog | |||
Close the currently open config dialog | |||
And I close the config dialog | |||
Click on a particular element in the currently displayed dialog | |||
And I click on "text_element" in the dialog | |||
And I click on "Page" in the dialog | |||
Press a button and confirm action in one step | |||
And I press and confirm "button_text" | |||
''<small>E.g<br /> | |||
And I press and confirm "Delete user" | |||
</small>'' | |||
==Actions Requiring Waiting== | |||
Waits until the page is ready | |||
And I wait until the page is ready | |||
Waits X seconds. Required after an action that requires data from an AJAX request. Don't use this unless the test really needs it - i.e. keeps failing. | |||
Waits X seconds. Required after an action that requires data from an AJAX request. | |||
And I wait "$numberofseconds" seconds | And I wait "$numberofseconds" seconds | ||
<small>''E.g:<br /> | |||
And I wait "1" seconds<br /> | |||
''</small> | |||
Waits until the provided element selector exists in the DOM | Waits until the provided element selector exists in the DOM | ||
Line 211: | Line 385: | ||
And I wait until "element_string" "selector_string" does not exist | And I wait until "element_string" "selector_string" does not exist | ||
==Click Actions== | |||
=Click Actions= | |||
There are several options for clicking an element in a page. The key difference is in the html tags it has. | There are several options for clicking an element in a page. The key difference is in the html tags it has. | ||
Line 234: | Line 407: | ||
<small>''E.g:<br /> | <small>''E.g:<br /> | ||
And I click on "Help"''</small><br /> | And I click on "Help"''</small><br /> | ||
Click on an element in a dialog box | |||
And I click on "element" in the dialog | |||
<small>''E.g:<br /> | |||
And I click on "Page" in the dialog<br /> | |||
''</small> | |||
====Panel Menu steps==== | |||
Panel menus in Mahara are the boxes that display page/collection titles and edit/delete icons on the Pages and collections page. | |||
We have some specific steps to target them. | |||
Click on the page/collection title | |||
And I click the panel "text string" | |||
And I click on "text string" panel menu | |||
And I click on "text string" panel collection | |||
<small>''E.g:<br /> | |||
And I click the panel "Page UserA_01" <br /> | |||
And I click on "Page UserA_01" panel menu <br /> | |||
And I click on "Collection UserA_01" panel collection <br /> | |||
''</small> | |||
Click on a specific collection page | |||
And I click on "page_name" in "collection_name" panel collection | |||
<small>''E.g:<br /> | |||
And I click on "Page UserA_01" in "Collection UserA_01" panel collection <br /> | |||
''</small> | |||
Click the panel's edit, delete or access options | |||
And I click on "Edit/Manage/Delete" in "page_name" panel menu | |||
<small>''E.g:<br /> | |||
And I click on "Edit" in "Page UserA_01" panel menu <br /> | |||
''</small> | |||
====Clicking with locators==== | |||
If the element you want to click doesn't have an obvious tag, you may need to specify a css or xpath element to be able to click it. As these are not as user-friendly to read, we now have a properties file in mahara (/htdocs/testing/frameworks/behat/classes/properties.php) which converts the css or xpath element to a name which is more human-readable. Use the following property steps in preference to any that directly use a css or xpath element. If you need to target an element not included in the properties file, that element should be added to the properties file. | If the element you want to click doesn't have an obvious tag, you may need to specify a css or xpath element to be able to click it. As these are not as user-friendly to read, we now have a properties file in mahara (/htdocs/testing/frameworks/behat/classes/properties.php) which converts the css or xpath element to a name which is more human-readable. Use the following property steps in preference to any that directly use a css or xpath element. If you need to target an element not included in the properties file, that element should be added to the properties file. | ||
Line 257: | Line 467: | ||
Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental. | Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental. | ||
And I drag "$element" "$selector" and I drop | And I drag "$element" "$selector" and I drop in "$containerelement" ”$selector" | ||
====Clicking on table elements==== | ====Clicking on table elements==== | ||
Click on the row containing a text string | |||
And I click the row "text_string" | |||
Click on the link or button inside a list/table row containing the specified text. | Click on the link or button inside a list/table row containing the specified text. | ||
And I click on "link or button" in "row_text_string" row | And I click on "link or button" in "row_text_string" row | ||
<small>''E.g:<br /> | |||
And I click on "Edit access" in "Page GroupA_01" row <br /> | |||
''</small> | |||
Click on the delete button inside a list/table row containing the specified text. | Click on the delete button inside a list/table row containing the specified text. | ||
And I delete the "text string" row | And I delete the "text string" row | ||
<small>''E.g:<br /> | |||
Given I delete the "Public comment by anonymous user" row<br /> | |||
''</small> | |||
Click on the specified element inside a table row containing the specified text. | Click on the specified element inside a table row containing the specified text. | ||
And I click on "$element" "$selector" in the table row | And I click on "$element" "$selector" in the table row | ||
<small>''E.g:<br /> | |||
And I click on "hidden-user-search-[0]" "css_element" in the table row<br /> | |||
''</small> | |||
Click a Smartevidence matrix point | |||
And I click the matrix point "num,num" | |||
<small>''E.g:<br /> | |||
And I click on the matrix point "3,4" <br /> | |||
''</small> | |||
=Filling in Forms= | ==Filling in Forms== | ||
Attaches file to field with specified id|name|label|value | Attaches file to field with specified id|name|label|value | ||
Line 308: | Line 536: | ||
Selects a radio button | Selects a radio button | ||
And I select the radio "field_label" | |||
<small>''E.g:<br /> | |||
And I select the radio "Note block 1" | |||
''</small> | |||
====Checking fields for values==== | ====Checking fields for values==== | ||
Checks | Checks that form field with specified id|name|label|value has specified value. | ||
And the "field" field should contain "value" | And the "field" field should contain "value" | ||
<small>''E.g.<br /> | <small>''E.g.<br /> | ||
And the "Occupation" field should contain "Hairdresser"''</small> | And the "Occupation" field should contain "Hairdresser"''</small> | ||
Checks | Checks that form field with specified id|name|label|value doesn't have specified value. | ||
And the "field" field should not contain "value" | And the "field" field should not contain "value" | ||
<small>''E.g.<br /> | <small>''E.g.<br /> | ||
And the "System message" field should not contain "None"''</small> | And the "System message" field should not contain "None"''</small> | ||
Checks | Checks the field matches the value. | ||
And the field "field_string" matches value "field_value_string" | And the field "field_string" matches value "field_value_string" | ||
<small>''E.g.<br /> | <small>''E.g.<br /> | ||
And the field "Institution administrator" matches value "1"''</small> | And the field "Institution administrator" matches value "1"''</small> | ||
Checks | Checks the field does not match the value. | ||
And the field "field_string" does not match value "field_value_string" | And the field "field_string" does not match value "field_value_string" | ||
Line 371: | Line 602: | ||
''</small> | ''</small> | ||
These core behat steps attempt to manage account settings, but are not currently used in Mahara and may not work. TODO: See what they do. | |||
And I set the following account settings values "?" | |||
And the following site settings are set "?" | |||
And the following plugin settings are set "?" | |||
====Steps allowing relative dates==== | |||
It is annoying to write a test to test something in future which then becomes obsolete when that date passes. These steps allow you to use relative dates. They are a bit more complicated to use than some of the other steps, but will make your life much easier when dealing with dates in tests. The "format" option can either be given in as a Mahara specific format defined in htdocs/lang/en.utf8/langconfig.php or as a format the PHP date function understands: http://php.net/manual/en/function.date.php. The "date" option allows "today", "yesterday" and similar English words for relative dates, as accepted by the PHP strtotime function: http://php.net/manual/en/datetime.formats.relative.php | |||
Fill in a relative date | |||
And I fill in :element with :date date in the format :format | |||
<small>''E.g:<br /> | |||
And I fill in "Completion date" with "+6 months" date in the format "Y/m/d" | |||
''</small> | |||
Check for a relative date | |||
And I should see the date "date" in the "element" element with the format "format" | |||
<small>''E.g:<br /> | |||
And I should see the date "today" in the "#sharedcollectionlist" element with the format "d F Y" | |||
''</small> | |||
====Using select boxes==== | ====Using select boxes and select2 boxes==== | ||
Checks that given select box contains the specified option. | Checks that given select box contains the specified option. | ||
Line 402: | Line 649: | ||
And I additionally select "option" from "select" | And I additionally select "option" from "select" | ||
=== TinyMCE === | Set a specified select2 field to a given value | ||
And I set the select2 field "field_name" to "text" | |||
And I set the select2 value "text" for "field_name" | |||
<small>''E.g:<br /> | |||
And I set the select2 value "Institution One" for "reportconfigform_institution" | |||
''</small> | |||
Add a value to a select2 field | |||
And I fill in select2 input "field_name" with "text" | |||
Clear a select2 value | |||
And I clear value "text" from select2 field "field_name" | |||
<small>''E.g:<br /> | |||
And I clear value "one" from select2 field "instconf_tagselect" | |||
''</small> | |||
Enter a value to a select2 field and select it in one step | |||
And I fill in select2 input "field_name" with "text" and select "entry" | |||
<small>''E.g:<br /> | |||
And I fill in select2 input "sendmessage_recipients" with "UserA" and select "Angela User (UserA)" | |||
''</small> | |||
====Switches==== | |||
Enable a switch | |||
And I enable the switch "field_label" | |||
''<small>E.g<br /> | |||
And I enable the switch "Make comment public" | |||
</small>'' | |||
Disable a switch | |||
And I disable the switch "field_label" | |||
''<small>E.g<br /> | |||
And I disable the switch "Open" | |||
</small>'' | |||
Enable a switch in a row identified by id it contains | |||
And I enable the switch in "id" row | |||
''<small>E.g<br /> | |||
And I enable the switch in "mahara_group_get_groups_by_id" row | |||
</small>'' | |||
Enable several switches in one step | |||
And I enable the following switches: | |||
Disable several switches in one step | |||
And I disable the following switches: | |||
==== TinyMCE Editor - e.g. the "Comments" text box==== | |||
Our WYSIWYG rich text editor, TinyMCE, behaves a bit strangely, so it requires its own special behat step to fill in a TinyMCE rich text field. You must identify the editor by the | Our WYSIWYG rich text editor, TinyMCE, behaves a bit strangely, so it requires its own special behat step to fill in a TinyMCE rich text field. You must identify the editor by the label of the text box. The label may not be visible on the page. Inspect the text box element and search for label and you should find it. As an example, the comments text box label looks like this in the page source: <label for="add_feedback_form_message">Comment</label> | ||
And I fill in text " | Enter text in a TinyMCE box identified by label | ||
And I fill in "text" in editor "editor_label" | |||
''<small>E.g. | |||
And I fill in "Comment by page owner" in editor "Comment" | |||
</small>'' | |||
Or you can leave out the iframe name, and Behat will find and use the first TinyMCE editor on the page. (This is useful when the TinyMCE editor's ID is assigned dynamically.) | Or you can leave out the iframe name, and Behat will find and use the first TinyMCE editor on the page. (This is useful when the TinyMCE editor's ID is assigned dynamically.) | ||
And I fill in "text" in first editor | |||
Click a button in the TinyMCE editor | |||
And I click the "hover_over_text" button in the editor | |||
''<small>E.g. | |||
And I click the "Insert/edit image" button in the editor | |||
</small>'' | |||
==== Webservices ==== | |||
Fill the wstoken text in field. This step finds the relevant token and fills in the field. | |||
And I fill in the wstoken for "service" owned by "user" | |||
<small>''E.g:<br /> | |||
And I fill in the wstoken for "Test service" owned by "Service Admin"<br /> | |||
''</small> | |||
==Checking For Specific Visible Elements== | |||
Checks that page contains specified text. It also checks if the text is visible when running Javascript tests. | |||
And I should see "$text" | |||
<small>''E.g:<br /> | |||
Then I should see "Latest changes I can view"<br /> | |||
''</small> | |||
Checks that page doesn't contain specified text. When running Javascript tests it also considers that texts may be hidden. | |||
And I should not see "$text" | |||
<small>''E.g:<br /> | |||
And I should not see "Here is a new block" | |||
''</small> | |||
Checks that page contains text matching the specified regex pattern - useful when checking dynamic content. | |||
And I should see text matching "pattern" | |||
Checks | Checks that page doesn't contain text matching the specified regex pattern. | ||
And I should see | And I should not see text matching "pattern" | ||
Checks that HTML response contains specified string. | |||
And the response should contain "text" | |||
Checks | Checks that HTML response doesn't contain specified string. | ||
And | And the response should not contain "text" | ||
Checks | Checks that field with specified identifier exists on page. | ||
And I should see the field "field" | And I should see the field "field_label" | ||
Make sure the field label is not visible | |||
And I should not see the field "field_label" | |||
Checks | Checks that current page PATH matches regular expression. | ||
And the url should match "pattern" | And the url should match "pattern" | ||
====Checking for elements within blocks==== | |||
Check whether images exist in a block | |||
And I should see images within the block "blocktitle" | |||
<small>''E.g:<br /> | |||
And I should see images within the block "Some HTML" | |||
''</small> | |||
Make sure images don't exist in a block | |||
And I should not see images within the block "blocktitle" | |||
<small>''E.g:<br /> | |||
And I should not see images within the block "Text block with an external image" | |||
''</small> | |||
Find text within a block | |||
And I should see "text" in the block "blocktitle" | |||
<small>''E.g:<br /> | |||
And I should see "This is a test" in the block "Note block 2" | |||
''</small> | |||
Make sure text is not in a block | |||
And I should not see "text" in the block "blocktitle" | |||
====Steps that check for elements by CSS locator==== | |||
Since we have a properties file for CSS elements, the properties steps should be used in preference than those that pass the locators in directly. If you can't get the available property steps to do what you need, we should probably write additional steps using that functionality. | |||
Checks | Checks that an element can be seen in a specified property | ||
And " | And I should see "text" in the "name" property | ||
<small>''E.g:<br /> | |||
And I should see "(2 pages)" in the "My portfolios" property <br /> | |||
''</small> | |||
Checks that an element is not seen in a specified property | |||
And I should not see "text" in the "name" property | |||
<small>''E.g:<br /> | |||
Then I should not see "Page UserA_01" in the "My portfolios" property <br /> | |||
''</small> | |||
Checks | Checks that the specified element is visible. Only available in tests using Javascript. | ||
And | And "$elements" "$selector" should be visible | ||
Checks | Checks that the specified element is not visible. Only available in tests using Javascript. | ||
And | And "$element" "$selector" should not be visible | ||
Checks that the specified element is visible inside the specified container. Only available in tests using Javascript. | |||
And "$element" "$selector" in the "$elementcontainer" "$selector" should be visible | |||
Checks | Checks that the specified element is not visible inside the specified container. Only available in tests using Javascript. | ||
And "$element" "$selector" in the "$elementcontainer" "$textselector" should not be visible | |||
Checks that the specified element contains the specified text. When running Javascript tests it also considers that texts may be hidden. | |||
And I should see "$text" in the "$element" “$sector” | And I should see "$text" in the "$element" “$sector” | ||
Checks that the specified element does not contain the specified text. When running Javascript tests it also considers that texts may be hidden. | |||
Checks | |||
And I should not see "$text" in the “$element" "$selector” | And I should not see "$text" in the “$element" "$selector” | ||
Checks that the first specified element appears before the second one. | |||
Checks | |||
And "$element" "$selector" should appear before "$element" "$selector" | And "$element" "$selector" should appear before "$element" "$selector" | ||
Checks that the first specified element appears after the second one. | |||
Checks | |||
And "$element" "selector" should appear after $"element" $"selector" | And "$element" "selector" should appear after $"element" $"selector" | ||
Checks that the first specified element appears after the second one. | |||
Checks | |||
And "following_element_string" "selector1_string" should appear after "preceding_element_string" "selector2_string" | And "following_element_string" "selector1_string" should appear after "preceding_element_string" "selector2_string" | ||
Checks | Checks that element of specified type is disabled. | ||
And the "$element" "$selector" should be disabled | And the "$element" "$selector" should be disabled | ||
Checks | Checks that element of specified type is enabled. | ||
And the "$element" "$selector" should be enabled | And the "$element" "$selector" should be enabled | ||
Checks the provided element and selector type are readonly on the current page. | Checks the provided element and selector type are readonly on the current page. | ||
And the "$element" "$selector" should be readonly | And the "$element" "$selector" should be readonly | ||
Checks the provided element and selector type exists in the current page. | 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. | -This step is for advanced users, use it if you don't find anything else suitable for what you need. | ||
And "$element" "$selector" should exists | And "$element" "$selector" should exists | ||
Checks that the provided element and selector type not exists in the current page. | 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. | -This step is for advanced users, use it if you don't find anything else suitable for what you need. | ||
And "$element" "$selector" should not exists | And "$element" "$selector" should not exists | ||
Checks that an element and selector type exists in another element and selector type on the current page. | Checks that an element and selector type exists in another element and selector type on the current page. | ||
Line 499: | Line 850: | ||
And "$element" "$selector" should exist in the "$element" "$selector" | And "$element" "$selector" should exist in the "$element" "$selector" | ||
Checks that element with specified CSS contains specified text. | |||
Checks | |||
And I should see "text" in the "element" element | And I should see "text" in the "element" element | ||
<small>''E.g:<br /> | |||
And I should see "Text block 1" in the "div#column-container" element<br /> | |||
''</small> | |||
Checks that element with specified CSS doesn't contain specified text. | |||
Checks | |||
And I should not see "text" in the "element" element | And I should not see "text" in the "element" element | ||
<small>''E.g:<br /> | |||
And I should not see "Page UserA_01" in the ".bt-newviews" element | |||
''</small> | |||
Checks that element with specified CSS contains specified HTML. | |||
Checks | |||
And the "element" element should contain "value" | And the "element" element should contain "value" | ||
<small>''E.g:<br /> | |||
Then the "div#logo-area" element should contain "/theme/modern/images/site-logo"<br /> | |||
''</small> | |||
Checks that element with specified CSS doesn't contain specified HTML. | |||
Checks | |||
And the "element" element should not contain "value" | And the "element" element should not contain "value" | ||
Checks that element with specified CSS exists on page. | |||
Checks | |||
And I should see an "element" element | And I should see an "element" element | ||
Checks | Checks that element with specified CSS doesn't exist on page. | ||
And I should not see an "element" element | And I should not see an "element" element | ||
Checks that (?P<num>\d+) CSS elements exist on the page | |||
And I should see (?P<num>\d+) "element" elements | |||
Checks that the specified element is visible. Only available in tests using Javascript. | |||
And I should see the element "element" "selectortype" | |||
==Printing/Display== | |||
Opens last response content in browser. | |||
And show last response | |||
Prints last response to console. | Prints last response to console. | ||
Line 548: | Line 894: | ||
And print current URL | And print current URL | ||
=Debugging Tests= | ==Debugging Tests== | ||
Pauses the test and waits for you to manually press the enter key. | Pauses the test and waits for you to manually press the enter key. This will cause your commit to fail if you try to push it, even if it's commented out. | ||
And I insert breakpoint | And I insert breakpoint | ||
Line 556: | Line 902: | ||
And I echo the line "text" | And I echo the line "text" | ||
==Ungrouped Steps== | |||
=Ungrouped Steps= | |||
Step definition to find exceptions, debugging() messages and PHP debug messages. Not currently used in Mahara. | |||
And I look for exceptions | And I look for exceptions | ||
Line 568: | Line 910: | ||
Follows the page redirection. Use this step after any action that shows a message and waits for a redirection | Follows the page redirection. Use this step after any action that shows a message and waits for a redirection | ||
And I wait to be redirected | And I wait to be redirected | ||
This step triggers cron like a user would do going to admin/cron.php. | This step triggers cron like a user would do going to admin/cron.php. | ||
And I trigger cron | And I trigger cron | ||
And I trigger the cron | |||
<small>''E.g:<br /> | |||
When I trigger the cron <br /> | |||
''</small> |
Latest revision as of 18:33, 24 September 2020
Search for step samples
If you feel sure behat must have a way of doing something, but you can't find the step, the underlying methods are documented in the Mink documentation. It's pretty technical, but useful if you want to search out steps from the code they call, rather than the gherkin.
Browser
Use the following path to navigate to a dynamic page of the current behat steps that can be used and also all the places that they are used in:
http://<your mahara url>/testing/frameworks/behat/behat_steps_used.php
Use these steps to create Behat tests
Copy and paste the steps in the order your need into a text editor (ie gedit or vim) to create your tests.
Command line
The fastest way to write test is using parts of previous tests. In the terminal type the following command to search through all the feature files for what you are looking for:
grep --color=auto -RniP -C 3 --include *.feature '(given|when|then|and).*delete.*activity' *
Replace delete and activity with the words that you specifically need
To see the list of current tests from your Mahara directory
grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/
There are test steps provided with Behat in the MinkContext.php file and other custom steps written for Mahara. To get a list of steps and where they're used from your dev instance, go to http://mahara/testing/frameworks/behat/behat_steps_used.php
The following three lines of code will give you a text file of the current steps, but it is not so pretty:
egrep -r '@(Given|When|Then)' ~/code/mahara/external/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php > behat_steps.txt egrep -rh '@(Given|When|Then)' ~/code/mahara/htdocs/testing/frameworks/behat/classes >> behat_steps.txt perl -i -pe "s/[?\"\'\*\(\)\[\]^\\]\|\\\\]//g" behat_steps.txt
This creates a file called behat_steps.txt in your current directory which contains the list. It will confirm for you that a step exists in the code, but it is not an attempt to quantify steps specifically used in Mahara. If the step is not explicitly referenced in code, it won't be in the list. Variables in the step are indicated by P<> or :. You can ignore / and /$ at the beginnings and ends of lines.
Available steps
Backgrounds/ Way to create heaps of users, groups, institutions:
Given the following "users" exist: | username | password | email | firstname | lastname | institution | authname | role | | UserA | Kupuh1pa! | [email protected] | Angela | User | mahara | internal | member | | UserB | Kupuh1pa! | [email protected] | Bob | User | mahara | internal | member |
Given the following "groups" exist: | name | owner | description | grouptype | open | invitefriends | editroles | submittableto | allowarchives | members | staff | | GroupA | UserA | GroupA owned by UserA | standard | ON | OFF | all | ON | OFF | UserB, UserC | | | GroupB | UserA | GroupB owned by UserA | standard | ON | OFF | all | OFF | OFF | UserB, UserC | |
Given the following "institutions" exist: | name | displayname | registerallowed | registerconfirm | | instone | Institution One | ON | OFF | | insttwo | Institution Two | ON | OFF |
Create heaps of empty pages for users, groups, institutions and sites.
Given the following "pages" exist: | title | description| ownertype | ownername | | Page UserA_01 | Page 01 | user | UserA | | Page UserA_02 | Page 02 | user | UserA | | Page GroupA_01 | Group page 01 | group | GroupA | | Page GroupA_02 | Group page 02 | group | GroupA | | Page Institution_01 | Institution page 01 | institution | instone | | Page Site_01 | Site page 01 | institution | mahara |
Create different block types on a page.
And the following "blocks" exist: | title | type | page |retractable | data | | My text 1 | text | Page One | yes | This is some text | | image jpg | image | Page One | no | attachment=Image1.jpg; width=100 | | G files 2 | filedownload | Page One | auto | attachments=mahara_about.pdf,Image2.png,testvid3.mp4,mahara.mp3 | | Rss food | externalfeed | Page One | no | source=http://www.thekitchenmaid.com/feed;count=3 | | my social | socialprofile | Page One | no | sns=instagram,twitter,facebook,tumblr,pinterest,mysocialmedia | | gall style1 | gallery | Page One | no | attachments=Image1.jpg,Image3.png,Image3.png,Image2.png;imagesel=2;showdesc=yes;width=75;imagestyle=1;photoframe=1 | | myfolder | folder | Page One | no | attachments=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png,mahara.mp3;dirname=myfolder | | my html | html | Page One | yes | attachment=test_html.html | | my Journal | Journal | Page One | no | copytype=nocopy;count=5;journaltitle=journal1 | | Jrnalentry | blogpost | Group page | no | copytype=nocopy;journaltitle=journal1;entrytitle=Entry Two | | Comments | comment | Group page | | | | PeerAssessmt| peerassessment | Group page | auto | | | creativecoms| creativecommons| Group page | no | commercialuse=yes;license=3.0;allowmods=no | | my nav | navigation | Page Two | no | collection=collection one;copytoall=yes | | my plan | plans | Page Two | no | plans=Plan One,Plan Two;tasksdisplaycount=10 | | internalm | internalmedia | Page Three | no | attachment=testvid3.mp4 | | my pdf | pdf | Page Three | no | attachment=mahara_about.pdf | | recentposts |recentforumposts| Page Three | no | groupname=Group1;maxposts=3 | | nzslang | externalvideo | Page Three | no | source=https://youtu.be/yRxFm70nOrY |
Note: Steps to create a block > Find the file type you want - give it a title, which page you want it on and if it is retractable
Create heaps of collections
Given the following "collections" exist: | title | description| ownertype | ownername | pages | | Collection UserA_01 | Collection 01 | user | UserA | Page UserA_06, Page UserA_12 | | Collection UserA_02 | Collection 02 | user | UserA | Page UserA_07 | | Collection GroupA_01 | Group collection 01 | group | GroupA | Page Group_01, Page GroupA_02 |
Create permissions
And the following "permissions" exist: | title | accesstype | | Page UserA_01 | public | | Collection UserA_01 | public |
And the following "permissions" exist: | title | accesstype | accessname | allowcomments | approvecomments | | Page GroupA_01 | loggedin | loggedin | 1 | 1 |
Create journals and journal posts
And the following "journals" exist: | owner | ownertype | title | description | tags | | celeste | user | Mars journal | Recording my Mars Mission | Mars |
And the following "journalposts" exist: | owner | ownertype | title | entry | blog | tags | draft | | celeste | user | I'm going to Mars! | I just passed my exam and am approved for a Mars Mission | Mars journal | Mars | 0 | | celeste | user | Spacefood | Spacefood is kind of gross if you don't cook it right | Mars journal | Mars,food | 0 |
Logging In/Out
Log in as an existing user. The example is the default user on the testing db.
Given I log in as "username" with password "password"
E.g:
Given I log in as "admin" with password "Kupuhipa1"
Log out. This is only necessary if you need to switch users during a scenario
Given I log out
Press a key
mahara.rdaymond.wgtn.cat-it.co.nz Simulate a key press in a particular field
And I press the key "key_name" in the "node_element" field
E.g:
And I press the key "Enter" in the "Search users" field
Choose a main menu item:
Given I choose "Main menu item" from main menu Given I choose "Admin menu item" from administration menu Given I choose "User menu item" from user menu Given I choose "User menu item" from user menu by id
E.g:
And I choose "Admin home" from administration menu
"by id" means find the menu item based on an html id, for instance "mail" for "? unread" messages link to inbox:
And I choose "mail" from user menu by id
Choose a sub menu in a main menu item:
When I choose "Sub-menu item" in "Main menu item" from main menu When I choose "Sub-menu item" in "Admin menu item" from administration menu When I choose "Sub-menu item" in "User menu item" from user menu
E.g:
And I choose "Settings" in "Setting" from user menu
And I choose "Pages and collections" in "Portfolio" from main menu
Scroll within pages
NOTE: scrolling is only done using ID which is unique
Go to the top of the page
And I scroll to the top
Scroll to the top of an id tag
And I scroll to the id "id"
E.g: And I scroll to the id "createcustomlayoutpane"
Scroll to the base of an id tag
And I scroll to the base of id "id"
E.g: And I scroll to the base of id "educationhistoryform"
Scroll to the centre of an id tag
And I scroll to the center of id "id"
E.g: And I scroll to the center of id "overview-page"
Mahara pages and blocks
Open the configuration of a block
And I configure the block "Block title"
E.g:
And I configure the block "Latest changes I can view"
Delete a block
And I delete the block "Block title"
E.g:
When I delete the block "1984"
Expanding the blocks when adding content to a page
And I expand "text" node
E.g:
And I expand "General" node
Collapsing content node
And I collapse "text" node
E.g:
And I collapse "Text Block 1" node
Expanding a node in a given property/css locator
And I expand "text" node in the "property" property And I expand "text" node in the "element" "selector" //please use the property step above in preference to this.
E.g:
And I expand "External" node in the "blocktype sidebar" property
Expand a section of the page
And I expand the section "section_name"
E.g:
And I expand the section "Advanced options"
Close a named section of the page
And I unexpand the section "section_name"
Expand all fieldsets
And I expand all fieldsets
Deletes a link that points to the named item as well as the item
And I delete the link and resource menu item "link_name"
E.g:
And I delete the link and resource menu item "Test Menu Link"
Opening/Loading/Closing Pages
Checks, that current page PATH is equal to specified.
And I should be on "page path"
E.g:
And I should be on "artefact/internal/index.php"
Opens homepage.
And I go to the homepage And I am on homepage
Checks, that current page is the homepage.
And I should be on the homepage
Reloads the current page.
And I reload the page
Waits until the page is completely loaded. This step is auto-executed after every step.
And I wait until the page is ready
Take you to a specific page using the relative path:
And I am on "page" And I go to "page"
Example: When I go to "admin/site/options.php" //opens the admin settings for your site.
Opens user profile.
And I am on user profile
Go to a named portfolio page
And I go to portfolio page "name"
E.g:
Given I go to portfolio page "Page UserA_01"
Opens named Group page
And I go to group "name
E.g:
When I go to group "GroupA"
Displays the page you are currently editing
And I display the page
Go to named view
And I go to view "name"
Moves backward one page in history.
And I move backward one page
Moves forward one page in history
And I move forward one page
Go to the next page of results of the pagination
And I jump to next page of the list "named_list"
E.g:
And I jump to next page of the list "groupviews_pagination"
Go to the previous page of results
And I jump to previous page of the list "named_list"
Go to a numbered page of results
And I jump to page "num" of the list "results"
E.g:
And I jump to page "2" of the list "sharedviews_pagination"
Checks, that current page response status is equal to specified.
And the response status code should be 404
Checks, that current page response status is not equal to specified.
And the response status code should not be 404
Dialogs, frames, windows and popups
Switches to the specified iframe.
And I switch to "$iframename" iframe
Switches to the main Mahara frame.
And I switch to the main frame
Switches to the specified window. Useful when interacting with popup windows.
And I switch to “windowname” window
Switches to the main Mahara window. Useful when you finish interacting with popup windows.
And I switch to the main window
Interacting with popups (these aren't currently used in Mahara, so there are no Mahara-specific examples)
And I accept the alert popup And I accept the confirm popup And I cancel the confirm popup And I fill in "text" for popup And I should see "text" in popup
Accepts the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental.
And I accept the currently displayed dialog
Close the currently displayed dialog
And I close the dialog
Close the currently open config dialog
And I close the config dialog
Click on a particular element in the currently displayed dialog
And I click on "text_element" in the dialog
And I click on "Page" in the dialog
Press a button and confirm action in one step
And I press and confirm "button_text"
E.g
And I press and confirm "Delete user"
Actions Requiring Waiting
Waits until the page is ready
And I wait until the page is ready
Waits X seconds. Required after an action that requires data from an AJAX request. Don't use this unless the test really needs it - i.e. keeps failing.
And I wait "$numberofseconds" seconds
E.g:
And I wait "1" seconds
Waits until the provided element selector exists in the DOM
And I wait until "$element" "$selector" exists
Waits until the provided element does not exist in the DOM
And I wait until "element_string" "selector_string" does not exist
Click Actions
There are several options for clicking an element in a page. The key difference is in the html tags it has. The first two built in steps 'I press' and 'I follow' take slightly different html tags.
Clicks link with specified id|title|alt|text.
And I follow "id|title|alt|text"
E.g.
And I follow "Lost username / password"
Presses button with specified id|name|title|alt|value.
And I press "id|name|title|alt|value"
E.g:
And I press "Save"
Click on is a mahara specific step intended for a link or button. The tags it targets are not documented.
And I click on "element"
E.g:
And I click on "Help"
Click on an element in a dialog box
And I click on "element" in the dialog
E.g:
And I click on "Page" in the dialog
Panel Menu steps
Panel menus in Mahara are the boxes that display page/collection titles and edit/delete icons on the Pages and collections page. We have some specific steps to target them.
Click on the page/collection title
And I click the panel "text string" And I click on "text string" panel menu And I click on "text string" panel collection
E.g:
And I click the panel "Page UserA_01"
And I click on "Page UserA_01" panel menu
And I click on "Collection UserA_01" panel collection
Click on a specific collection page
And I click on "page_name" in "collection_name" panel collection
E.g:
And I click on "Page UserA_01" in "Collection UserA_01" panel collection
Click the panel's edit, delete or access options
And I click on "Edit/Manage/Delete" in "page_name" panel menu
E.g:
And I click on "Edit" in "Page UserA_01" panel menu
Clicking with locators
If the element you want to click doesn't have an obvious tag, you may need to specify a css or xpath element to be able to click it. As these are not as user-friendly to read, we now have a properties file in mahara (/htdocs/testing/frameworks/behat/classes/properties.php) which converts the css or xpath element to a name which is more human-readable. Use the following property steps in preference to any that directly use a css or xpath element. If you need to target an element not included in the properties file, that element should be added to the properties file.
And I press "search text" in the "property name" property And I follow "search text" in the "property name" property And I click on "search text" in the "property name" property
E.g.
And I press "Close" in the "Upload dialog" property
And I follow "Note" in the "blocktype sidebar" property
And I click on "Settings" in the "Toolbar buttons" property
These steps replace the following steps, which should no longer be used:
And I press "button" in the "$element" "$selector" And I follow "link" in the "$element" "$selector" And I click on "link or button" in the "$element" "$selector"
There are a couple(?) of steps which take a css/xpath locator that haven't been replaced by a properties step. They are not currently used in any Mahara tests, but are included for completeness:
Generic mouse over action. Mouse over a element of the specified type.
And I hover "$element" "$selector"
Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental.
And I drag "$element" "$selector" and I drop in "$containerelement" ”$selector"
Clicking on table elements
Click on the row containing a text string
And I click the row "text_string"
Click on the link or button inside a list/table row containing the specified text.
And I click on "link or button" in "row_text_string" row
E.g:
And I click on "Edit access" in "Page GroupA_01" row
Click on the delete button inside a list/table row containing the specified text.
And I delete the "text string" row
E.g:
Given I delete the "Public comment by anonymous user" row
Click on the specified element inside a table row containing the specified text.
And I click on "$element" "$selector" in the table row
E.g:
And I click on "hidden-user-search-[0]" "css_element" in the table row
Click a Smartevidence matrix point
And I click the matrix point "num,num"
E.g:
And I click on the matrix point "3,4"
Filling in Forms
Attaches file to field with specified id|name|label|value
And I attach the file "File name" to "Field"
E.g:
And I attach the file "groupmembers.csv" to "CSV file"
Checkboxes and Radio buttons
Checks checkbox with specified id|name|label|value.
And I check "option"
E.g:
And I check "Facebook (Social media)"
Unchecks checkbox with specified id|name|label|value.
And I uncheck "option"
Checks that checkbox with specified in|name|label|value is checked.
And the "checkbox" checkbox should be checked And the checkbox "checkbox" is|should be checked
E.g:
And the "edit_interaction_autosubscribe" checkbox should be checked
Checks that checkbox with specified in|name|label|value is unchecked.
And the "checkbox" checkbox should not be checked And the checkbox "checkbox" should be unchecked|not be checked And the checkbox "checkbox" is unchecked|not checked
E.g:
And the "Friend invitations" checkbox should not be checked
And the checkbox "test page name 1" should be unchecked
Selects a radio button
And I select the radio "field_label"
E.g:
And I select the radio "Note block 1"
Checking fields for values
Checks that form field with specified id|name|label|value has specified value.
And the "field" field should contain "value"
E.g.
And the "Occupation" field should contain "Hairdresser"
Checks that form field with specified id|name|label|value doesn't have specified value.
And the "field" field should not contain "value"
E.g.
And the "System message" field should not contain "None"
Checks the field matches the value.
And the field "field_string" matches value "field_value_string"
E.g.
And the field "Institution administrator" matches value "1"
Checks the field does not match the value.
And the field "field_string" does not match value "field_value_string"
Checks multiple field/value pairs match
And the following fields match these values:
E.g.
And the following fields match these values: | Page title | Page GroupA_01 |
Checks that the provided field/value pairs don't match.
And the following fields do not match these values:
Entering Text
Fills in a form field with specified text
And I fill in "Field" with "Text" And I set the field "Field" to "Text" And I fill in "Text" for "Field"
E.g:
And I fill in "Title" with "Site blog"
And I set the field "Post" to "Hello"
And I fill in "Would you like to be my friend?" for "Message"
Fills in multiple form fields with field/value data.
And I set the following fields to these values: | Field name | Field value | And I fill in the following: | Field name | Field value |
E.g:
And I fill in the following:
- | firstname | Jen |
- | lastname | Jenny |
- | email | [email protected] |
- | username | jen |
- | password | mahara1 |
And I set the following fields to these values:
- | addeducationhistory_startdate | 1 Jan 2017 |
- | addeducationhistory_institution | Mail-order PhD |
- | addeducationhistory_institutionaddress | 45 Empty St |
These core behat steps attempt to manage account settings, but are not currently used in Mahara and may not work. TODO: See what they do.
And I set the following account settings values "?" And the following site settings are set "?" And the following plugin settings are set "?"
Steps allowing relative dates
It is annoying to write a test to test something in future which then becomes obsolete when that date passes. These steps allow you to use relative dates. They are a bit more complicated to use than some of the other steps, but will make your life much easier when dealing with dates in tests. The "format" option can either be given in as a Mahara specific format defined in htdocs/lang/en.utf8/langconfig.php or as a format the PHP date function understands: http://php.net/manual/en/function.date.php. The "date" option allows "today", "yesterday" and similar English words for relative dates, as accepted by the PHP strtotime function: http://php.net/manual/en/datetime.formats.relative.php
Fill in a relative date
And I fill in :element with :date date in the format :format
E.g:
And I fill in "Completion date" with "+6 months" date in the format "Y/m/d"
Check for a relative date
And I should see the date "date" in the "element" element with the format "format"
E.g:
And I should see the date "today" in the "#sharedcollectionlist" element with the format "d F Y"
Using select boxes and select2 boxes
Checks that given select box contains the specified option.
And the "select_string" select box should contain "option_string"
E.g:
Then the "accesslist[0][searchtype]" select box should contain "Institution One"
Checks that given select box contains the specified option.
And the "select_string" select box should not contain "option_string"
E.g:
And the "accesslist[0][searchtype]" select box should not contain "Institution Two"
Checks that the select box contains a list of elements
And the "select_string" select box should contain all "list_of_options"
E.g:
And the "Activity type:" select box should contain all "Administration messages | Comment | Contact us | Feedback on annotations | Group message | Institution message | Message from other users | New forum post | New page access | Objectionable content | Objectionable content in forum | Repeat virus upload | System message | Virus flag release | Watchlist"
Selects option in select field with specified id|name|label|value.
And I select "option" from "select"
E.g:
And I select "Email digest" from "Objectionable content"
Selects additional option in select field with specified id|name|label|value.
And I additionally select "option" from "select"
Set a specified select2 field to a given value
And I set the select2 field "field_name" to "text" And I set the select2 value "text" for "field_name"
E.g:
And I set the select2 value "Institution One" for "reportconfigform_institution"
Add a value to a select2 field
And I fill in select2 input "field_name" with "text"
Clear a select2 value
And I clear value "text" from select2 field "field_name"
E.g:
And I clear value "one" from select2 field "instconf_tagselect"
Enter a value to a select2 field and select it in one step
And I fill in select2 input "field_name" with "text" and select "entry"
E.g:
And I fill in select2 input "sendmessage_recipients" with "UserA" and select "Angela User (UserA)"
Switches
Enable a switch
And I enable the switch "field_label"
E.g
And I enable the switch "Make comment public"
Disable a switch
And I disable the switch "field_label"
E.g
And I disable the switch "Open"
Enable a switch in a row identified by id it contains
And I enable the switch in "id" row
E.g
And I enable the switch in "mahara_group_get_groups_by_id" row
Enable several switches in one step
And I enable the following switches:
Disable several switches in one step
And I disable the following switches:
TinyMCE Editor - e.g. the "Comments" text box
Our WYSIWYG rich text editor, TinyMCE, behaves a bit strangely, so it requires its own special behat step to fill in a TinyMCE rich text field. You must identify the editor by the label of the text box. The label may not be visible on the page. Inspect the text box element and search for label and you should find it. As an example, the comments text box label looks like this in the page source: <label for="add_feedback_form_message">Comment</label>
Enter text in a TinyMCE box identified by label
And I fill in "text" in editor "editor_label"
E.g. And I fill in "Comment by page owner" in editor "Comment"
Or you can leave out the iframe name, and Behat will find and use the first TinyMCE editor on the page. (This is useful when the TinyMCE editor's ID is assigned dynamically.)
And I fill in "text" in first editor
Click a button in the TinyMCE editor
And I click the "hover_over_text" button in the editor
E.g. And I click the "Insert/edit image" button in the editor
Webservices
Fill the wstoken text in field. This step finds the relevant token and fills in the field.
And I fill in the wstoken for "service" owned by "user"
E.g:
And I fill in the wstoken for "Test service" owned by "Service Admin"
Checking For Specific Visible Elements
Checks that page contains specified text. It also checks if the text is visible when running Javascript tests.
And I should see "$text"
E.g:
Then I should see "Latest changes I can view"
Checks that page doesn't contain specified text. When running Javascript tests it also considers that texts may be hidden.
And I should not see "$text"
E.g:
And I should not see "Here is a new block"
Checks that page contains text matching the specified regex pattern - useful when checking dynamic content.
And I should see text matching "pattern"
Checks that page doesn't contain text matching the specified regex pattern.
And I should not see text matching "pattern"
Checks that HTML response contains specified string.
And the response should contain "text"
Checks that HTML response doesn't contain specified string.
And the response should not contain "text"
Checks that field with specified identifier exists on page.
And I should see the field "field_label"
Make sure the field label is not visible
And I should not see the field "field_label"
Checks that current page PATH matches regular expression.
And the url should match "pattern"
Checking for elements within blocks
Check whether images exist in a block
And I should see images within the block "blocktitle"
E.g:
And I should see images within the block "Some HTML"
Make sure images don't exist in a block
And I should not see images within the block "blocktitle"
E.g:
And I should not see images within the block "Text block with an external image"
Find text within a block
And I should see "text" in the block "blocktitle"
E.g:
And I should see "This is a test" in the block "Note block 2"
Make sure text is not in a block
And I should not see "text" in the block "blocktitle"
Steps that check for elements by CSS locator
Since we have a properties file for CSS elements, the properties steps should be used in preference than those that pass the locators in directly. If you can't get the available property steps to do what you need, we should probably write additional steps using that functionality.
Checks that an element can be seen in a specified property
And I should see "text" in the "name" property
E.g:
And I should see "(2 pages)" in the "My portfolios" property
Checks that an element is not seen in a specified property
And I should not see "text" in the "name" property
E.g:
Then I should not see "Page UserA_01" in the "My portfolios" property
Checks that the specified element is visible. Only available in tests using Javascript.
And "$elements" "$selector" should be visible
Checks that the specified element is not visible. Only available in tests using Javascript.
And "$element" "$selector" should not be visible
Checks that the specified element is visible inside the specified container. Only available in tests using Javascript.
And "$element" "$selector" in the "$elementcontainer" "$selector" should be visible
Checks that the specified element is not visible inside the specified container. Only available in tests using Javascript.
And "$element" "$selector" in the "$elementcontainer" "$textselector" should not be visible
Checks that the specified element contains the specified text. When running Javascript tests it also considers that texts may be hidden.
And I should see "$text" in the "$element" “$sector”
Checks that the specified element does not contain the specified text. When running Javascript tests it also considers that texts may be hidden.
And I should not see "$text" in the “$element" "$selector”
Checks that the first specified element appears before the second one.
And "$element" "$selector" should appear before "$element" "$selector"
Checks that the first specified element appears after the second one.
And "$element" "selector" should appear after $"element" $"selector"
Checks that the first specified element appears after the second one.
And "following_element_string" "selector1_string" should appear after "preceding_element_string" "selector2_string"
Checks that element of specified type is disabled.
And the "$element" "$selector" should be disabled
Checks that element of specified type is enabled.
And the "$element" "$selector" should be enabled
Checks the provided element and selector type are readonly on the current page.
And the "$element" "$selector" should be readonly
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.
And "$element" "$selector" should exists
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.
And "$element" "$selector" should not exists
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.
And "$element" "$selector" should exist in the "$element" "$selector"
Checks that element with specified CSS contains specified text.
And I should see "text" in the "element" element
E.g:
And I should see "Text block 1" in the "div#column-container" element
Checks that element with specified CSS doesn't contain specified text.
And I should not see "text" in the "element" element
E.g:
And I should not see "Page UserA_01" in the ".bt-newviews" element
Checks that element with specified CSS contains specified HTML.
And the "element" element should contain "value"
E.g:
Then the "div#logo-area" element should contain "/theme/modern/images/site-logo"
Checks that element with specified CSS doesn't contain specified HTML.
And the "element" element should not contain "value"
Checks that element with specified CSS exists on page.
And I should see an "element" element
Checks that element with specified CSS doesn't exist on page.
And I should not see an "element" element
Checks that (?P<num>\d+) CSS elements exist on the page
And I should see (?P<num>\d+) "element" elements
Checks that the specified element is visible. Only available in tests using Javascript.
And I should see the element "element" "selectortype"
Printing/Display
Opens last response content in browser.
And show last response
Prints last response to console.
And print last response
Prints current URL to console.
And print current URL
Debugging Tests
Pauses the test and waits for you to manually press the enter key. This will cause your commit to fail if you try to push it, even if it's commented out.
And I insert breakpoint
Prints a line of your choosing to the console so you can confirm the test is reaching that point
And I echo the line "text"
Ungrouped Steps
Step definition to find exceptions, debugging() messages and PHP debug messages. Not currently used in Mahara.
And I look for exceptions
Follows the page redirection. Use this step after any action that shows a message and waits for a redirection
And I wait to be redirected
This step triggers cron like a user would do going to admin/cron.php.
And I trigger cron And I trigger the cron
E.g:
When I trigger the cron