Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Behat] Rework behat - using attributes instead class/id in address and shipping page #10921

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function getRouteName(): string
*/
public function checkValidationMessageFor(string $element, string $message): bool
{
$errorLabel = $this->getElement($element)->getParent()->find('css', '[data-test-sylius-validation-error]');
$errorLabel = $this->getElement($element)->getParent()->find('css', '[data-test-validation-error]');

if (null === $errorLabel) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-sylius-validation-error]');
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-validation-error]');
}

return $message === $errorLabel->getText();
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Shop/Account/ResetPasswordPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function specifyConfirmPassword(string $password): void

public function checkValidationMessageFor(string $element, string $message): bool
{
$errorLabel = $this->getElement($element)->getParent()->find('css', '[data-test-sylius-validation-error]');
$errorLabel = $this->getElement($element)->getParent()->find('css', '[data-test-validation-error]');

if (null === $errorLabel) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-sylius-validation-error]');
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-validation-error]');
}

return $message === $errorLabel->getText();
Expand Down
48 changes: 24 additions & 24 deletions src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function chooseDifferentBillingAddress(): void
public function checkInvalidCredentialsValidation(): bool
{
$this->getElement('login_password')->waitFor(5, function () {
$validationElement = $this->getElement('login_password')->getParent()->find('css', '.red.label');
$validationElement = $this->getElement('login_password')->getParent()->find('css', '[data-test-login-errors]');
if (null === $validationElement) {
return false;
}
Expand All @@ -85,12 +85,12 @@ public function checkValidationMessageFor(string $element, string $message): boo
{
$foundElement = $this->getFieldElement($element);
if (null === $foundElement) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-validation-error]');
}

$validationMessage = $foundElement->find('css', '.sylius-validation-error');
if (null === $validationMessage) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-validation-error]');
}

return $message === $validationMessage->getText();
Expand Down Expand Up @@ -118,7 +118,7 @@ public function selectBillingAddressProvince(string $province): void
$this->getElement('billing_country_province')->selectOption($province);
}

public function specifyEmail(string $email): void
public function specifyEmail(?string $email): void
{
$this->getElement('customer_email')->setValue($email);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public function getItemSubtotal(string $itemName): string

$subtotalTable = $this->getElement('checkout_subtotal');

return $subtotalTable->find('css', sprintf('#sylius-item-%s-subtotal', $itemSlug))->getText();
return $subtotalTable->find('css', sprintf('[data-test-item-subtotal="%s"]', $itemSlug))->getText();
}

public function getShippingAddressCountry(): string
Expand Down Expand Up @@ -253,31 +253,31 @@ public function getPreFilledBillingAddress(): AddressInterface
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'billing_address_book' => '#sylius-billing-address .ui.dropdown',
'billing_first_name' => '#sylius_checkout_address_billingAddress_firstName',
'billing_last_name' => '#sylius_checkout_address_billingAddress_lastName',
'billing_street' => '#sylius_checkout_address_billingAddress_street',
'billing_city' => '#sylius_checkout_address_billingAddress_city',
'billing_country' => '#sylius_checkout_address_billingAddress_countryCode',
'billing_address_book' => '[data-test-billing-address] .ui.dropdown',
'billing_city' => '[data-test-billing-city]',
'billing_country' => '[data-test-billing-country]',
'billing_country_province' => '[name="sylius_checkout_address[billingAddress][provinceCode]"]',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'billing_postcode' => '#sylius_checkout_address_billingAddress_postcode',
'billing_first_name' => '[data-test-billing-first-name]',
'billing_last_name' => '[data-test-billing-last-name]',
'billing_postcode' => '[data-test-billing-postcode]',
'billing_province' => '[name="sylius_checkout_address[billingAddress][provinceName]"]',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'checkout_subtotal' => '#sylius-checkout-subtotal',
'customer_email' => '#sylius_checkout_address_customer_email',
'different_billing_address' => '#sylius_checkout_address_differentBillingAddress',
'different_billing_address_label' => '#sylius_checkout_address_differentBillingAddress ~ label',
'billing_street' => '[data-test-billing-street]',
'checkout_subtotal' => '[data-test-checkout-subtotal]',
'customer_email' => '[data-test-login-email]',
'different_billing_address' => '[data-test-different-billing-address]',
'different_billing_address_label' => '[data-test-different-billing-address-label]',
'login_button' => '#sylius-api-login-submit',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'login_password' => 'input[type=\'password\']',
'next_step' => '#next-step',
'shipping_address_book' => '#sylius-shipping-address .ui.dropdown',
'shipping_city' => '#sylius_checkout_address_shippingAddress_city',
'shipping_country' => '#sylius_checkout_address_shippingAddress_countryCode',
'next_step' => '[data-test-next-step]',
'shipping_address_book' => '[data-test-address-book]',
'shipping_city' => '[data-test-shipping-city]',
'shipping_country' => '[data-test-shipping-country]',
'shipping_country_province' => '[name="sylius_checkout_address[shippingAddress][provinceCode]"]',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'shipping_first_name' => '#sylius_checkout_address_shippingAddress_firstName',
'shipping_last_name' => '#sylius_checkout_address_shippingAddress_lastName',
'shipping_postcode' => '#sylius_checkout_address_shippingAddress_postcode',
'shipping_first_name' => '[data-test-shipping-first-name]',
'shipping_last_name' => '[data-test-shipping-last-name]',
'shipping_postcode' => '[data-test-shipping-postcode]',
'shipping_province' => '[name="sylius_checkout_address[shippingAddress][provinceName]"]',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'shipping_street' => '#sylius_checkout_address_shippingAddress_street',
'shipping_street' => '[data-test-shipping-street]',
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function specifyBillingAddress(AddressInterface $billingAddress): void;

