BasicContext
class BasicContext implements Context (View source)
BasicContext
Context used to define generic steps like following anchors or pressing buttons. Handles timeouts. Handles redirections. Handles AJAX enabled links, buttons and forms - jQuery is assumed.
Traits
Represents a behat context which is aware of a main {SilverStripeContext} context.
Helpers for working with steps
Properties
protected | SilverStripeContext | $mainContext | from MainContextAwareTrait | |
protected | string | $dateFormat | Date format in date() syntax |
|
protected | string | $timeFormat | Time format in date() syntax |
|
protected | string | $datetimeFormat | Date/time format in date() syntax |
Methods
Get scenario from step in a feature node See https://github.com/Behat/Behat/issues/653
Retry until no exceptions are thrown, or until $timeout seconds are reached.
Check if a step has a given tag
Hook into jQuery ajaxStart, ajaxSuccess and ajaxComplete events.
Wait for the __ajaxStatus()to return anything but 'waiting'.
Close modal dialog if test scenario fails on CMS page
Delete any created files and folders from assets directory
Example: I should see a "Submit" button Example: I should not see a "Delete" button
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Select an individual input from within a group, matched by the top-most label.
Pauses the scenario until the user presses a key. Useful when debugging a scenario.
Transforms relative time statements compatible with strtotime().
Transforms relative date and time statements compatible with strtotime().
Transforms relative date statements compatible with strtotime().
Checks that field with specified in|name|label|value is disabled.
Checks that checkbox with specified in|name|label|value is enabled.
Clicks a link in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).
Fills in a field in a specfic region similar to (iFollowInTheRegion or iSeeTextInRegion)
Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).
Finds the first visible table by various factors:
- table[id]
- table[title]
- table *[class=title]
- fieldset[data-name] table
- table caption
Checks the order of two texts.
Wait until a certain amount of seconds till I see an element identified by a CSS selector.
Wait until a particular element is visible, using a CSS selector. Useful for content loaded via AJAX, or only populated after JS execution.
Wait until a particular string is found on the page. Useful for content loaded via AJAX, or only populated after JS execution.
Continuously poll the dom until callback returns true, code copied from (@link http://docs.behat.org/cookbook/using_spin_functions.html) If not found within a given wait period, timeout and throw error
We have to catch exceptions and log somehow else otherwise behat falls over
Details
SilverStripeContext
getMainContext()
Get the main context
$this
setMainContext(SilverStripeContext $mainContext)
No description
detectMainContext(BeforeScenarioScope $scope)
Helper method to detect the main context
protected ScenarioInterface
getStepScenario(FeatureNode $feature, NodeInterface $step)
Get scenario from step in a feature node See https://github.com/Behat/Behat/issues/653
protected mixed
retryThrowable(callable $callback, int $timeout = 3)
Retry until no exceptions are thrown, or until $timeout seconds are reached.
If timeout reached, re-throws the first exception.
protected bool
stepHasTag(StepScope $event, string $tag)
Check if a step has a given tag
Session
getSession(string $name = null)
Get Mink session from MinkContext
appendErrorHandlerBeforeStep(AfterStepScope $event)
No description
readErrorHandlerAfterStep(AfterStepScope $event)
No description
handleAjaxBeforeStep(BeforeStepScope $event)
Hook into jQuery ajaxStart, ajaxSuccess and ajaxComplete events.
Prepare __ajaxStatus() functions and attach them to these handlers. Event handlers are removed after one run.
handleAjaxAfterStep(AfterStepScope $event)
Wait for the __ajaxStatus()to return anything but 'waiting'.
Don't wait longer than 5 seconds.
Don't unregister handler if we're dealing with modal windows
handleAjaxTimeout()
No description
takeScreenshotAfterFailedStep(AfterStepScope $event)
Take screenshot when step fails.
Works only with Selenium2Driver.
closeModalDialog(AfterScenarioScope $event)
Close modal dialog if test scenario fails on CMS page
cleanAssetsAfterScenario(AfterScenarioScope $event)
Delete any created files and folders from assets directory
takeScreenshot(StepScope $event)
Take a nice screenshot
stepPageCantBeFound()
No description
stepIWaitFor(float $secs)
No description
protected NodeElement|null
findNamedButton(string $title)
Find visible button with the given text.
Supports data-text-alternate property.
iShouldSeeAButton(string $negative, string $text)
Example: I should see a "Submit" button Example: I should not see a "Delete" button
stepIPressTheButton(string $text)
No description
stepIPressTheButtonConfirmingTheDialog(string $button)
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Example1: I press the "Remove current combo" button, confirming the dialog Example2: I follow the "Remove current combo" link, confirming the dialog
stepIPressTheButtonDismissingTheDialog(string $button)
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Example: I follow the "Remove current combo" link, dismissing the dialog
iClickInTheElement(string $clickType, string $text, string $selector)
No description
iClickInTheElementConfirmingTheDialog(string $clickType, string $text, string $selector)
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Example: I click "Delete" in the ".actions" element, confirming the dialog
iClickInTheElementDismissingTheDialog(string $clickType, string $text, string $selector)
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
Example: I click "Delete" in the ".actions" element, dismissing the dialog
iSeeTheDialogText(string $expected)
No description
iTypeIntoTheDialog(string $data)
No description
iConfirmTheDialog()
No description
iDismissTheDialog()
No description
protected Session
getWebDriverSession()
Get Selenium webdriver session.
Note: Will fail if current driver isn't Selenium2Driver
Given
iAttachTheFileTo(string $field, string $path)
No description
iSelectFromInputGroup(string $value, string $labelText)
Select an individual input from within a group, matched by the top-most label.
iPutABreakpoint()
Pauses the scenario until the user presses a key. Useful when debugging a scenario.
false|string
castRelativeToAbsoluteTime(string $prefix, string $val)
Transforms relative time statements compatible with strtotime().
Example: "time of 1 hour ago" might return "22:00:00" if its currently "23:00:00". Customize through setTimeFormat().
false|string
castRelativeToAbsoluteDatetime(string $prefix, string $val)
Transforms relative date and time statements compatible with strtotime().
Example: "datetime of 2 days ago" might return "2013-10-10 22:00:00" if its currently the 12th of October 2013. Customize through setDatetimeFormat().
false|string
castRelativeToAbsoluteDate(string $prefix, string $val)
Transforms relative date statements compatible with strtotime().
Example: "date 2 days ago" might return "2013-10-10" if its currently the 12th of October 2013. Customize through setDateFormat().
getDateFormat()
No description
setDateFormat($format)
No description
getTimeFormat()
No description
setTimeFormat($format)
No description
getDatetimeFormat()
No description
setDatetimeFormat($format)
No description
stepFieldShouldBeDisabled(string $name, string $type, string $negate)
Checks that field with specified in|name|label|value is disabled.
Example: Then the field "Email" should be disabled Example: Then the "Email" field should be disabled
stepFieldShouldBeEnabled(string $field)
Checks that checkbox with specified in|name|label|value is enabled.
Example: Then the field "Email" should be enabled Example: Then the "Email" field should be enabled
iFollowInTheRegion(string $link, string $region)
Clicks a link in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).
Example: Given I follow "Select" in the "header .login-form" region Example: Given I follow "Select" in the "My Login Form" region
iFillinTheRegion(string $field, string $value, string $region)
Fills in a field in a specfic region similar to (iFollowInTheRegion or iSeeTextInRegion)
Example: Given I fill in "Hello" with "World"
iSeeTextInRegion(string $negate, string $text, string $region)
Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).
Supports regular expressions in text value.
Example: Given I should see "My Text" in the "header .login-form" region Example: Given I should not see "My Text" in the "My Login Form" region
iSelectTheRadioButton(string $radioLabel)
Selects the specified radio button
theTableShouldContain(string $selector, string $text)
No description
theTableShouldNotContain(string $selector, string $text)
No description
iClickOnInTheTable(string $text, string $selector)
No description
protected NodeElement
getTable(string $selector)
Finds the first visible table by various factors:
- table[id]
- table[title]
- table *[class=title]
- fieldset[data-name] table
- table caption
theTextBeforeAfter(string $textBefore, string $order, string $textAfter, string $element)
Checks the order of two texts.
Assumptions: the two texts appear in their conjunct parent element once
iWaitXUntilISee(int $wait, string $selector)
Wait until a certain amount of seconds till I see an element identified by a CSS selector.
Example: Given I wait for 10 seconds until I see the ".css_element" element
iWaitUntilISee(string $selector)
Wait until a particular element is visible, using a CSS selector. Useful for content loaded via AJAX, or only populated after JS execution.
Example: Given I wait until I see the "header .login-form" element
iWaitUntilISeeText(string $text)
Wait until a particular string is found on the page. Useful for content loaded via AJAX, or only populated after JS execution.
Example: Given I wait until I see the text "Welcome back, John!"
iScrollToBottom()
No description
iScrollToTop()
No description
iScrollToField(string $locator, string $type)
Scroll to a certain element by label.
Requires an "id" attribute to uniquely identify the element in the document.
Example: Given I scroll to the "Submit" button Example: Given I scroll to the "My Date" field
iScrollToElement(string $locator)
Scroll to a certain element by CSS selector.
Requires an "id" attribute to uniquely identify the element in the document.
Example: Given I scroll to the ".css_element" element
bool
spin(callable $lambda, int $wait = 60)
Continuously poll the dom until callback returns true, code copied from (@link http://docs.behat.org/cookbook/using_spin_functions.html) If not found within a given wait period, timeout and throw error
protected
logException(Exception $exception)
We have to catch exceptions and log somehow else otherwise behat falls over