[Behat] Implemet latest product scenario

This commit is contained in:
Łukasz 2016-11-16 09:00:24 +01:00
parent d274599f9b
commit 6d2ab318c8
8 changed files with 115 additions and 2 deletions

View file

@ -1,4 +1,4 @@
@viewing_products
@homepage
Feature: Viewing a latest product list
In order to be up-to-date with the newest products
As a Visitor
@ -6,7 +6,7 @@ Feature: Viewing a latest product list
Background:
Given the store operates on a single channel in "United States"
And the store has "Belvedere Vodka", "Coconaut Liqeur", "Chopin Chocolate Liquer" and "Capitan Morgan White Rum" products
And this channel has "Belvedere Vodka", "Coconaut Liqeur", "Chopin Chocolate Liquer" and "Capitan Morgan White Rum" products
@ui
Scenario: Viewing latest products

View file

@ -224,6 +224,7 @@ final class ProductContext implements Context
/**
* @Given /^(this product) is named "([^"]+)" (in the "([^"]+)" locale)$/
* @Given /^the (product "[^"]+") is named "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function thisProductIsNamedIn(ProductInterface $product, $name, $locale)
{
@ -272,6 +273,19 @@ final class ProductContext implements Context
}
}
/**
* @Given /^(this channel) has "([^"]+)", "([^"]+)", "([^"]+)" and "([^"]+)" products$/
*/
public function thisChannelHasProducts(ChannelInterface $channel, ...$productsNames)
{
foreach ($productsNames as $productName) {
$product = $this->createProduct($productName);
$product->addChannel($channel);
$this->saveProduct($product);
}
}
/**
* @Given /^the (product "[^"]+") has(?:| a) "([^"]+)" variant priced at ("[^"]+")$/
* @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+")$/

View file

@ -0,0 +1,57 @@
<?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.
*/
namespace Sylius\Behat\Context\Ui\Shop;
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Shop\HomePageInterface;
use Webmozart\Assert\Assert;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
final class HomepageContext implements Context
{
/**
* @var HomePageInterface
*/
private $homePage;
/**
* @param HomePageInterface $homepage
*/
public function __construct(HomePageInterface $homepage)
{
$this->homePage = $homepage;
}
/**
* @When I check latest products
*/
public function iCheckLatestProducts()
{
$this->homePage->open();
}
/**
* @Then I should see :numberOfProducts products in the list
*/
public function iShouldSeeProductsInTheList($numberOfProducts)
{
$foundProductsNames = $this->homePage->getLatestProductsNames();
Assert::same(
(int) $numberOfProducts,
count($foundProductsNames),
'%d rows with products should appear on page, %d rows has been found'
);
}
}

View file

@ -102,6 +102,17 @@ class HomePage extends SymfonyPage implements HomePageInterface
$this->getElement('locale_selector')->clickLink($localeCode);
}
/**
* {@inheritdoc}
*/
public function getLatestProductsNames()
{;
return array_map(
function (NodeElement $element) { return $element->getText(); },
$this->getDocument()->findAll('css', '.sylius-product-name')
);
}
/**
* {@inheritdoc}
*/

View file

@ -57,4 +57,9 @@ interface HomePageInterface extends SymfonyPageInterface
* @param string $localeCode
*/
public function switchLocale($localeCode);
/**
* @return array
*/
public function getLatestProductsNames();
}

View file

@ -333,6 +333,11 @@
<tag name="fob.context_service" />
</service>
<service id="sylius.behat.context.ui.shop.homepage" class="Sylius\Behat\Context\Ui\Shop\HomepageContext">
<argument type="service" id="sylius.behat.page.shop.home" />
<tag name="fob.context_service" />
</service>
<service id="sylius.behat.context.ui.shop.locale" class="Sylius\Behat\Context\Ui\Shop\LocaleContext">
<argument type="service" id="sylius.behat.page.shop.home" />
<tag name="fob.context_service" />

View file

@ -29,6 +29,7 @@ imports:
- suites/ui/checkout/paying_for_order.yml
- suites/ui/currency/currencies.yml
- suites/ui/currency/managing_currencies.yml
- suites/ui/homepage/viewing_products.yml
- suites/ui/inventory/cart_inventory.yml
- suites/ui/inventory/checkout_inventory.yml
- suites/ui/inventory/managing_inventory.yml

View file

@ -0,0 +1,20 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui_homepage:
contexts_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shop_security
- sylius.behat.context.ui.shop.homepage
filters:
tags: "@homepage && @ui"