From 1ccf67b158f4fec2359c412a5c834453c3ca7dda Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 18 Mar 2021 15:15:16 +1300 Subject: [PATCH] MNT Fix archive button behat test --- tests/behat/features/publish-a-page.feature | 6 +++-- tests/behat/src/FixtureContext.php | 26 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/behat/features/publish-a-page.feature b/tests/behat/features/publish-a-page.feature index d4ec9d0b..07ec109d 100644 --- a/tests/behat/features/publish-a-page.feature +++ b/tests/behat/features/publish-a-page.feature @@ -82,9 +82,11 @@ Feature: Publish a page When I press the "Unpublish" button, confirming the dialog And I click "More options" in the "#ActionMenus" element - Then I should see an "Archive" button + # Use a css-selector instead of the the "Archive" button otherwise it will get confused with + # the "Archive" model admin + Then I see the "#Form_EditForm_action_archive" element + When I click the "#Form_EditForm_action_archive" element, confirming the dialog - When I press the "Archive" button, confirming the dialog Then I should see a "Restore" button And I should not see a "Published" button And I should not see a "Publish" button diff --git a/tests/behat/src/FixtureContext.php b/tests/behat/src/FixtureContext.php index 0d5931bb..b2f7df6c 100644 --- a/tests/behat/src/FixtureContext.php +++ b/tests/behat/src/FixtureContext.php @@ -2,8 +2,10 @@ namespace SilverStripe\CMS\Tests\Behaviour; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Mink\Element\DocumentElement; use Behat\Mink\Element\NodeElement; +use SilverStripe\BehatExtension\Context\BasicContext; use SilverStripe\BehatExtension\Context\FixtureContext as BehatFixtureContext; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\SiteTree; @@ -17,6 +19,18 @@ use SilverStripe\Versioned\Versioned; */ class FixtureContext extends BehatFixtureContext { + /** + * @var BasicContext + */ + protected $basicContext; + + + /** @BeforeScenario */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->basicContext = $scope->getEnvironment()->getContext(BasicContext::class); + } + protected function scaffoldDefaultFixtureFactory() { $factory = parent::scaffoldDefaultFixtureFactory(); @@ -81,6 +95,18 @@ class FixtureContext extends BehatFixtureContext $element->click(); } + /** + * Needs to be in single command to avoid "unexpected alert open" errors in Selenium. + * + * @When /^I click the "([^"]+)" element, confirming the dialog$/ + * @param $selector + */ + public function iClickTheElementConfirmingTheDialog($selector) + { + $this->iClickTheElement($selector); + $this->basicContext->iConfirmTheDialog(); + } + /** * @When /^I see the "([^"]+)" element$/ * @param $selector