package Synchronization; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.asserts.SoftAssert; import java.time.Duration; public class Waits { public static void main(String[] args) { WebDriver obj = new FirefoxDriver(); obj.get("https://rahulshettyacademy.com/seleniumPractise/#/"); WebDriverWait object = new WebDriverWait(obj, Duration.ofSeconds(2)); WebElement button; SoftAssert test= new SoftAssert(); WebElement incrementButton; for(int i=1;i<=6;i++) { String buttonXPath = "(//div[@class='product-action']/button)[" + i + "]"; button = object.until(ExpectedConditions.elementToBeClickable(By.xpath(buttonXPath))); String incrementXpath = "(//a[@class='increment'])["+i+"]"; incrementButton= object.until(ExpectedConditions.elementToBeClickable(By.xpath(incrementXpath))); if(i==1) { int j; for( j=1;j<=5;j++) { incrementButton.click(); } test.assertTrue(j==2,"5 items added in cart"); button.click(); } else if(i==2) { int j; for(j=1;j<=7;j++) { incrementButton.click(); } test.assertFalse(j>3,"If not meets return false"); button.click(); } else if(i==5) { int j; for(j=1;j<=7;j++) { incrementButton.click(); } test.assertFalse(j>3,"If not meets return false"); button.click(); } } WebElement cart = obj.findElement(By.xpath("//div[@class='cart']/a/img")); obj.manage().window().maximize(); object.until(ExpectedConditions.elementToBeClickable(cart)); cart.click(); test.assertAll(); } }