Академический Документы
Профессиональный Документы
Культура Документы
import java.sql.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;
@Test
public void temperature() {
try {
System.setProperty("webdriver.chrome.driver",
"C:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://weathershopper.pythonanywhere.com/");
String temp =
driver.findElement(By.id("temperature")).getText();
String[] temp_split = temp.split(" ");
int numb = Integer.parseInt(temp_split[0]);
System.out.println(numb);
if (numb>34) {
driver.findElement(By.xpath("//button[contains(text(),'Buy
sunscreens')]")).click();
System.out.println("checkpoint2");
String[] itemsNeeded = { "SPF-30", "SPF-50" };
System.out.println("checkpoint_sunscreen");
mapping(driver, itemsNeeded);
}
else if (numb<19) {
driver.findElement(By.xpath("//button[contains(text(),'Buy
moisturizers')]")).click();
String[] itemsNeeded = { "Almond", "Aloe" };
System.out.println("checkpoint_moisturizer");
mapping(driver, itemsNeeded);
}
else {
System.out.println("Temperature is normal. Stay
hydrated.");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
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 =
Integer.parseInt(product_price);//Convert to Integer
if((list_of_products.get(k).getText().toLowerCase()).contains(items[j].toLowerCase(
))) {
map_final_products_pro.put(Integer.parseInt(list_of_products_price.get(k).getText()
.replaceAll("[^0-9]", "")), list_of_products.get(k).getText());
}
}
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())){
buttons.get(i).click();
}
}
}
Thread.sleep(5000);
addToCart(driver,items,al);
driver.findElement(By.cssSelector("button.thin-text.nav-
link")).click();
WebDriverWait w = new WebDriverWait(driver, 10);
w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[contains(text(
),'Checkout')]")));
int k=0;
for(int i=1;i <= items.length; i++) {
for(int j=1;j<=2;j++) {
WebElement web =
driver.findElement(By.xpath("//table[@class='table table-
striped']//tbody//tr["+i+"]//td["+j+"]"));
if(web.getText().toString().equalsIgnoreCase((String)al.toArray()[k])) {
System.out.println(web.getText().toString()+"
verified");
//assert.assertEquals(actual, expected);
//verify the sum of the prices of products
}
else {
System.out.println("not verified");
}
k++;
}
}
cardPayment(driver);
}
driver.switchTo().frame(0);
WebDriverWait block = new WebDriverWait(driver,10);
WebElement modal =
block.until(ExpectedConditions.visibilityOfElementLocated(By.className("Modal")));
modal.findElement(By.xpath("//input[@placeholder='Email']")).sendKeys("qwerty@gmail
.com");
Thread.sleep(9000);
System.out.println("outside loop");
if(driver.findElement(By.cssSelector("div.Codebox.can-
setfocus.Section-child")).isDisplayed()) {
System.out.println("inside classname loop");
Thread.sleep(9000);
if(driver.findElement(By.className("CodeNotReceived-
actionMessage")).isDisplayed()){
System.out.println("inside inside classname loop");
driver.findElement(By.className("CodeNotReceived-
actionMessage")).click();
}
}
Thread.sleep(5000);
modal.findElement(By.xpath("//input[@placeholder='Card
number']")).sendKeys("4242424242424242");
modal.findElement(By.xpath("//input[@placeholder='MM /
YY']")).sendKeys("09/23");
modal.findElement(By.xpath("//input[@placeholder='CVC']")).sendKeys("363");
modal.findElement(By.xpath("//input[@placeholder='ZIP
Code']")).sendKeys("689121");
modal.findElement(By.className("Checkbox")).click();
modal.findElement(By.xpath("//input[@inputmode='tel']")).sendKeys("9876543210");
modal.findElement(By.xpath("//button[@type='submit']")).click();
paymentSuccess(driver);
}
System.out.println(driver.findElement(By.cssSelector("p.text-
justify")).getText());
driver.close();
}
else {
System.out.println("Oops! Payment Failed");
}
}
}
}