public function selectBillingAddressProvince(string $province): void;

public function specifyEmail(string $email): void;
public function specifyEmail(?string $email): void;

public function specifyShippingAddressFullName(string $fullName): void;

Expand Down
36 changes: 18 additions & 18 deletions src/Sylius/Behat/Page/Shop/Checkout/SelectShippingPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function selectShippingMethod(string $shippingMethod): void

public function getShippingMethods(): array
{
$inputs = $this->getSession()->getPage()->findAll('css', '#sylius-shipping-methods .item .content label');
$inputs = $this->getSession()->getPage()->findAll('css', '[data-test-shipping-method-label]');

$shippingMethods = [];
foreach ($inputs as $input) {
Expand All @@ -51,12 +51,12 @@ public function getShippingMethods(): array

public function getSelectedShippingMethodName(): ?string
{
$shippingMethods = $this->getSession()->getPage()->findAll('css', '#sylius-shipping-methods .item');
$shippingMethods = $this->getSession()->getPage()->findAll('css', '[data-test-shipping-item]');

/** @var NodeElement $shippingMethod */
foreach ($shippingMethods as $shippingMethod) {
if (null !== $shippingMethod->find('css', 'input:checked')) {
return $shippingMethod->find('css', '.content label')->getText();
return $shippingMethod->find('css', '[data-test-shipping-method-label]')->getText();
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public function getItemSubtotal(string $itemName): string

$subtotalTable = $this->getElement('checkout_subtotal');

return $subtotalTable->find('css', sprintf('#sylius-item-%s-subtotal', $itemSlug))->getText();
return $subtotalTable->find('css', sprintf('[data-test-item-subtotal="%s"]', $itemSlug))->getText();
}

public function nextStep(): void
Expand All @@ -107,7 +107,7 @@ public function changeAddressByStepLabel(): void

public function getPurchaserEmail(): string
{
return $this->getElement('purchaser-email')->getText();
return $this->getElement('purchaser_email')->getText();
}

public function getValidationMessageForShipment(): string
Expand All @@ -117,9 +117,9 @@ public function getValidationMessageForShipment(): string
throw new ElementNotFoundException($this->getSession(), 'Items element');
}

$validationMessage = $foundElement->find('css', '.sylius-validation-error');
$validationMessage = $foundElement->find('css', '[data-test-validation-error]');
if (null === $validationMessage) {
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '[data-test-validation-error]');
}

return $validationMessage->getText();
Expand All @@ -137,7 +137,7 @@ public function isNextStepButtonUnavailable(): bool

public function hasShippingMethod(string $shippingMethodName): bool
{
$inputs = $this->getSession()->getPage()->findAll('css', '#sylius-shipping-methods .item .content label');
$inputs = $this->getSession()->getPage()->findAll('css', '[data-test-shipping-method-label]');

$shippingMethods = [];
foreach ($inputs as $input) {
Expand All @@ -150,17 +150,17 @@ public function hasShippingMethod(string $shippingMethodName): bool
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'address' => '.steps a:contains("Address")',
'checkout_subtotal' => '#sylius-checkout-subtotal',
'next_step' => '#next-step',
'order_cannot_be_shipped_message' => '#sylius-order-cannot-be-shipped',
'purchaser-email' => '#purchaser-email',
'shipment' => '.items',
'shipping_method' => '[name="sylius_checkout_select_shipping[shipments][0][method]"]',
'shipping_method_fee' => '.item:contains("%shipping_method%") .fee',
'shipping_method_select' => '.item:contains("%shipping_method%") > .field > .ui.radio.checkbox',
'address' => '[data-test-step-address]',
'checkout_subtotal' => '[data-test-checkout-subtotal]',
'next_step' => '[data-test-next-step]',
'order_cannot_be_shipped_message' => '[data-test-order-cannot-be-shipped]',
'purchaser_email' => '[data-test-purchaser-name-or-email]',
'shipment' => '[data-test-shipments]',
'shipping_method' => '[data-test-shipping-method-select]',
'shipping_method_fee' => '[data-test-shipping-item]:contains("%shipping_method%") [data-test-shipping-method-fee]',
'shipping_method_select' => '[data-test-shipping-item]:contains("%shipping_method%") > .field > .ui.radio.checkbox',
'shipping_method_option' => '.item:contains("%shipping_method%") input',
pamil marked this conversation as resolved.
Show resolved Hide resolved
'warning_no_shipping_methods' => '#sylius-order-cannot-be-shipped',
'warning_no_shipping_methods' => '[data-test-order-cannot-be-shipped]',
]);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if app.user is not empty and app.user.customer is not empty and app.user.customer.addresses|length > 0 %}
<div class="ui fluid floating dropdown labeled search icon button address-book-select">
<div class="ui fluid floating dropdown labeled search icon button address-book-select" {{ sylius_test_html_attribute('address-book') }}>
<i class="book icon"></i>
<span class="text">{{ 'sylius.ui.select_address_from_book'|trans }}</span>
<div class="menu">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div id="sylius-shipping-address">
<div id="sylius-shipping-address" {{ sylius_test_html_attribute('shipping-address') }}>
{% include '@SyliusShop/Checkout/Address/_addressBookSelect.html.twig' %}
<h3 class="ui dividing header">{{ 'sylius.ui.shipping_address'|trans }}</h3>
{% if form.customer is defined %}
{% include '@SyliusShop/Common/Form/_login.html.twig' with {'form': form.customer} %}
{% endif %}
{% include '@SyliusShop/Common/Form/_address.html.twig' with {'form': form.shippingAddress, 'order': order} %}
{{ form_row(form.differentBillingAddress, {'attr': {'data-toggles': 'sylius-billing-address'}}) }}
{% include '@SyliusShop/Common/Form/_address.html.twig' with {'form': form.shippingAddress, 'order': order, 'type': 'shipping'} %}
{{ form_row(form.differentBillingAddress,sylius_test_form_attribute('different-billing-address')|sylius_merge_recursive({'attr': {'data-toggles': 'sylius-billing-address'}, 'label_attr': {'data-test-different-billing-address-label': ''}} )) }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ form_row(form.differentBillingAddress,sylius_test_form_attribute('different-billing-address')|sylius_merge_recursive({'attr': {'data-toggles': 'sylius-billing-address'}, 'label_attr': {'data-test-different-billing-address-label': ''}} )) }}
{{ form_row(form.differentBillingAddress, sylius_test_form_attribute('different-billing-address') | sylius_merge_recursive({'attr': {'data-toggles': 'sylius-billing-address'}, 'label_attr': {'data-test-different-billing-address-label': ''}} )) }}


