Skip to content

Commit 43244ec

Browse files
committed
Productpage ci friendly
1 parent b2f48d9 commit 43244ec

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

src/main/java/com/automation/pages/ProductsPage.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
import org.openqa.selenium.support.ui.ExpectedConditions;
77

88
public class ProductsPage extends BasePage {
9+
10+
911
public ProductsPage(WebDriver driver) {
1012
super(driver);
1113
}
1214

1315
private final By productsNavBtn = By.cssSelector("a[href='/products']");
1416

15-
By continueShoppingBtn = By.xpath("//button[contains(text(),'Continue Shopping')]");
17+
private final By continueShoppingBtn = By.xpath("//button[contains(text(),'Continue Shopping')]");
1618
//driver.findElement(By.xpath("//u[normalize-space()='View Cart']"))
17-
By viewCartBtn = By.xpath("//a[@href='/view_cart']");
19+
private final By viewCartBtn = By.xpath("//a[@href='/view_cart']");
1820

1921
public ProductsPage navigateToProducts() {
2022
driver.findElement(productsNavBtn).click();
@@ -24,21 +26,42 @@ public ProductsPage navigateToProducts() {
2426
//one product at a time
2527
public ProductsPage addProductToCart(int productId) {
2628
By addToCart = By.xpath("//a[@data-product-id='" + productId + "']");
27-
driver.findElement(addToCart).click();
28-
return this;
29+
click(addToCart);
30+
return this;
2931
}
30-
//accepts multiple product ids and adds them to cart
32+
/** without ci accepts multiple product ids and adds them to cart
3133
public ProductsPage addMultipleProducts(int... productIds) {
3234
for (int id : productIds) {
3335
By addToCart = By.xpath("//a[@data-product-id='" + id + "']");
3436
click(addToCart);
35-
wait.until(ExpectedConditions
36-
.visibilityOfElementLocated(continueShoppingBtn));
3737
continueShopping();
3838
3939
}
4040
return this;
4141
}
42+
**/
43+
// Add multiple products (CI SAFE VERSION)
44+
public ProductsPage addMultipleProducts(int... productIds) {
45+
46+
for (int id : productIds) {
47+
48+
By addToCart = By.xpath("//a[@data-product-id='" + id + "']");
49+
50+
// 1. Click product safely
51+
wait.until(ExpectedConditions.elementToBeClickable(addToCart)).click();
52+
53+
// 2. Wait modal appears
54+
wait.until(ExpectedConditions.visibilityOfElementLocated(continueShoppingBtn));
55+
56+
// 3. Click continue shopping safely
57+
wait.until(ExpectedConditions.elementToBeClickable(continueShoppingBtn)).click();
58+
59+
// 4. Wait modal disappears before next iteration (VERY IMPORTANT)
60+
wait.until(ExpectedConditions.invisibilityOfElementLocated(continueShoppingBtn));
61+
}
62+
63+
return this;
64+
}
4265

4366
private void waitForModal() {
4467
wait.until(ExpectedConditions.visibilityOfElementLocated(continueShoppingBtn));

0 commit comments

Comments
 (0)