Skip to content

Commit 01a1d35

Browse files
author
Oleksandr Manchenko
committed
MTA-550: Re-factor Tests for Assign Promoted Products
- Re-factor up-sell products - Re-factor related products
1 parent e96aff0 commit 01a1d35

35 files changed

+988
-1091
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Crosssell.php

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,10 @@
66

77
namespace Magento\Catalog\Test\Block\Product\ProductList;
88

9-
use Magento\Mtf\Block\Block;
10-
use Magento\Mtf\Client\Locator;
11-
use Magento\Mtf\Fixture\FixtureInterface;
12-
139
/**
1410
* Cross-sell product block on the checkout page.
1511
*/
16-
class Crosssell extends Block
12+
class Crosssell extends PromotedSection
1713
{
18-
/**
19-
* Product item block.
20-
*
21-
* @var string
22-
*/
23-
protected $productItem = 'li.product-item';
24-
25-
/**
26-
* Product item block by product name.
27-
*
28-
* @var string
29-
*/
30-
protected $productItemByName = './/*[contains(@class,"product-item-link") and @title="%s"]/ancestor::li';
31-
32-
/**
33-
* Check whether block is visible.
34-
*
35-
* @return bool
36-
*/
37-
public function isVisible()
38-
{
39-
return $this->_rootElement->isVisible();
40-
}
41-
42-
/**
43-
* Return product item block.
44-
*
45-
* @param FixtureInterface $product
46-
* @return ProductItem
47-
*/
48-
public function getProductItem(FixtureInterface $product)
49-
{
50-
$locator = sprintf($this->productItemByName, $product->getName());
51-
52-
return $this->blockFactory->create(
53-
'Magento\Catalog\Test\Block\Product\ProductList\ProductItem',
54-
['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]
55-
);
56-
}
57-
58-
/**
59-
* Get list of product names.
60-
*
61-
* @return array
62-
*/
63-
public function getProductNames()
64-
{
65-
$productItems = $this->_rootElement->getElements($this->productItem, Locator::SELECTOR_CSS);
66-
$names = [];
67-
68-
foreach ($productItems as $productItem) {
69-
/** @var ProductItem $productItemBlock */
70-
$productItemBlock = $this->blockFactory->create(
71-
'Magento\Catalog\Test\Block\Product\ProductList\ProductItem',
72-
['element' => $productItem]
73-
);
74-
75-
$names[] = $productItemBlock->getProductName();
76-
}
77-
78-
return $names;
79-
}
14+
//
8015
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Product\ProductList;
8+
9+
use Magento\Mtf\Block\Block;
10+
use Magento\Mtf\Client\Locator;
11+
use Magento\Mtf\Fixture\FixtureInterface;
12+
13+
/**
14+
* Base promoted products block.
15+
*/
16+
class PromotedSection extends Block
17+
{
18+
/**
19+
* Product item block.
20+
*
21+
* @var string
22+
*/
23+
protected $productItem = 'li.product-item';
24+
25+
/**
26+
* Product item block by product name.
27+
*
28+
* @var string
29+
*/
30+
protected $productItemByName = './/*[contains(@class,"product-item-link") and @title="%s"]/ancestor::li';
31+
32+
/**
33+
* Check whether block is visible.
34+
*
35+
* @return bool
36+
*/
37+
public function isVisible()
38+
{
39+
return $this->_rootElement->isVisible();
40+
}
41+
42+
/**
43+
* Return product item block.
44+
*
45+
* @param FixtureInterface $product
46+
* @return ProductItem
47+
*/
48+
public function getProductItem(FixtureInterface $product)
49+
{
50+
$locator = sprintf($this->productItemByName, $product->getName());
51+
52+
return $this->blockFactory->create(
53+
'Magento\Catalog\Test\Block\Product\ProductList\ProductItem',
54+
['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]
55+
);
56+
}
57+
58+
/**
59+
* Return list of products.
60+
*
61+
* @return ProductItem[]
62+
*/
63+
public function getProducts()
64+
{
65+
$elements = $this->_rootElement->getElements($this->productItem, Locator::SELECTOR_CSS);
66+
$result = [];
67+
68+
foreach ($elements as $element) {
69+
$result[] = $this->blockFactory->create(
70+
'Magento\Catalog\Test\Block\Product\ProductList\ProductItem',
71+
['element' => $element]
72+
);
73+
}
74+
75+
return $result;
76+
}
77+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Related.php

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,48 @@
66

77
namespace Magento\Catalog\Test\Block\Product\ProductList;
88

9-
use Magento\Mtf\Block\Block;
9+
use Magento\Catalog\Test\Block\Product\ProductList\Related\ProductItem;
1010
use Magento\Mtf\Client\Locator;
11-
use Magento\Mtf\Client\Element\SimpleElement;
11+
use Magento\Mtf\Fixture\FixtureInterface;
1212

1313
/**
14-
* Class Related
15-
* Related product block on the page
14+
* Related products section on the page.
1615
*/
17-
class Related extends Block
16+
class Related extends PromotedSection
1817
{
1918
/**
20-
* Related product locator on the page
19+
* Return product item block.
2120
*
22-
* @var string
21+
* @param FixtureInterface $product
22+
* @return ProductItem
2323
*/
24-
protected $relatedProduct = "//div[normalize-space(div//a)='%s']";
25-
26-
/**
27-
* Checking related product visibility
28-
*
29-
* @param string $productName
30-
* @return bool
31-
*/
32-
public function isRelatedProductVisible($productName)
24+
public function getProductItem(FixtureInterface $product)
3325
{
34-
return $this->getProductElement($productName)->isVisible();
35-
}
26+
$locator = sprintf($this->productItemByName, $product->getName());
3627

37-
/**
38-
* Verify that you can choose the related products
39-
*
40-
* @param string $productName
41-
* @return bool
42-
*/
43-
public function isRelatedProductSelectable($productName)
44-
{
45-
return $this->getProductElement($productName)->find("[name='related_products[]']")->isVisible();
28+
return $this->blockFactory->create(
29+
'Magento\Catalog\Test\Block\Product\ProductList\Related\ProductItem',
30+
['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]
31+
);
4632
}
4733

4834
/**
49-
* Open related product
35+
* Return list of products.
5036
*
51-
* @param string $productName
52-
* @return void
37+
* @return ProductItem[]
5338
*/
54-
public function openRelatedProduct($productName)
39+
public function getProducts()
5540
{
56-
$this->getProductElement($productName)->find('.product.name>a')->click();
57-
}
41+
$elements = $this->_rootElement->getElements($this->productItem, Locator::SELECTOR_CSS);
42+
$result = [];
5843

59-
/**
60-
* Select related product
61-
*
62-
* @param string $productName
63-
* @return void
64-
*/
65-
public function selectProductForAddToCart($productName)
66-
{
67-
$this->getProductElement($productName)
68-
->find("[name='related_products[]']", Locator::SELECTOR_CSS, 'checkbox')
69-
->setValue('Yes');
70-
}
44+
foreach ($elements as $element) {
45+
$result[] = $this->blockFactory->create(
46+
'Magento\Catalog\Test\Block\Product\ProductList\Related\ProductItem',
47+
['element' => $element]
48+
);
49+
}
7150

72-
/**
73-
* Get related product element
74-
*
75-
* @param string $productName
76-
* @return SimpleElement
77-
*/
78-
private function getProductElement($productName)
79-
{
80-
return $this->_rootElement->find(sprintf($this->relatedProduct, $productName), Locator::SELECTOR_XPATH);
51+
return $result;
8152
}
8253
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Product\ProductList\Related;
8+
9+
use Magento\Mtf\Client\Locator;
10+
11+
/**
12+
* Product item block on related products section.
13+
*/
14+
class ProductItem extends \Magento\Catalog\Test\Block\Product\ProductList\ProductItem
15+
{
16+
/**
17+
* Trigger for choose related product.
18+
*
19+
* @var string
20+
*/
21+
protected $triggerChoose = "[name='related_products[]']";
22+
23+
/**
24+
* Verify that you can choose the related products.
25+
*
26+
* @return bool
27+
*/
28+
public function isSelectable()
29+
{
30+
return $this->_rootElement->find($this->triggerChoose)->isVisible();
31+
}
32+
33+
/**
34+
* Choose the related products.
35+
*
36+
* @return void
37+
*/
38+
public function select()
39+
{
40+
$this->_rootElement->find($this->triggerChoose, Locator::SELECTOR_CSS, 'checkbox')->setValue('Yes');
41+
}
42+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Upsell.php

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,10 @@
66

77
namespace Magento\Catalog\Test\Block\Product\ProductList;
88

9-
use Magento\Mtf\Block\Block;
10-
use Magento\Mtf\Client\Locator;
11-
use Magento\Mtf\Client\Element\SimpleElement;
12-
139
/**
14-
* Class Upsell
15-
* Upsell product block on the page
10+
* Up-sell product section on the page.
1611
*/
17-
class Upsell extends Block
12+
class Upsell extends PromotedSection
1813
{
19-
/**
20-
* Upsell product locator on the page
21-
*
22-
* @var string
23-
*/
24-
protected $upsellProduct = "//div[normalize-space(div//a)='%s']";
25-
26-
/**
27-
* Checking upsell product visibility
28-
*
29-
* @param string $productName
30-
* @return bool
31-
*/
32-
public function isUpsellProductVisible($productName)
33-
{
34-
return $this->getProductElement($productName)->isVisible();
35-
}
36-
37-
/**
38-
* Open upsell product
39-
*
40-
* @param string $productName
41-
*/
42-
public function openUpsellProduct($productName)
43-
{
44-
$this->getProductElement($productName)->find('.product.name>a')->click();
45-
}
46-
47-
/**
48-
* Get a the product
49-
*
50-
* @param string $productName
51-
* @return SimpleElement
52-
*/
53-
private function getProductElement($productName)
54-
{
55-
return $this->_rootElement->find(sprintf($this->upsellProduct, $productName), Locator::SELECTOR_XPATH);
56-
}
14+
//
5715
}

0 commit comments

Comments
 (0)