{{ sonata_block_render_event('sylius.shop.checkout.address.shipping_address_form', {'order': order}) }}
</div>

<div id="sylius-billing-address">
<div id="sylius-billing-address" {{ sylius_test_html_attribute('billing-address') }}>
<div class="ui hidden divider"></div>
{% include '@SyliusShop/Checkout/Address/_addressBookSelect.html.twig' %}
<h3 class="ui dividing header">{{ 'sylius.ui.billing_address'|trans }}</h3>
{% include '@SyliusShop/Common/Form/_address.html.twig' with {'form': form.billingAddress, 'order': order} %}
{% include '@SyliusShop/Common/Form/_address.html.twig' with {'form': form.billingAddress, 'order': order, 'type': 'billing'} %}

{{ sonata_block_render_event('sylius.shop.checkout.address.billing_address_form', {'order': order}) }}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<a href="{{ path('sylius_shop_homepage') }}" class="ui large icon labeled button"><i class="arrow left icon"></i> {{ 'sylius.ui.back_to_store'|trans }}</a>
</div>
<div class="right aligned column">
<button type="submit" id="next-step" class="ui large primary icon labeled button"><i class="arrow right icon"></i> {{ 'sylius.ui.next'|trans }}</button>
<button type="submit" id="next-step" class="ui large primary icon labeled button" {{ sylius_test_html_attribute('next-step') }}><i class="arrow right icon"></i> {{ 'sylius.ui.next'|trans }}</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endif %}
</div>
<div class="right aligned column">
<button type="submit" id="next-step" class="ui large primary icon labeled{% if not enabled %} disabled{% endif %} button">
<button type="submit" id="next-step" class="ui large primary icon labeled{% if not enabled %} disabled{% endif %} button" {{ sylius_test_html_attribute('next-step') }}>
<i class="arrow right icon"></i>
{{ 'sylius.ui.next'|trans }}
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{% import '@SyliusShop/Common/Macro/money.html.twig' as money %}

