Commit 84875cf7 authored by Qazi Zain's avatar Qazi Zain

Added A practice test , using Assertion and Explicit wait

parent 08a5f2c4
package FunctionalTesting;
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 Practice {
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 broklebutton= obj.findElement(By.xpath("//div[@class='products-wrapper']/div/div/h4[text()='Brocolli - 1 Kg']/following-sibling::div[@class='stepper-input']/a[@class='increment'][1]"));
WebElement culiFlower = obj.findElement(By.xpath("//div[@class='products-wrapper']/div/div/h4[text()='Cauliflower - 1 Kg']/following-sibling::div[@class='stepper-input']/a[@class='increment'][1]"));
for(int i=1;i<=3;i++)
{ String buttonXPath = "(//div[@class='product-action']/button)[" + i + "]";
button = object.until(ExpectedConditions.elementToBeClickable(By.xpath(buttonXPath)));
if(i==1)
{
int j;
for( j=1;j<=5;j++)
{
object.until(ExpectedConditions.elementToBeClickable(broklebutton));
broklebutton.click();
}
test.assertTrue(j==2,"5 items added in cart");
button.click();
}
else if(i==2)
{
int j;
for(j=1;j<=7;j++)
{
object.until(ExpectedConditions.elementToBeClickable(culiFlower));
culiFlower.click();
}
test.assertFalse(j>3,"If not meets return false");
button.click();
}
}
test.assertAll();
}
}
...@@ -20,13 +20,10 @@ public class WebElementAutomation { ...@@ -20,13 +20,10 @@ public class WebElementAutomation {
WebElement object = obj.findElement(By.cssSelector("select#ctl00_mainContent_DropDownListCurrency")); WebElement object = obj.findElement(By.cssSelector("select#ctl00_mainContent_DropDownListCurrency"));
Select StaticDropDown = new Select(object); Select ob = new Select(object);
StaticDropDown.selectByIndex(2);
System.out.println(StaticDropDown.getFirstSelectedOption().getText());
StaticDropDown.selectByValue("INR");
System.out.println(StaticDropDown.getFirstSelectedOption().getText());
ob.selectByIndex(1);
ob.selectByValue("AED");
//------------------------------------> updated Static DropDown <------------------------------------------- //------------------------------------> updated Static DropDown <-------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment