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
Step tools to help debug failing 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 |
|
protected | FixtureContext | $fixtureContext |
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
Ensure utilty steps are reset for subsequent scenarios
Useful step for working out why a behat testing isn't working when running the browser headless Remove this step from in a feature file once the test is working correct
Utility function for debugging failing behat tests Remove this step from in a feature file once the test is working correct
Take a screenshot when step fails, or take a screenshot after every step if the use has specified "I take a screenshot after every step" Works only with FacebookWebDriver.
Dump rendered HTML to disk Useful for seeing the state of a page when writing and debugging feature files
Get the fixture context of the current module
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.
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
Detect element with javascript, rather than having the selector converted to xpath There's already an xpath based function 'I see the "" element' iSeeTheElement() in silverstripe/cms There's also an 'I should see "" element' in MinkContext which also converts the css selector to xpath
Selects the option in select field with specified id|name|label|value Also accepts CSS selectors
Add tag values to the react TagField component which uses react-select
This doesn't seem to work quite right in practice iDragTheElementToTheElement is much more reliable
Use this to follow hyperlinks with target="_blank" Behat won't switch to the new tab Also allows use of css selectors
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|ScenarioScope $event, string $tag)
Check if a step has a given tag
void
resetUtilitiesAfterStep(AfterScenarioScope $event)
Ensure utilty steps are reset for subsequent scenarios
iTakeAScreenshotAfterEveryStep()
Useful step for working out why a behat testing isn't working when running the browser headless Remove this step from in a feature file once the test is working correct
iDumpTheRenderedHtmlAfterEveryStep()
Utility function for debugging failing behat tests Remove this step from in a feature file once the test is working correct
takeScreenshotAfterFailedStep(AfterStepScope $event)
Take a screenshot when step fails, or take a screenshot after every step if the use has specified "I take a screenshot after every step" Works only with FacebookWebDriver.
void
dumpHtmlAfterStep(AfterStepScope $event)
Dump HTML when step fails.
dumpRenderedHtml(StepScope $event)
Dump rendered HTML to disk Useful for seeing the state of a page when writing and debugging feature files
takeScreenshot(StepScope $event)
Take a nice screenshot
void
gatherContexts(BeforeScenarioScope $scope)
Get the fixture context of the current module
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
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
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
stepIPressTheButtons(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
iClickOnTheElement(string $selector)
No description
iClickOnTheElementConfirmingTheDialog($selector)
Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
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
theElementAttributeShouldBe($selector, $attribute, $value)
No description
iSeeTheDialogText(string $expected)
No description
iTypeIntoTheDialog(string $data)
No description
protected WebDriverAlert
getExpectedAlert()
Wait for alert to appear, and return handle
iConfirmTheDialog()
No description
iDismissTheDialog()
No description
protected WebDriver
getWebDriverSession()
Get Selenium webdriver session.
Note: Will fail if current driver isn't FacebookWebDriver
Given
iAttachTheFileTo(string $field, string $path)
deprecated
deprecated
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
logMessage(string $message)
Log a message
protected
logException(Exception $exception)
We have to catch exceptions and log somehow else otherwise behat falls over
iShouldSeeTheElement($not, $cssSelector = '')
Detect element with javascript, rather than having the selector converted to xpath There's already an xpath based function 'I see the "" element' iSeeTheElement() in silverstripe/cms There's also an 'I should see "" element' in MinkContext which also converts the css selector to xpath
iSelectFromTheField(string $value, string $locator, string $withJavascript)
Selects the option in select field with specified id|name|label|value Also accepts CSS selectors
theRenderedHtmlShouldContain(string $not, string $htmlFragment)
No description
iAddToTheTagField(string $value, string $locator)
Add tag values to the react TagField component which uses react-select
theFieldShouldHaveTheValue(string $locator, string $value)
No description
iDragTheElementToTheElement(string $locatorA, string $locatorB)
No description
iDragTheElementBy(string $locatorA, string $xOffset, string $yOffset)
This doesn't seem to work quite right in practice iDragTheElementToTheElement is much more reliable
iPressTheKeyGlobally(string $keyCombo)
Globally press the key i.e. not type into an input
iAttachTheFileToTheField($filename, $locator)
Use upload fields
iFollowWithJavascript(string $locator)
Use this to follow hyperlinks with target="_blank" Behat won't switch to the new tab Also allows use of css selectors