<div class="item">
<div class="item" {{ sylius_test_html_attribute('shipping-item') }}>
<div class="field">
<div class="ui radio checkbox">
{{ form_widget(form) }}
{{ form_widget(form, sylius_test_form_attribute('shipping-method-select')) }}
</div>
</div>
<div class="content">
<a class="header">{{ form_label(form) }}</a>
<a class="header" {{ sylius_test_html_attribute('shipping-method-label') }}>{{ form_label(form) }}</a>
{% if method.description is not null %}
<div class="description">
<p>{{ method.description }}</p>
</div>
{% endif %}
</div>
<div class="extra">
<div class="ui large right floated fee label">
<div class="ui large right floated fee label" {{ sylius_test_html_attribute('shipping-method-fee') }}>
{{ money.convertAndFormat(fee) }}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="{{ path('sylius_shop_checkout_address') }}" class="ui large icon labeled button"><i class="arrow left icon"></i> {{ 'sylius.ui.change_address'|trans }}</a>
</div>
<div class="right aligned column">
<button type="submit" id="next-step" class="ui large primary icon labeled{% if not enabled %} disabled{% endif %} button">
<button type="submit" id="next-step" class="ui large primary icon labeled{% if not enabled %} disabled{% endif %} button" {{ sylius_test_html_attribute('next-step') }}>
<i class="arrow right icon"></i>
{{ 'sylius.ui.next'|trans }}
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="ui segment">
<div class="ui dividing header">{{ 'sylius.ui.shipment'|trans }} #{{ loop.index }}</div>
<div class="ui fluid stackable items">
<div class="ui fluid stackable items" {{ sylius_test_html_attribute('shipments') }}>
{{ form_errors(form.method) }}

{% for key, choice_form in form.method %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="ui icon message" id="sylius-order-cannot-be-shipped">
<div class="ui icon message" id="sylius-order-cannot-be-shipped" {{ sylius_test_html_attribute('order-cannot-be-shipped') }}>
<i class="warning sign icon"></i>
<div class="content">
<div class="header">{{ 'sylius.ui.warning'|trans }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="right menu">
{% if order.customer.id|default(null) is not null %}
<div class="item" id="purchaser-email">{{ 'sylius.ui.checking_out_as'|trans }} {{ order.customer.fullName|default(order.customer.email) }}.</div>
<div class="item" id="purchaser-email" {{ sylius_test_html_attribute('purchaser-name-or-email') }}>{{ 'sylius.ui.checking_out_as'|trans }} {{ order.customer.fullName|default(order.customer.email) }}.</div>
{% else %}
<a href="{{ path('sylius_shop_login') }}" class="item">{{ 'sylius.ui.sign_in'|trans }}</a>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endif %}

<div class="ui {{ steps_count }} steps">
<a class="{{ steps['address'] }} step" href="{{ path('sylius_shop_checkout_address') }}">
<a class="{{ steps['address'] }} step" href="{{ path('sylius_shop_checkout_address') }}" {{ sylius_test_html_attribute('step-address') }}>
<i class="map icon"></i>
<div class="content">
<div class="title">{{ 'sylius.ui.address'|trans }}</div>
Expand Down
Loading