mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-09-28 20:29:36 +02:00
Formatting Cleanup
This commit is contained in:
parent
6f648a418a
commit
e1d42b89fe
@ -9,7 +9,9 @@ use Behat\Behat\Context\ClosuredContextInterface,
|
|||||||
Behat\Behat\Event\StepEvent,
|
Behat\Behat\Event\StepEvent,
|
||||||
Behat\Behat\Event\ScenarioEvent,
|
Behat\Behat\Event\ScenarioEvent,
|
||||||
Behat\Behat\Exception\PendingException;
|
Behat\Behat\Exception\PendingException;
|
||||||
|
|
||||||
use Behat\Mink\Driver\Selenium2Driver;
|
use Behat\Mink\Driver\Selenium2Driver;
|
||||||
|
|
||||||
use Behat\Gherkin\Node\PyStringNode,
|
use Behat\Gherkin\Node\PyStringNode,
|
||||||
Behat\Gherkin\Node\TableNode;
|
Behat\Gherkin\Node\TableNode;
|
||||||
|
|
||||||
@ -53,8 +55,7 @@ class BasicContext extends BehatContext
|
|||||||
*
|
*
|
||||||
* @param array $parameters context parameters (set them up through behat.yml)
|
* @param array $parameters context parameters (set them up through behat.yml)
|
||||||
*/
|
*/
|
||||||
public function __construct(array $parameters)
|
public function __construct(array $parameters) {
|
||||||
{
|
|
||||||
// Initialize your context here
|
// Initialize your context here
|
||||||
$this->context = $parameters;
|
$this->context = $parameters;
|
||||||
}
|
}
|
||||||
@ -64,8 +65,7 @@ class BasicContext extends BehatContext
|
|||||||
*
|
*
|
||||||
* @return \Behat\Mink\Session
|
* @return \Behat\Mink\Session
|
||||||
*/
|
*/
|
||||||
public function getSession($name = null)
|
public function getSession($name = null) {
|
||||||
{
|
|
||||||
return $this->getMainContext()->getSession($name);
|
return $this->getMainContext()->getSession($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +75,7 @@ class BasicContext extends BehatContext
|
|||||||
* Excluding scenarios with @modal tag is required,
|
* Excluding scenarios with @modal tag is required,
|
||||||
* because modal dialogs stop any JS interaction
|
* because modal dialogs stop any JS interaction
|
||||||
*/
|
*/
|
||||||
public function appendErrorHandlerBeforeStep(StepEvent $event)
|
public function appendErrorHandlerBeforeStep(StepEvent $event) {
|
||||||
{
|
|
||||||
$javascript = <<<JS
|
$javascript = <<<JS
|
||||||
window.onerror = function(message, file, line, column, error) {
|
window.onerror = function(message, file, line, column, error) {
|
||||||
var body = document.getElementsByTagName('body')[0];
|
var body = document.getElementsByTagName('body')[0];
|
||||||
@ -103,8 +102,7 @@ JS;
|
|||||||
* Excluding scenarios with @modal tag is required,
|
* Excluding scenarios with @modal tag is required,
|
||||||
* because modal dialogs stop any JS interaction
|
* because modal dialogs stop any JS interaction
|
||||||
*/
|
*/
|
||||||
public function readErrorHandlerAfterStep(StepEvent $event)
|
public function readErrorHandlerAfterStep(StepEvent $event) {
|
||||||
{
|
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
|
|
||||||
$jserrors = $page->find('xpath', '//body[@data-jserrors]');
|
$jserrors = $page->find('xpath', '//body[@data-jserrors]');
|
||||||
@ -131,8 +129,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @BeforeStep
|
* @BeforeStep
|
||||||
*/
|
*/
|
||||||
public function handleAjaxBeforeStep(StepEvent $event)
|
public function handleAjaxBeforeStep(StepEvent $event) {
|
||||||
{
|
|
||||||
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
||||||
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
||||||
|
|
||||||
@ -175,8 +172,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @AfterStep ~@modal
|
* @AfterStep ~@modal
|
||||||
*/
|
*/
|
||||||
public function handleAjaxAfterStep(StepEvent $event)
|
public function handleAjaxAfterStep(StepEvent $event) {
|
||||||
{
|
|
||||||
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
||||||
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
||||||
|
|
||||||
@ -196,8 +192,7 @@ JS;
|
|||||||
$this->getSession()->executeScript($javascript);
|
$this->getSession()->executeScript($javascript);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleAjaxTimeout()
|
public function handleAjaxTimeout() {
|
||||||
{
|
|
||||||
$timeoutMs = $this->getMainContext()->getAjaxTimeout();
|
$timeoutMs = $this->getMainContext()->getAjaxTimeout();
|
||||||
|
|
||||||
// Wait for an ajax request to complete, but only for a maximum of 5 seconds to avoid deadlocks
|
// Wait for an ajax request to complete, but only for a maximum of 5 seconds to avoid deadlocks
|
||||||
@ -215,8 +210,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @AfterStep
|
* @AfterStep
|
||||||
*/
|
*/
|
||||||
public function takeScreenshotAfterFailedStep(StepEvent $event)
|
public function takeScreenshotAfterFailedStep(StepEvent $event) {
|
||||||
{
|
|
||||||
if (4 === $event->getResult()) {
|
if (4 === $event->getResult()) {
|
||||||
$this->takeScreenshot($event);
|
$this->takeScreenshot($event);
|
||||||
}
|
}
|
||||||
@ -248,8 +242,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @AfterScenario @assets
|
* @AfterScenario @assets
|
||||||
*/
|
*/
|
||||||
public function cleanAssetsAfterScenario(ScenarioEvent $event)
|
public function cleanAssetsAfterScenario(ScenarioEvent $event) {
|
||||||
{
|
|
||||||
foreach(\File::get() as $file) {
|
foreach(\File::get() as $file) {
|
||||||
if(file_exists($file->getFullPath())) $file->delete();
|
if(file_exists($file->getFullPath())) $file->delete();
|
||||||
}
|
}
|
||||||
@ -296,8 +289,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Then /^I should be redirected to "([^"]+)"/
|
* @Then /^I should be redirected to "([^"]+)"/
|
||||||
*/
|
*/
|
||||||
public function stepIShouldBeRedirectedTo($url)
|
public function stepIShouldBeRedirectedTo($url) {
|
||||||
{
|
|
||||||
if ($this->getMainContext()->canIntercept()) {
|
if ($this->getMainContext()->canIntercept()) {
|
||||||
$client = $this->getSession()->getDriver()->getClient();
|
$client = $this->getSession()->getDriver()->getClient();
|
||||||
$client->followRedirects(true);
|
$client->followRedirects(true);
|
||||||
@ -312,8 +304,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(
|
||||||
// Content from ErrorPage default record
|
// Content from ErrorPage default record
|
||||||
@ -326,16 +317,14 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^I wait (?:for )?([\d\.]+) second(?:s?)$/
|
* @Given /^I wait (?:for )?([\d\.]+) second(?:s?)$/
|
||||||
*/
|
*/
|
||||||
public function stepIWaitFor($secs)
|
public function stepIWaitFor($secs) {
|
||||||
{
|
|
||||||
$this->getSession()->wait((float)$secs*1000);
|
$this->getSession()->wait((float)$secs*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Given /^I press the "([^"]*)" button$/
|
* @Given /^I press the "([^"]*)" button$/
|
||||||
*/
|
*/
|
||||||
public function stepIPressTheButton($button)
|
public function stepIPressTheButton($button) {
|
||||||
{
|
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
$els = $page->findAll('named', array('link_or_button', "'$button'"));
|
$els = $page->findAll('named', array('link_or_button', "'$button'"));
|
||||||
$matchedEl = null;
|
$matchedEl = null;
|
||||||
@ -353,8 +342,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @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) {
|
||||||
{
|
|
||||||
$this->stepIPressTheButton($button);
|
$this->stepIPressTheButton($button);
|
||||||
$this->iConfirmTheDialog();
|
$this->iConfirmTheDialog();
|
||||||
}
|
}
|
||||||
@ -365,8 +353,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @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) {
|
||||||
{
|
|
||||||
$this->stepIPressTheButton($button);
|
$this->stepIPressTheButton($button);
|
||||||
$this->iDismissTheDialog();
|
$this->iDismissTheDialog();
|
||||||
}
|
}
|
||||||
@ -374,8 +361,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^I click "([^"]*)" in the "([^"]*)" element$/
|
* @Given /^I click "([^"]*)" in the "([^"]*)" element$/
|
||||||
*/
|
*/
|
||||||
public function iClickInTheElement($text, $selector)
|
public function iClickInTheElement($text, $selector) {
|
||||||
{
|
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
|
|
||||||
$parentElement = $page->find('css', $selector);
|
$parentElement = $page->find('css', $selector);
|
||||||
@ -390,8 +376,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^I type "([^"]*)" into the dialog$/
|
* @Given /^I type "([^"]*)" into the dialog$/
|
||||||
*/
|
*/
|
||||||
public function iTypeIntoTheDialog($data)
|
public function iTypeIntoTheDialog($data) {
|
||||||
{
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'text' => $data,
|
'text' => $data,
|
||||||
);
|
);
|
||||||
@ -401,8 +386,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^I confirm the dialog$/
|
* @Given /^I confirm the dialog$/
|
||||||
*/
|
*/
|
||||||
public function iConfirmTheDialog()
|
public function iConfirmTheDialog() {
|
||||||
{
|
|
||||||
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
|
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
|
||||||
$this->handleAjaxTimeout();
|
$this->handleAjaxTimeout();
|
||||||
}
|
}
|
||||||
@ -410,8 +394,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^I dismiss the dialog$/
|
* @Given /^I dismiss the dialog$/
|
||||||
*/
|
*/
|
||||||
public function iDismissTheDialog()
|
public function iDismissTheDialog() {
|
||||||
{
|
|
||||||
$this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
|
$this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
|
||||||
$this->handleAjaxTimeout();
|
$this->handleAjaxTimeout();
|
||||||
}
|
}
|
||||||
@ -419,8 +402,7 @@ JS;
|
|||||||
/**
|
/**
|
||||||
* @Given /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)" with HTML5$/
|
* @Given /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)" with HTML5$/
|
||||||
*/
|
*/
|
||||||
public function iAttachTheFileTo($field, $path)
|
public function iAttachTheFileTo($field, $path) {
|
||||||
{
|
|
||||||
// Remove wrapped button styling to make input field accessible to Selenium
|
// Remove wrapped button styling to make input field accessible to Selenium
|
||||||
$js = <<<JS
|
$js = <<<JS
|
||||||
var input = jQuery('[name="$field"]');
|
var input = jQuery('[name="$field"]');
|
||||||
@ -469,8 +451,7 @@ JS;
|
|||||||
*
|
*
|
||||||
* @Then /^(?:|I )put a breakpoint$/
|
* @Then /^(?:|I )put a breakpoint$/
|
||||||
*/
|
*/
|
||||||
public function iPutABreakpoint()
|
public function iPutABreakpoint() {
|
||||||
{
|
|
||||||
fwrite(STDOUT, "\033[s \033[93m[Breakpoint] Press \033[1;93m[RETURN]\033[0;93m to continue...\033[0m");
|
fwrite(STDOUT, "\033[s \033[93m[Breakpoint] Press \033[1;93m[RETURN]\033[0;93m to continue...\033[0m");
|
||||||
while (fgets(STDIN, 1024) == '') {}
|
while (fgets(STDIN, 1024) == '') {}
|
||||||
fwrite(STDOUT, "\033[u");
|
fwrite(STDOUT, "\033[u");
|
||||||
@ -618,7 +599,8 @@ JS;
|
|||||||
|
|
||||||
$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();
|
||||||
@ -638,7 +620,8 @@ JS;
|
|||||||
|
|
||||||
$fieldObj = $regionObj->findField($field);
|
$fieldObj = $regionObj->findField($field);
|
||||||
if (empty($fieldObj)) {
|
if (empty($fieldObj)) {
|
||||||
throw new \Exception(sprintf('The field "%s" was not found in the region "%s" on the page %s', $field, $region, $this->getSession()->getCurrentUrl()));
|
throw new \Exception(sprintf('The field "%s" was not found in the region "%s"
|
||||||
|
on the page %s', $field, $region, $this->getSession()->getCurrentUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$regionObj->fillField($field, $value);
|
$regionObj->fillField($field, $value);
|
||||||
@ -756,10 +739,12 @@ JS;
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Find tables by a <caption> field
|
// Find tables by a <caption> field
|
||||||
$candidates += $page->findAll('xpath', "//table//caption[contains(normalize-space(string(.)), $selector)]/ancestor-or-self::table[1]");
|
$candidates += $page->findAll('xpath', "//table//caption[contains(normalize-space(string(.)),
|
||||||
|
$selector)]/ancestor-or-self::table[1]");
|
||||||
|
|
||||||
// Find tables by a .title node
|
// Find tables by a .title node
|
||||||
$candidates += $page->findAll('xpath', "//table//*[@class='title' and contains(normalize-space(string(.)), $selector)]/ancestor-or-self::table[1]");
|
$candidates += $page->findAll('xpath', "//table//*[@class='title' and contains(normalize-space(string(.)),
|
||||||
|
$selector)]/ancestor-or-self::table[1]");
|
||||||
|
|
||||||
// Some tables don't have a visible title, so look for a fieldset with data-name instead
|
// Some tables don't have a visible title, so look for a fieldset with data-name instead
|
||||||
$candidates += $page->findAll('xpath', "//fieldset[@data-name=$selector]//table");
|
$candidates += $page->findAll('xpath', "//fieldset[@data-name=$selector]//table");
|
||||||
|
Loading…
Reference in New Issue
Block a user