Skip to content

Instantly share code, notes, and snippets.

@leopic
Created April 5, 2013 23:48
Show Gist options
  • Select an option

  • Save leopic/5323535 to your computer and use it in GitHub Desktop.

Select an option

Save leopic/5323535 to your computer and use it in GitHub Desktop.
diff --git a/qa-automation-tests/src/main/java/com/backcountry/component/retail/ProductDetailsPage.java b/qa-automation-tests/src/main/java/com/backcountry/component/retail/ProductDetailsPage.java
index 671ec83..dd072e4 100644
--- a/qa-automation-tests/src/main/java/com/backcountry/component/retail/ProductDetailsPage.java
+++ b/qa-automation-tests/src/main/java/com/backcountry/component/retail/ProductDetailsPage.java
@@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.equalTo;
public class ProductDetailsPage extends BaseComponent {
private static final String ADD_TO_CART_BTN_SELECTOR = ".add-to-cart-btn";
public static final String MAIN_PRODUCT_IMAGE_SELECTOR = "#main_product_image";
+ private static final String BUY_BOX_MODAL_CONTAINER = ".qa-ui-dialog-title-1 ";
+ private static final String BUY_BOX_MODAL_RADIO_NAME = "variant-radio";
public ProductDetailsPage(WebDriver driver, RetailComponentFactory componentFactory) {
super(driver, componentFactory, ".pdp div.page");
@@ -103,47 +105,7 @@ public class ProductDetailsPage extends BaseComponent {
public void fillGiftCertInformation(String name, String email, String message) {
sendKeys("#recipient-name", name);
sendKeys("#recipient-email", email);
- sendKeys("#recipient-message" , message);
- }
-
- public String chooseRandomVariant() {
- click("#product-variant-select-button");
-
- waitFor(elementPresent("#product-variant-select-menu>li>a"));
-
- List<WebElement> descriptions =
- driver.findElements(By.cssSelector("#product-variant-select-menu>li>a"));
-
- try{
- //Just in case...
- Thread.sleep(500);
- }
- catch(Exception e){
- e.printStackTrace();
- }
-
- int variantToSelect = 0;
- if (descriptions.size() > 1) {
- //IE9 & IE10 break if the variant selected is not visible, so we need
- //to verify that the selected variant is visible
- boolean isVariantVisible = false;
- int attempts = 0;
- while(!isVariantVisible && attempts < 10){
- variantToSelect = randomInt(descriptions.size());
- if (variantToSelect == 0) {
- variantToSelect = randomInt(descriptions.size());
- }
- isVariantVisible = descriptions.get(variantToSelect).isDisplayed();
- attempts++;
- }
- if(attempts == 10){
- System.out.println("COULDN'T FIND A VARIANT WITH isDisplayed() = true AFTER 10 ATTEMPTS");
- }
- }
- String result = null;
- result = descriptions.get(variantToSelect).getText();
- descriptions.get(variantToSelect).click();
- return result;
+ sendKeys("#recipient-message" , message);
}
public boolean checkIfTermExists(String term) {
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/manager/UpdateRegularPriceItemEditorTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/manager/UpdateRegularPriceItemEditorTest.java
index 6df96d7..3d2de0d 100755
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/manager/UpdateRegularPriceItemEditorTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/manager/UpdateRegularPriceItemEditorTest.java
@@ -19,7 +19,10 @@ public class UpdateRegularPriceItemEditorTest extends RetailBaseTestCase {
helperFactory().navigationTestHelper().navigateToProduct(sku);
ProductDetailsPage productDetailsPage = withPage().productDetailsPage();
- productDetailsPage.chooseRandomVariant();
+
+ //productDetailsPage.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
String variantValue = productDetailsPage.getSelectedVariant().value;
//1- Log in to manager.backcountry.com
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/manager/VerifyQtyUpdatedInManagerTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/manager/VerifyQtyUpdatedInManagerTest.java
index 4f17ce6..4e6ee87 100755
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/manager/VerifyQtyUpdatedInManagerTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/manager/VerifyQtyUpdatedInManagerTest.java
@@ -26,7 +26,7 @@ public class VerifyQtyUpdatedInManagerTest extends RetailBaseTestCase {
ProductDetailsPage productDetailsPage = withPage().productDetailsPage();
//3) Add random variant to cart
- String variantOriginal = productDetailsPage.chooseRandomVariant();
+ String variantOriginal = helperFactory().buyBoxHelper().chooseRandomVariant();
String variant = variantOriginal.substring(0, variantOriginal.indexOf("(")).trim();
productDetailsPage.clickOnAddToCart();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/PayPalButtonOnCartTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/PayPalButtonOnCartTest.java
index 0f396bb..fd952ee 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/PayPalButtonOnCartTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/PayPalButtonOnCartTest.java
@@ -40,7 +40,8 @@ public class PayPalButtonOnCartTest extends RetailBaseTestCase {
subcategory.clickOnRandomNonTOOSProduct();
ProductDetailsPage productDetails = withPage().productDetailsPage();
- productDetails.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+ //productDetails.chooseRandomVariant();
productDetails.clickOnAddToCart();
withPage().header().clickOnCartLink();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralAddItemWithGiftTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralAddItemWithGiftTest.java
index 73ef1db..a24166f 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralAddItemWithGiftTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralAddItemWithGiftTest.java
@@ -60,7 +60,9 @@ public class GeneralAddItemWithGiftTest extends RetailBaseTestCase {
ProductDetailsPage productDetailsPage = withPage().productDetailsPage();
assertTrue(productDetailsPage.isFreeGiftBoxDisplayed(), "Free Gift box not displayed in PDP");
- productDetailsPage.chooseRandomVariant();
+ //productDetailsPage.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
String giftDescription = removeNewlines(productDetailsPage.getFreeGiftDescription());
String itemSku = productDetailsPage.getProductSKU();
productDetailsPage.clickOnAddToCart();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralContinueShoppingTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralContinueShoppingTest.java
index 49af76c..ee5cdad 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralContinueShoppingTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralContinueShoppingTest.java
@@ -24,7 +24,10 @@ public class GeneralContinueShoppingTest extends RetailBaseTestCase {
subcategory.clickOnRandomNonTOOSProduct();
ProductDetailsPage productDetails = withPage().productDetailsPage();
- productDetails.chooseRandomVariant();
+
+ //productDetails.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
productDetails.clickOnAddToCart();
withPage().header().clickOnCartLink();
} else {
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralItemsInventoryTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralItemsInventoryTest.java
index 27c5bef..3428c85 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralItemsInventoryTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/cartcheckout/simpleCart/GeneralItemsInventoryTest.java
@@ -48,10 +48,15 @@ public class GeneralItemsInventoryTest extends RetailBaseTestCase {
}
ProductDetailsPage productDetails = withPage().productDetailsPage();
- productDetails.chooseRandomVariant();
+
+ //productDetails.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
String itemIdOnPDP = productDetails.getProductSKU();
+
//Step 1.Add Item to Cart
productDetails.clickOnAddToCart();
+
//Step 2.Click on Cart link
withPage().header().clickOnCartLink();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/AddToCartTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/AddToCartTest.java
index 0479bb3..7645293 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/AddToCartTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/AddToCartTest.java
@@ -36,7 +36,10 @@ public class AddToCartTest extends RetailBaseTestCase {
helperFactory().navigationTestHelper().navigateToNonTOOSPdp(productUrl);
ProductDetailsPage pdp = withPage().productDetailsPage();
assertTrue(pdp.isAddToCartVisible(), "Add To Cart button not visible on PDP.");
- pdp.chooseRandomVariant();
+
+ //pdp.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
pdp.clickOnAddToCart();
Cart cartPage = withPage().cart();
assertTrue(cartPage.isCartCurrentPage(), "Not on cart page after add to cart.");
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/BuyBoxTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/BuyBoxTest.java
index 5d231aa..19f5e4b 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/BuyBoxTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/BuyBoxTest.java
@@ -78,18 +78,16 @@ public class BuyBoxTest extends RetailBaseTestCase {
this.gotToProductPage(productUrl);
ProductDetailsPage pdp = withPage().productDetailsPage();
WebElement addToCartButtonWebElement = pdp.getAddToCartElement();
-
- assertTrue(addToCartButtonWebElement.isEnabled(), "Add to cart button should be initially enabled.");
+
CarouselHelper carouselHelper = helperFactory().carouselBoxHelper();
Carousel colorCarousel = pdp.getAvailableColorSelectorCarousel();
carouselHelper.clickOnRandomImage(colorCarousel);
- assertTrue(addToCartButtonWebElement.isEnabled(), "Add to cart button should still be enabled.");
Carousel sizesCarousel = pdp.getAvailableSizeSelectorCarousel();
carouselHelper.clickOnRandomItem(sizesCarousel);
pdp.clickOnAddToCart();
- assertTrue(helperFactory().cartTestHelper().isCartPage(), "Add to cart button should have been enabled and clicking it should have redirected to cart page");
+ assertTrue(helperFactory().cartTestHelper().isCartPage(), "User was not redirected to cart page.");
}
@Test(dataProvider = "getTestData", dataProviderClass = FileDataProvider.class)
diff --git a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/MainImageTest.java b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/MainImageTest.java
index 498de80..6788833 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/MainImageTest.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/tests/retail/pdp/MainImageTest.java
@@ -119,7 +119,9 @@ public class MainImageTest extends RetailBaseTestCase {
String variantOptionSaved;
String sku;
- pdp.chooseRandomVariant();
+ //pdp.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
sku = pdp.getProductSKU();
LOG.debug(sku);// to give more details
variantOptionSaved = pdp.getSelectedVariantByJS();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/util/helper/TestHelperFactory.java b/qa-automation-tests/src/test/java/com/backcountry/util/helper/TestHelperFactory.java
index 48974b8..2527ae5 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/util/helper/TestHelperFactory.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/util/helper/TestHelperFactory.java
@@ -25,6 +25,7 @@ import com.backcountry.util.helper.tests.ProductDetailsPageTestHelper;
import com.backcountry.util.helper.tests.ProductListingTestHelper;
import com.backcountry.util.helper.tests.ProfileHelper;
import com.backcountry.util.helper.tests.SignInPageHelper;
+import com.backcountry.util.helper.tests.BuyBoxHelper;
public class TestHelperFactory {
private RetailComponentFactory factory;
@@ -122,4 +123,8 @@ public class TestHelperFactory {
public CarouselHelper carouselBoxHelper() {
return new CarouselHelper(factory, driver, config, navigationHelper);
}
+
+ public BuyBoxHelper buyBoxHelper() {
+ return new BuyBoxHelper(factory, driver, config, navigationHelper);
+ }
}
diff --git a/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/AddToCartShippingItemTestHelper.java b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/AddToCartShippingItemTestHelper.java
index c610c51..8bedab8 100644
--- a/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/AddToCartShippingItemTestHelper.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/AddToCartShippingItemTestHelper.java
@@ -40,7 +40,9 @@ public class AddToCartShippingItemTestHelper extends BaseTestHelper {
productDetails = factory.productDetailsPage();
}
- productDetails.chooseRandomVariant();
+ //productDetails.chooseRandomVariant();
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+
skuOnPDP = productDetails.getProductSKU();
itemsOnPDP = productDetails.getNumberOfItemsInPDP();
priceOnPDP = productDetails.getItemFullPrice();
diff --git a/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/BuyBoxHelper.java b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/BuyBoxHelper.java
new file mode 100644
index 0000000..65037aa
--- /dev/null
+++ b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/BuyBoxHelper.java
@@ -0,0 +1,93 @@
+package com.backcountry.util.helper.tests;
+
+import com.backcountry.component.retail.factory.RetailComponentFactory;
+import com.backcountry.component.retail.widget.Carousel;
+import com.backcountry.component.retail.ProductDetailsPage;
+import com.backcountry.util.TestConfiguration;
+import com.backcountry.util.helper.NavigationHelper;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import java.util.List;
+
+public class BuyBoxHelper extends BaseTestHelper {
+
+ ProductDetailsPage pdp = getFactory().productDetailsPage();
+
+ public BuyBoxHelper(RetailComponentFactory factory, WebDriver driver, TestConfiguration config, NavigationHelper navigationHelper) {
+ super(factory, driver, config, navigationHelper);
+ }
+
+ public String chooseRandomVariant() {
+ WebElement sizeSelector = driver.findElement(By.cssSelector(".qa-size-selector"));
+
+ if (sizeSelector != null) {
+ return chooseRandomVariantFromAttributeSelector();
+ } else {
+ return chooseRandomVariantFromDropdown();
+ }
+ }
+
+ public String chooseRandomVariantFromAttributeSelector() {
+ String selectedColor;
+ String selectedSize;
+ Carousel colorCarousel = pdp.getAvailableColorSelectorCarousel();
+ List<WebElement> availableSizes = findElements("#product-size-selector .attribute-selector-item");
+
+ helperFactory().carouselBoxHelper().clickOnRandomItem(colorCarousel);
+
+ for (int i = 0; i < availableSizes.size(); i++) {
+ WebElement size = availableSizes.get(i);
+
+ if (size.getAttribute("class").indexOf("inactive") < 0) {
+ size.click();
+ break;
+ }
+ }
+
+ selectedColor = driver.findElement(By.cssSelector("#product-color-selector .selected-attribute-name")).getText();
+ selectedSize = driver.findElement(By.cssSelector("#product-size-selector .selected-attribute-name")).getText();
+
+ return selectedColor + " " + selectedSize;
+ }
+
+ public String chooseRandomVariantFromDropdown() {
+
+ driver.findElement(By.cssSelector("#product-variant-select-button")).click();
+
+ try{
+ // Just in case...
+ Thread.sleep(500);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ List<WebElement> descriptions = driver.findElements(By.cssSelector("#product-variant-select-menu>li>a"));
+
+ int variantToSelect = 0;
+ if (descriptions.size() > 1) {
+ // IE9 & IE10 break if the variant selected is not visible, so we need
+ // to verify that the selected variant is visible.
+ boolean isVariantVisible = false;
+ int attempts = 0;
+ while(!isVariantVisible && attempts < 10){
+ variantToSelect = randomInt(descriptions.size());
+ if (variantToSelect == 0) {
+ variantToSelect = randomInt(descriptions.size());
+ }
+ isVariantVisible = descriptions.get(variantToSelect).isDisplayed();
+ attempts++;
+ }
+ if(attempts == 10){
+ System.out.println("COULDN'T FIND A VARIANT WITH isDisplayed() = true AFTER 10 ATTEMPTS");
+ }
+ }
+ String result = null;
+ result = descriptions.get(variantToSelect).getText();
+ descriptions.get(variantToSelect).click();
+ return result;
+ }
+}
diff --git a/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/NavigationTestHelper.java b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/NavigationTestHelper.java
index 958af6c..0c46d06 100755
--- a/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/NavigationTestHelper.java
+++ b/qa-automation-tests/src/test/java/com/backcountry/util/helper/tests/NavigationTestHelper.java
@@ -15,6 +15,7 @@ import com.backcountry.component.retail.ShippingOptionsOnCart;
import com.backcountry.component.retail.factory.RetailComponentFactory;
import com.backcountry.util.TestConfiguration;
import com.backcountry.util.helper.NavigationHelper;
+import com.backcountry.util.helper.tests.BuyBoxHelper;
public class NavigationTestHelper extends BaseTestHelper {
public NavigationTestHelper(RetailComponentFactory factory, WebDriver driver, TestConfiguration config,
@@ -123,7 +124,10 @@ public class NavigationTestHelper extends BaseTestHelper {
factory.subcategory().clickOnRandomProduct();
productDetails = factory.productDetailsPage();
}
- productDetails.chooseRandomVariant();
+ // COCO!
+ helperFactory().buyBoxHelper().chooseRandomVariant();
+ //productDetails.chooseRandomVariant();
+
skuOnPDP = productDetails.getProductSKU();
priceOnPDP = productDetails.getItemFullPrice();
itemsOnPDP = productDetails.getNumberOfItemsInPDP();
@@ -195,7 +199,9 @@ public class NavigationTestHelper extends BaseTestHelper {
}
productDetails = factory.productDetailsPage();
}
- String selectedOption = productDetails.chooseRandomVariant();
+ // COCO
+ String selectedOption = helperFactory().buyBoxHelper().chooseRandomVariant();
+ //String selectedOption = productDetails.chooseRandomVariant();
itemIdOnPDP = productDetails.getProductSKU();
LOG.debug("Adding the following product to the cart: " + productDetails.getCurrentURL() + " option: "
@@ -349,9 +355,13 @@ public class NavigationTestHelper extends BaseTestHelper {
String itemIdOnPDP;
int quantityOnCart;
- do{
+ do {
productDetails = factory.productDetailsPage();
- String selectedOption = productDetails.chooseRandomVariant();
+
+ // COCO! over here! >>
+ //String selectedOption = productDetails.chooseRandomVariant();
+ String selectedOption = helperFactory().buyBoxHelper().chooseRandomVariant();
+
itemIdOnPDP = productDetails.getProductSKU();
LOG.debug("Adding the following product to the cart: " + productDetails.getCurrentURL() + " option: "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment