/** * Assert configurable product is added to cart together with the proper related product * * @param Product $product * @param Product[] $assigned * @return void */ protected function assertOnTheFrontEnd(Product $product, array $assigned) { /** @var Product $simple2 */ /** @var Product $configurable */ list($simple2, $configurable) = $assigned; //Open up simple1 product page $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->assertEquals($product->getName(), $productPage->getViewBlock()->getProductName()); /** @var \Magento\Catalog\Test\Block\Product\ProductList\Related $relatedBlock */ $relatedBlock = $productPage->getRelatedProductBlock(); //Verify related simple2 and configurable on Simple1 product page $this->assertTrue($relatedBlock->isRelatedProductVisible($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductSelectable($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductVisible($configurable->getName())); $this->assertFalse($relatedBlock->isRelatedProductSelectable($configurable->getName())); //Open and verify configurable page $relatedBlock->openRelatedProduct($configurable->getName()); $this->assertEquals($configurable->getName(), $productPage->getViewBlock()->getProductName()); //Verify related simple2 on Configurable product page and add to cart it $relatedBlock = $productPage->getRelatedProductBlock(); $this->assertTrue($relatedBlock->isRelatedProductVisible($simple2->getName())); $this->assertTrue($relatedBlock->isRelatedProductSelectable($simple2->getName())); $relatedBlock->selectProductForAddToCart($simple2->getName()); $productPage->getViewBlock()->addToCart($configurable); //Verify that both configurable product and simple product 2 are added to shopping cart $checkoutCartPage = Factory::getPageFactory()->getCheckoutCartIndex(); $checkoutCartBlock = $checkoutCartPage->getCartBlock(); $checkoutCartPage->getMessagesBlock()->waitSuccessMessage(); $this->assertTrue($checkoutCartBlock->isProductInShoppingCart($configurable), 'Configurable product was not found in the shopping cart.'); $this->assertTrue($checkoutCartBlock->isProductInShoppingCart($simple2), 'Related product was not found in the shopping cart.'); }
/** * Assert absence product on category page (frontend) * * @param Product $product * @return void */ protected function assertAbsenceOnCategory(Product $product) { //Pages $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); //Steps $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getCategoryName()); //Verification on category product list $productListBlock = $categoryPage->getListProductBlock(); $this->assertFalse($productListBlock->isProductVisible($product->getName())); }
/** * @param Product $product * @param Product[] $assigned * @return void */ protected function assertOnTheFrontEnd(Product $product, array $assigned) { /** @var Product $simple2 */ /** @var Product $configurable */ list($simple2, $configurable) = $assigned; //Open up simple1 product page $productPage = Factory::getPageFactory()->getCatalogProductView(); Factory::getClientBrowser()->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $this->assertEquals($product->getName(), $productPage->getViewBlock()->getProductName()); /** @var \Magento\Catalog\Test\Block\Product\ProductList\Upsell $upsellBlock */ $upsellBlock = $productPage->getUpsellBlock(); //Verify upsell simple2 and configurable on Simple1 product page $this->assertTrue($upsellBlock->isUpsellProductVisible($simple2->getName())); $this->assertTrue($upsellBlock->isUpsellProductVisible($configurable->getName())); //Open and verify configurable page $upsellBlock->openUpsellProduct($configurable->getName()); $this->assertEquals($configurable->getName(), $productPage->getViewBlock()->getProductName()); //Verify upsell simple2 on Configurable product page and open it $upsellBlock = $productPage->getUpsellBlock(); $this->assertTrue($upsellBlock->isUpsellProductVisible($simple2->getName())); $upsellBlock->openUpsellProduct($simple2->getName()); $this->assertEquals($simple2->getName(), $productPage->getViewBlock()->getProductName()); $this->assertFalse($productPage->getUpsellBlock()->isVisible()); }
/** * Assert configurable product on frontend * * @param Product $product * @param ConfigurableProduct $variations * @return void */ protected function assertOnFrontend(Product $product, ConfigurableProduct $variations) { //Pages $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); $productPage = Factory::getPageFactory()->getCatalogProductView(); //Steps $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getNewCategoryName()); //Verification on category product list $productListBlock = $categoryPage->getListProductBlock(); $this->assertTrue($productListBlock->isProductVisible($product->getName()), 'Product is absent on category page.'); //Verification on product detail page $productViewBlock = $productPage->getViewBlock(); $productListBlock->openProductViewPage($product->getName()); $this->assertEquals($product->getName(), $productViewBlock->getProductName(), 'Product name does not correspond to specified.'); $price = $productViewBlock->getPriceBlock()->getPrice(); $this->assertEquals(number_format($product->getProductPrice(), 2), $price, 'Product price does not correspond to specified.'); $pageOptions = $productViewBlock->getOptions($variations); $configurableOptions = []; foreach ($pageOptions['configurable_options'] as $attribute) { $configurableOption = []; foreach ($attribute['options'] as $option) { $configurableOption[] = $option['title']; } $configurableOptions[$attribute['title']] = $configurableOption; } $this->assertEquals($variations->getConfigurableOptions(), $configurableOptions); }
/** * Assert product data on category and product pages * * @param Product $product * @return void */ protected function assertOnCategory($product) { //Pages $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); $productPage = Factory::getPageFactory()->getCatalogProductView(); //Steps $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getCategoryName()); //Verification on category product list $productListBlock = $categoryPage->getListProductBlock(); $this->assertTrue($productListBlock->isProductVisible($product->getName())); $productListBlock->openProductViewPage($product->getName()); //Verification on product detail page $productViewBlock = $productPage->getViewBlock(); $this->assertEquals($product->getName(), $productViewBlock->getProductName()); $price = $productViewBlock->getPriceBlock()->getPrice(); $this->assertEquals(number_format($product->getProductPrice(), 2), $price); $productOptionsBlock = $productPage->getViewBlock()->getCustomOptionsBlock(); $fixture = $product->getData('fields/custom_options/value'); $actualOptions = $productOptionsBlock->getOptions($product); $this->assertCount(count($fixture), $actualOptions); $this->assertTrue(isset($actualOptions['custom_options'][$fixture[0]['title']]['options'][0]['title'])); $this->assertEquals($fixture[0]['title'], $actualOptions['custom_options'][$fixture[0]['title']]['title']); }
/** * Assert configurable product on frontend * * @param Product $product * @param ConfigurableProduct $variations * @return void */ protected function assertOnFrontend(Product $product, ConfigurableProduct $variations) { //Pages $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); $productPage = Factory::getPageFactory()->getCatalogProductView(); //Steps $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getNewCategoryName()); //Verification on category product list $productListBlock = $categoryPage->getListProductBlock(); $this->assertTrue($productListBlock->isProductVisible($product->getName()), 'Product is absent on category page.'); //Verification on product detail page $productViewBlock = $productPage->getViewBlock(); $productListBlock->openProductViewPage($product->getName()); $this->assertEquals($product->getName(), $productViewBlock->getProductName(), 'Product name does not correspond to specified.'); $price = $productViewBlock->getProductPrice(); $this->assertEquals(number_format($product->getProductPrice(), 2), $price['price_regular_price'], 'Product price does not correspond to specified.'); $this->assertTrue($productViewBlock->verifyProductOptions($variations), 'Added configurable options are absent.'); }
/** * Click on cross-sell product link * * @param Product $product * @return Element */ public function clickLink($product) { $this->_rootElement->find(sprintf($this->linkSelector, $product->getName()), Locator::SELECTOR_CSS)->click(); }