Skip to content

Commit

Permalink
Merge pull request #5811 from magento-tsg/2.4-develop-pr51
Browse files Browse the repository at this point in the history
[TSG] TESTs Fixes for 2.4.1 (pr51) (2.4-develop)
  • Loading branch information
zakdma authored Jun 17, 2020
2 parents 29e1368 + 4d2f1ee commit 79b58c9
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<argument name="selector" type="string"/>
<argument name="userInput" type="string"/>
</arguments>


<waitForElementVisible selector="{{selector}}" time="60" stepKey="waitForElementVisible"/>
<see selector="{{selector}}" userInput="{{userInput}}" stepKey="assertElement"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<argument name="qty" type="string"/>
</arguments>

<waitForElementVisible selector="{{CheckoutCartProductSection.productName}}" time="60" stepKey="waitForProductNameVisible"/>
<see selector="{{CheckoutCartProductSection.productName}}" userInput="{{productName}}" stepKey="seeProductNameInCheckoutSummary"/>
<see selector="{{CheckoutCartProductSection.ProductPriceByName(productName)}}" userInput="{{productPrice}}" stepKey="seeProductPriceInCart"/>
<see selector="{{CheckoutCartProductSection.productSubtotalByName(productName)}}" userInput="{{subtotal}}" stepKey="seeSubtotalPrice"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontAddBundleDynamicProductToShoppingCartTest">
<annotations>
<features value="Checkout"/>
<stories value="Shopping Cart"/>
<title value="Add bundle dynamic product to the cart"/>
<description value="Add bundle dynamic product to the cart"/>
Expand All @@ -18,6 +19,7 @@
</annotations>

<before>
<magentoCLI command="config:set {{DisableFreeShippingConfigData.path}} {{DisableFreeShippingConfigData.value}}" stepKey="disableFreeShipping"/>
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
<magentoCLI command="config:set {{EnableFlatRateDefaultPriceConfigData.path}} {{EnableFlatRateDefaultPriceConfigData.value}}" stepKey="enableFlatRateDefaultPrice"/>
<createData entity="SimpleSubCategory" stepKey="createSubCategory"/>
Expand Down Expand Up @@ -46,19 +48,23 @@
<requiredEntity createDataKey="createBundleOption1_1"/>
<requiredEntity createDataKey="simpleProduct2"/>
</createData>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<actionGroup ref="AdminCartPriceRuleDeleteAllActionGroup" stepKey="deleteAllRules"/>
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value="cataloginventory_stock"/>
</actionGroup>
</before>
<after>
<deleteData createDataKey="simpleProduct1" stepKey="deleteProduct1"/>
<deleteData createDataKey="simpleProduct2" stepKey="deleteProduct2"/>
<deleteData createDataKey="createBundleProduct" stepKey="deleteBundleProduct"/>
<deleteData createDataKey="createSubCategory" stepKey="deleteCategory"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAsAdmin"/>
</after>

<!--Open Product page in StoreFront -->
<actionGroup ref="AssertProductNameAndSkuInStorefrontProductPageByCustomAttributeUrlKeyActionGroup" stepKey="openProductPageAndVerifyProduct">
<argument name="product" value="$$createBundleProduct$$"/>
<argument name="product" value="$createBundleProduct$"/>
</actionGroup>

<!--Assert Product Price Range -->
Expand Down Expand Up @@ -93,8 +99,8 @@

<!--Assert Product items in cart -->
<actionGroup ref="AssertStorefrontCheckoutCartItemsActionGroup" stepKey="assertSimpleProduct1ItemsInCheckOutCart">
<argument name="productName" value="$$createBundleProduct.name$$"/>
<argument name="productSku" value="$$createBundleProduct.sku$$"/>
<argument name="productName" value="$createBundleProduct.name$"/>
<argument name="productSku" value="$createBundleProduct.sku$"/>
<argument name="productPrice" value="$50.00"/>
<argument name="subtotal" value="$100.00" />
<argument name="qty" value="2"/>
Expand All @@ -107,13 +113,13 @@
</actionGroup>
<actionGroup ref="AssertStorefrontElementVisibleActionGroup" stepKey="seeProductOptionInCart">
<argument name="selector" value="{{CheckoutCartProductSection.productOptionLabel}}"/>
<argument name="userInput" value="1 x $$simpleProduct2.name$$ $50.00"/>
<argument name="userInput" value="1 x $simpleProduct2.name$ $50.00"/>
</actionGroup>

<!-- Assert Product in Mini Cart -->
<actionGroup ref="StorefrontClickOnMiniCartActionGroup" stepKey="clickOnMiniCart"/>
<actionGroup ref="AssertStorefrontMiniCartItemsActionGroup" stepKey="assertSimpleProduct3MiniCart">
<argument name="productName" value="$$createBundleProduct.name$$"/>
<argument name="productName" value="$createBundleProduct.name$"/>
<argument name="productPrice" value="$50.00"/>
<argument name="cartSubtotal" value="$100.00" />
<argument name="qty" value="2"/>
Expand Down
62 changes: 62 additions & 0 deletions app/code/Magento/Rule/Test/Mftf/Helper/RuleHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Rule\Test\Mftf\Helper;

