mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
API Support extended JS error reporting
This commit is contained in:
parent
bf36edecad
commit
bc3b0b4cd5
@ -76,9 +76,13 @@ class BasicContext extends BehatContext
|
|||||||
public function appendErrorHandlerBeforeStep(StepEvent $event)
|
public function appendErrorHandlerBeforeStep(StepEvent $event)
|
||||||
{
|
{
|
||||||
$javascript = <<<JS
|
$javascript = <<<JS
|
||||||
window.onerror = function(msg) {
|
window.onerror = function(message, file, line, column, error) {
|
||||||
var body = document.getElementsByTagName('body')[0];
|
var body = document.getElementsByTagName('body')[0];
|
||||||
body.setAttribute('data-jserrors', '[captured JavaScript error] ' + msg);
|
var msg = message + " in " + file + ":" + line + ":" + column;
|
||||||
|
if(error !== undefined && error.stack !== undefined) {
|
||||||
|
msg += "\\nSTACKTRACE:\\n" + error.stack;
|
||||||
|
}
|
||||||
|
body.setAttribute('data-jserrors', '[captured JavaScript error] ' + msg);
|
||||||
}
|
}
|
||||||
if ('undefined' !== typeof window.jQuery) {
|
if ('undefined' !== typeof window.jQuery) {
|
||||||
window.jQuery('body').ajaxError(function(event, jqxhr, settings, exception) {
|
window.jQuery('body').ajaxError(function(event, jqxhr, settings, exception) {
|
||||||
@ -217,7 +221,7 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete any created files and folders from assets directory
|
* Delete any created files and folders from assets directory
|
||||||
*
|
*
|
||||||
* @AfterScenario @assets
|
* @AfterScenario @assets
|
||||||
*/
|
*/
|
||||||
public function cleanAssetsAfterScenario(ScenarioEvent $event)
|
public function cleanAssetsAfterScenario(ScenarioEvent $event)
|
||||||
@ -244,7 +248,7 @@ JS;
|
|||||||
|
|
||||||
\Filesystem::makeFolder($path);
|
\Filesystem::makeFolder($path);
|
||||||
$path = realpath($path);
|
$path = realpath($path);
|
||||||
|
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
file_put_contents('php://stderr', sprintf('"%s" is not valid directory and failed to create it' . PHP_EOL, $path));
|
file_put_contents('php://stderr', sprintf('"%s" is not valid directory and failed to create it' . PHP_EOL, $path));
|
||||||
return;
|
return;
|
||||||
@ -284,7 +288,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^the page can't be found/
|
* @Given /^the page can't be found/
|
||||||
*/
|
*/
|
||||||
public function stepPageCantBeFound()
|
public function stepPageCantBeFound()
|
||||||
{
|
{
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
assertTrue(
|
assertTrue(
|
||||||
@ -320,9 +324,9 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
* Example1: I press the "Remove current combo" button, confirming the dialog
|
* Example1: I press the "Remove current combo" button, confirming the dialog
|
||||||
* Example2: I follow the "Remove current combo" link, confirming the dialog
|
* Example2: I follow the "Remove current combo" link, confirming the dialog
|
||||||
*
|
*
|
||||||
* @Given /^I (?:press|follow) the "([^"]*)" (?:button|link), confirming the dialog$/
|
* @Given /^I (?:press|follow) the "([^"]*)" (?:button|link), confirming the dialog$/
|
||||||
*/
|
*/
|
||||||
public function stepIPressTheButtonConfirmingTheDialog($button)
|
public function stepIPressTheButtonConfirmingTheDialog($button)
|
||||||
@ -334,7 +338,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
* Example: I follow the "Remove current combo" link, dismissing the dialog
|
* Example: I follow the "Remove current combo" link, dismissing the dialog
|
||||||
*
|
*
|
||||||
* @Given /^I (?:press|follow) the "([^"]*)" (?:button|link), dismissing the dialog$/
|
* @Given /^I (?:press|follow) the "([^"]*)" (?:button|link), dismissing the dialog$/
|
||||||
*/
|
*/
|
||||||
public function stepIPressTheButtonDismissingTheDialog($button)
|
public function stepIPressTheButtonDismissingTheDialog($button)
|
||||||
@ -454,7 +458,7 @@ JS;
|
|||||||
* Transforms relative time statements compatible with strtotime().
|
* Transforms relative time statements compatible with strtotime().
|
||||||
* Example: "time of 1 hour ago" might return "22:00:00" if its currently "23:00:00".
|
* Example: "time of 1 hour ago" might return "22:00:00" if its currently "23:00:00".
|
||||||
* Customize through {@link setTimeFormat()}.
|
* Customize through {@link setTimeFormat()}.
|
||||||
*
|
*
|
||||||
* @Transform /^(?:(the|a)) time of (?<val>.*)$/
|
* @Transform /^(?:(the|a)) time of (?<val>.*)$/
|
||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteTime($prefix, $val) {
|
public function castRelativeToAbsoluteTime($prefix, $val) {
|
||||||
@ -470,9 +474,9 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms relative date and time statements compatible with strtotime().
|
* 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
|
* Example: "datetime of 2 days ago" might return "2013-10-10 22:00:00" if its currently
|
||||||
* the 12th of October 2013. Customize through {@link setDatetimeFormat()}.
|
* the 12th of October 2013. Customize through {@link setDatetimeFormat()}.
|
||||||
*
|
*
|
||||||
* @Transform /^(?:(the|a)) datetime of (?<val>.*)$/
|
* @Transform /^(?:(the|a)) datetime of (?<val>.*)$/
|
||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteDatetime($prefix, $val) {
|
public function castRelativeToAbsoluteDatetime($prefix, $val) {
|
||||||
@ -488,9 +492,9 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms relative date statements compatible with strtotime().
|
* Transforms relative date statements compatible with strtotime().
|
||||||
* Example: "date 2 days ago" might return "2013-10-10" if its currently
|
* Example: "date 2 days ago" might return "2013-10-10" if its currently
|
||||||
* the 12th of October 2013. Customize through {@link setDateFormat()}.
|
* the 12th of October 2013. Customize through {@link setDateFormat()}.
|
||||||
*
|
*
|
||||||
* @Transform /^(?:(the|a)) date of (?<val>.*)$/
|
* @Transform /^(?:(the|a)) date of (?<val>.*)$/
|
||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteDate($prefix, $val) {
|
public function castRelativeToAbsoluteDate($prefix, $val) {
|
||||||
@ -539,13 +543,13 @@ JS;
|
|||||||
public function stepFieldShouldBeDisabled($name, $type, $negate) {
|
public function stepFieldShouldBeDisabled($name, $type, $negate) {
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
if($type == 'field') {
|
if($type == 'field') {
|
||||||
$element = $page->findField($name);
|
$element = $page->findField($name);
|
||||||
} else {
|
} else {
|
||||||
$element = $page->find('named', array(
|
$element = $page->find('named', array(
|
||||||
'button', $this->getSession()->getSelectorsHandler()->xpathLiteral($name)
|
'button', $this->getSession()->getSelectorsHandler()->xpathLiteral($name)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNotNull($element, sprintf("Element '%s' not found", $name));
|
assertNotNull($element, sprintf("Element '%s' not found", $name));
|
||||||
|
|
||||||
$disabledAttribute = $element->getAttribute('disabled');
|
$disabledAttribute = $element->getAttribute('disabled');
|
||||||
@ -577,27 +581,27 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* Clicks a link in a specific region (an element identified by a CSS selector, a "data-title" attribute,
|
* 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).
|
* 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 "header .login-form" region
|
||||||
* Example: Given I follow "Select" in the "My Login Form" region
|
* Example: Given I follow "Select" in the "My Login Form" region
|
||||||
*
|
*
|
||||||
* @Given /^I (?:follow|click) "(?P<link>[^"]*)" in the "(?P<region>[^"]*)" region$/
|
* @Given /^I (?:follow|click) "(?P<link>[^"]*)" in the "(?P<region>[^"]*)" region$/
|
||||||
*/
|
*/
|
||||||
public function iFollowInTheRegion($link, $region) {
|
public function iFollowInTheRegion($link, $region) {
|
||||||
$context = $this->getMainContext();
|
$context = $this->getMainContext();
|
||||||
$regionObj = $context->getRegionObj($region);
|
$regionObj = $context->getRegionObj($region);
|
||||||
assertNotNull($regionObj);
|
assertNotNull($regionObj);
|
||||||
|
|
||||||
$linkObj = $regionObj->findLink($link);
|
$linkObj = $regionObj->findLink($link);
|
||||||
if (empty($linkObj)) {
|
if (empty($linkObj)) {
|
||||||
throw new \Exception(sprintf('The link "%s" was not found in the region "%s" on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
|
throw new \Exception(sprintf('The link "%s" was not found in the region "%s" on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$linkObj->click();
|
$linkObj->click();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills in a field in a specfic region similar to (@see iFollowInTheRegion or @see iSeeTextInRegion)
|
* Fills in a field in a specfic region similar to (@see iFollowInTheRegion or @see iSeeTextInRegion)
|
||||||
*
|
*
|
||||||
* Example: Given I fill in "Hello" with "World"
|
* Example: Given I fill in "Hello" with "World"
|
||||||
*
|
*
|
||||||
@ -615,16 +619,16 @@ JS;
|
|||||||
|
|
||||||
$regionObj->fillField($field, $value);
|
$regionObj->fillField($field, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute,
|
* 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).
|
* or a named region mapped to a CSS selector via Behat configuration).
|
||||||
* Supports regular expressions in text value.
|
* Supports regular expressions in text value.
|
||||||
*
|
*
|
||||||
* Example: Given I should see "My Text" in the "header .login-form" region
|
* 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
|
* Example: Given I should not see "My Text" in the "My Login Form" region
|
||||||
*
|
*
|
||||||
* @Given /^I should (?P<negate>(?:(not |)))see "(?P<text>[^"]*)" in the "(?P<region>[^"]*)" region$/
|
* @Given /^I should (?P<negate>(?:(not |)))see "(?P<text>[^"]*)" in the "(?P<region>[^"]*)" region$/
|
||||||
*/
|
*/
|
||||||
public function iSeeTextInRegion($negate, $text, $region) {
|
public function iSeeTextInRegion($negate, $text, $region) {
|
||||||
@ -639,7 +643,7 @@ JS;
|
|||||||
if(trim($negate)) {
|
if(trim($negate)) {
|
||||||
if (preg_match($regex, $actual)) {
|
if (preg_match($regex, $actual)) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'The text "%s" was found in the text of the "%s" region on the page %s.',
|
'The text "%s" was found in the text of the "%s" region on the page %s.',
|
||||||
$text,
|
$text,
|
||||||
$region,
|
$region,
|
||||||
$this->getSession()->getCurrentUrl()
|
$this->getSession()->getCurrentUrl()
|
||||||
@ -659,12 +663,12 @@ JS;
|
|||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects the specified radio button
|
* Selects the specified radio button
|
||||||
*
|
*
|
||||||
* @Given /^I select the "([^"]*)" radio button$/
|
* @Given /^I select the "([^"]*)" radio button$/
|
||||||
*/
|
*/
|
||||||
public function iSelectTheRadioButton($radioLabel) {
|
public function iSelectTheRadioButton($radioLabel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user