package intro;
import static [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class temper {
@Test
public void temperature() {
try {
[Link]("[Link]",
"C:\\selenium\\[Link]");
WebDriver driver = new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
[Link]("Browser Invoked and navigated to URL", true);
String temp =
[Link]([Link]("temperature")).getText();
String[] temp_split = [Link](" ");
int numb = [Link](temp_split[0]);
[Link](numb);
if (numb>34) {
[Link]([Link]("//button[contains(text(),'Buy
sunscreens')]")).click();
[Link]("checkpoint2");
String[] itemsNeeded = { "SPF-30", "SPF-50" };
[Link]("checkpoint_sunscreen");
mapping(driver, itemsNeeded);
}
else if (numb<19) {
[Link]([Link]("//button[contains(text(),'Buy
moisturizers')]")).click();
String[] itemsNeeded = { "Almond", "Aloe" };
[Link]("checkpoint_moisturizer");
mapping(driver, itemsNeeded);
}
else {
[Link]("Temperature is normal. Stay
hydrated.");
}
}
catch (Exception e) {
[Link]();
}
}
public void mapping(WebDriver driver, String[] items) throws
InterruptedException {
// Fetch All the Products Text
List<WebElement> list_of_products =
[Link]([Link]("[Link]-space-10"));
List<WebElement> list_of_products_price =
[Link]([Link]("[Link]-space-10~p"));
List<WebElement> buttons =
[Link]([Link]("[Link]-space-10~p~button"));
// Use of HashMap to store Products and Their prices(after
conversion to Integer)
String product_name;
String product_price;
int int_product_price;
int low_price;
HashMap<Integer, String> map_final_products = new
HashMap<Integer, String>();
HashMap<Integer, String> map_final_products_pro = new
HashMap<Integer, String>();
//LinkedHashMap<Integer, String> map_final_products_pro_check =
new LinkedHashMap<Integer, String>();
ArrayList<String> al = new ArrayList<String>();
for(int i=0;i<list_of_products.size();i++) {
product_name = list_of_products.get(i).getText();//Iterate
and fetch product name
product_price =
list_of_products_price.get(i).getText();//Iterate and fetch product price
product_price = product_price.replaceAll("[^0-9]",
"");//Replace anything with space other than numbers
int_product_price =
[Link](product_price);//Convert to Integer
map_final_products.put(int_product_price,product_name);//Add product and
price in HashMap
}
[Link]("Product Name and price fetched from UI and saved in
HashMap as:" + map_final_products.toString(),true);
for(int j = 0; j < [Link]; j++) {
map_final_products_pro.clear();
for (int k=0; k < list_of_products.size(); k++) {
if((list_of_products.get(k).getText().toLowerCase()).contains(items[j].toLowerCase(
))) {
map_final_products_pro.put([Link](list_of_products_price.get(k).getText()
.replaceAll("[^0-9]", "")), list_of_products.get(k).getText());
}
}
//[Link]("Product Name and price fetched from UI and
saved in HashMap as:" + map_final_products_pro.toString(),true);
Set<Integer> allkeys = map_final_products_pro.keySet();
ArrayList<Integer> array_list_values_product_prices = new
ArrayList<Integer>(allkeys);
[Link](array_list_values_product_prices);
low_price = array_list_values_product_prices.get(0);
//[Link]("Low Product Price is: " + low_price + "
Product name is: " + map_final_products_pro.get(low_price),true);
//map_final_products_pro_check.put(low_price,map_final_prod
ucts_pro.get(low_price));
[Link](map_final_products_pro.get(low_price));
[Link]([Link](low_price));
//[Link]("Product Name and price saved in HashMap
as:" + map_final_products_pro_check.toString(),true);
for(int i=0;i<list_of_products.size();i++) {
if(map_final_products_pro.get(low_price).equalsIgnoreCase(list_of_products.get(i).g
etText())){
[Link](i).click();
}
}
}
[Link](5000);
addToCart(driver,items,al);
public void addToCart(WebDriver driver,String[] items,
ArrayList<String> al) throws InterruptedException {
[Link]([Link]("[Link]-
link")).click();
WebDriverWait w = new WebDriverWait(driver, 10);
[Link]([Link]([Link]("//h2[contains(text(
),'Checkout')]")));
int k=0;
for(int i=1;i <= [Link]; i++) {
for(int j=1;j<=2;j++) {
WebElement web =
[Link]([Link]("//table[@class='table table-
striped']//tbody//tr["+i+"]//td["+j+"]"));
if([Link]().toString().equalsIgnoreCase((String)[Link]()[k])) {
[Link]([Link]().toString()+"
verified");
//[Link](actual, expected);
//verify the sum of the prices of products
}
else {
[Link]("not verified");
}
k++;
}
}
cardPayment(driver);
}
public void cardPayment(WebDriver driver) throws InterruptedException
{
[Link]([Link]("//button[@class='stripe-button-
el']//span[contains(text(),'Pay with Card')]")).click();
[Link]().frame(0);
WebDriverWait block = new WebDriverWait(driver,10);
WebElement modal =
[Link]([Link]([Link]("Modal")));
[Link]([Link]("//input[@placeholder='Email']")).sendKeys("qwerty@gmail
.com");
[Link](9000);
[Link]("outside loop");
if([Link]([Link]("[Link]-
[Link]-child")).isDisplayed()) {
[Link]("inside classname loop");
[Link](9000);
if([Link]([Link]("CodeNotReceived-
actionMessage")).isDisplayed()){
[Link]("inside inside classname loop");
[Link]([Link]("CodeNotReceived-
actionMessage")).click();
}
}
[Link](5000);
[Link]([Link]("//input[@placeholder='Card
number']")).sendKeys("4242424242424242");
[Link]([Link]("//input[@placeholder='MM /
YY']")).sendKeys("09/23");
[Link]([Link]("//input[@placeholder='CVC']")).sendKeys("363");
[Link]([Link]("//input[@placeholder='ZIP
Code']")).sendKeys("689121");
[Link]([Link]("Checkbox")).click();
[Link]([Link]("//input[@inputmode='tel']")).sendKeys("9876543210");
[Link]([Link]("//button[@type='submit']")).click();
paymentSuccess(driver);
}
public void paymentSuccess(WebDriver driver) throws
InterruptedException {
[Link](9000);
WebElement heading =
[Link]([Link]("/html[1]/body[1]/div[1]/div[1]/h2[1]"));
if([Link]() != null){
if([Link]().equalsIgnoreCase("Payment Success")) {
[Link]([Link]([Link]("[Link]-
justify")).getText());
[Link]();
}
else {
[Link]("Oops! Payment Failed");
}
}
}
}