Skip to content

Commit

Permalink
[Behat] Extract browser element and context
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Mar 7, 2022
1 parent 5dee3dc commit d4bf36c
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 30 deletions.
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public function iLogOut(): void
$this->dashboardPage->logOut();
}

/**
* @When I go back one page in the browser
*/
public function iGoBackOnePageInTheBrowser(): void
{
$this->dashboardPage->goBackInTheBrowser();
}

/**
* @Then I should see :number new orders
*/
Expand Down
36 changes: 36 additions & 0 deletions src/Sylius/Behat/Context/Ui/BrowserContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Context\Ui;

use Behat\Behat\Context\Context;
use Sylius\Behat\Element\BrowserElementInterface;

final class BrowserContext implements Context
{
/** @var BrowserElementInterface */
private $browserElement;

public function __construct(BrowserElementInterface $browserElement)
{
$this->browserElement = $browserElement;
}

/**
* @When I go back one page in the browser
*/
public function iGoBackOnePageInTheBrowser(): void
{
$this->browserElement->goBack();
}
}
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Ui/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ public function iDeleteAccount($email)
$this->customerShowPage->deleteAccount();
}

/**
* @When I go back one page in the browser
*/
public function iGoBackOnePageInTheBrowser(): void
{
$this->homePage->goBackInTheBrowser();
}

/**
* @Then the user account should be deleted
*/
Expand Down
24 changes: 24 additions & 0 deletions src/Sylius/Behat/Element/BrowserElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Element;

use FriendsOfBehat\PageObjectExtension\Element\Element;

final class BrowserElement extends Element implements BrowserElementInterface
{
public function goBack(): void
{
$this->getDriver()->back();
}
}
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Element/BrowserElementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Element;

interface BrowserElementInterface
{
public function goBack(): void;
}
5 changes: 0 additions & 5 deletions src/Sylius/Behat/Page/Admin/DashboardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public function chooseChannel(string $channelName): void
$this->getElement('channel_choosing_link', ['%channelName%' => $channelName])->click();
}

public function goBackInTheBrowser(): void
{
$this->getDriver()->back();
}

public function getRouteName(): string
{
return 'sylius_admin_dashboard';
Expand Down
2 changes: 0 additions & 2 deletions src/Sylius/Behat/Page/Admin/DashboardPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ public function isSectionWithLabelVisible(string $name): bool;
public function logOut(): void;

public function chooseChannel(string $channelName): void;

public function goBackInTheBrowser(): void;
}
5 changes: 0 additions & 5 deletions src/Sylius/Behat/Page/Shop/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ function (NodeElement $element) {
);
}

public function goBackInTheBrowser(): void
{
$this->getDriver()->back();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand Down
2 changes: 0 additions & 2 deletions src/Sylius/Behat/Page/Shop/HomePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ public function getAvailableLocales(): array;
public function switchLocale(string $localeCode): void;

public function getLatestProductsNames(): array;

public function goBackInTheBrowser(): void;
}
4 changes: 4 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@
<tag name="fob.context_service" />
</service>

<service id="sylius.behat.context.ui.browser" class="Sylius\Behat\Context\Ui\BrowserContext">
<argument type="service" id="sylius.behat.element.browser" />
</service>

<service id="sylius.behat.context.ui.channel" class="Sylius\Behat\Context\Ui\ChannelContext">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.channel_context_setter" />
Expand Down
3 changes: 3 additions & 0 deletions src/Sylius/Behat/Resources/config/services/elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
<import resource="elements/shop.xml" />
<import resource="elements/product.xml" />
</imports>

<services>
<service id="sylius.behat.element" class="FriendsOfBehat\PageObjectExtension\Element\Element" abstract="true" public="false">
<argument type="service" id="behat.mink.default_session" />
<argument type="service" id="behat.mink.parameters" />
</service>

<service id="sylius.behat.element.browser" class="Sylius\Behat\Element\BrowserElement" parent="sylius.behat.element" public="false" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ default:
- sylius.behat.context.setup.user
- sylius.behat.context.setup.zone

- sylius.behat.context.ui.browser
- sylius.behat.context.ui.channel
- sylius.behat.context.ui.email
- sylius.behat.context.ui.shop.account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default:
- sylius.behat.context.ui.admin.dashboard
- sylius.behat.context.ui.admin.login
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.browser

filters:
tags: "@admin_dashboard&&@ui"

0 comments on commit d4bf36c

Please sign in to comment.