use Facebook\WebDriver\Remote\RemoteWebDriver as FacebookWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Magento\FunctionalTestingFramework\Helper\Helper;
use Magento\FunctionalTestingFramework\Module\MagentoWebDriver;

/**
* Class for MFTF helpers for CatalogRule module.
*/
class RuleHelper extends Helper
{
/**
* Delete all Catalog Price Rules obe by one.
*
* @param string $emptyRow
* @param string $modalAceptButton
* @param string $deleteButton
* @param string $successMessageContainer
* @param string $successMessage
*
* @return void
*/
public function deleteAllRulesOneByOne(
string $firstNotEmptyRow,
string $modalAcceptButton,
string $deleteButton,
string $successMessageContainer,
string $successMessage
): void {
try {
/** @var MagentoWebDriver $webDriver */
$magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
/** @var FacebookWebDriver $webDriver */
$webDriver = $magentoWebDriver->webDriver;
$rows = $webDriver->findElements(WebDriverBy::cssSelector($firstNotEmptyRow));
while (!empty($rows)) {
$rows[0]->click();
$magentoWebDriver->waitForPageLoad(30);
$magentoWebDriver->click($deleteButton);
$magentoWebDriver->waitForPageLoad(30);
$magentoWebDriver->waitForElementVisible($modalAcceptButton, 10);
$magentoWebDriver->waitForPageLoad(60);
$magentoWebDriver->click($modalAcceptButton);
$magentoWebDriver->waitForPageLoad(60);
$magentoWebDriver->waitForLoadingMaskToDisappear();
$magentoWebDriver->waitForElementVisible($successMessageContainer, 10);
$magentoWebDriver->see($successMessage, $successMessageContainer);
$rows = $webDriver->findElements(WebDriverBy::cssSelector($firstNotEmptyRow));
}
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCartPriceRuleDeleteAllActionGroup">
<annotations>
<description>Open Cart Price Rule grid and delete all rules one by one. Need to avoid interference with other tests that test cart price rules.</description>
</annotations>

<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="goToAdminCartPriceRuleGridPage"/>
<!-- It sometimes is loading too long for default 10s -->
<waitForPageLoad time="60" stepKey="waitForPageFullyLoaded"/>
<conditionalClick selector="{{AdminDataGridHeaderSection.clearFilters}}" dependentSelector="{{AdminDataGridHeaderSection.clearFilters}}" visible="true" stepKey="clearExistingFilters"/>
<helper class="\Magento\Rule\Test\Mftf\Helper\RuleHelper" method="deleteAllRulesOneByOne" stepKey="deleteAllRulesOneByOne">
<argument name="firstNotEmptyRow">{{AdminDataGridTableSection.firstNotEmptyRow}}</argument>
<argument name="modalAcceptButton">{{AdminConfirmationModalSection.ok}}</argument>
<argument name="deleteButton">{{AdminMainActionsSection.delete}}</argument>
<argument name="successMessageContainer">{{AdminMessagesSection.success}}</argument>
<argument name="successMessage">You deleted the rule.</argument>
</helper>
<waitForElementVisible selector="{{AdminDataGridTableSection.dataGridEmpty}}" stepKey="waitDataGridEmptyMessageAppears"/>
<see selector="{{AdminDataGridTableSection.dataGridEmpty}}" userInput="We couldn't find any records." stepKey="assertDataGridEmptyMessage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ class SearchTest extends WebapiAbstract
*/
private $product;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$productSku = 'simple';

$objectManager = Bootstrap::getObjectManager();
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
$this->product = $productRepository->get($productSku);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* Tests that webapi call returns response when search criteria is valid.
*
* @magentoApiDataFixture Magento/Catalog/_files/products.php
*/
public function testExistingProductSearch()
public function testExistingProductSearch(): void
{
$productName = $this->product->getName();

Expand All @@ -47,14 +52,16 @@ public function testExistingProductSearch()

self::assertArrayHasKey('search_criteria', $response);
self::assertArrayHasKey('items', $response);
self::assertGreaterThan(0, count($response['items']));
self::assertGreaterThan(1, count($response['items']));
self::assertGreaterThan(0, $response['items'][0]['id']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* Tests that response is empty if invalid data is provided.
*
* @magentoApiDataFixture Magento/Catalog/_files/products.php
*/
public function testNonExistentProductSearch()
public function testNonExistentProductSearch(): void
{
$searchCriteria = $this->buildSearchCriteria('nonExistentProduct');
$serviceInfo = $this->buildServiceInfo($searchCriteria);
Expand Down

0 comments on commit 79b58c9

Please sign in to comment.