Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package automationFramework;
- import java.util.Random;
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- public class FirstTestCase {
- static String [] bar_code= {"00000020","00000030","00000040"};
- static String [] product= {"zapatilla","buzo","camiza"};
- /*
- //Method to validate the correct creation of product
- public static void validate_creation(){
- //First Product
- WebElement search_fp =driver.findElement(By.id("q"));
- search_fp.sendKeys(bar_code[0]);
- //Button:"Find a product"
- driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- //Second Product
- WebElement search_sp =driver.findElement(By.id("q"));
- search_sp.clear();
- search_sp.sendKeys(bar_code[1]);
- driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- //Third Product
- WebElement search_tp =driver.findElement(By.id("q"));
- search_tp.clear();
- search_tp.sendKeys(bar_code[2]);
- driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- }
- */
- public static void main(String[] args) {
- WebDriver driver= new ChromeDriver();
- //Load Chromedriver
- System.setProperty("webdriver.chrome.driver","C:\\Users\\Oing Oing\\Downloads\\ChromeDriver\\chromedriver.exe");
- //Implicit wait, any search for elements on the page could take the time the implicit wait is set for before throwing exception
- driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
- //Launch the Prizy Price Website
- driver.get(" http://tomcat.jcor.com.ar/prizy-pricer/");
- /*
- //Create a new product
- driver.findElement(By.linkText("Create a new Product")).click();
- //First Product
- WebElement fp_barCode =driver.findElement(By.id("barCode"));
- fp_barCode.sendKeys("bar_code[0]");
- WebElement fp_description =driver.findElement(By.id("description"));
- fp_description.sendKeys("product[0]");
- driver.findElement(By.id("create")).click();
- driver.findElement(By.linkText("Nuevo Product")).click();
- //Second Product
- WebElement sp_barCode =driver.findElement(By.id("barCode"));
- sp_barCode.sendKeys("bar_code[1]");
- WebElement sp_description =driver.findElement(By.id("description"));
- sp_description.sendKeys("product[1]");
- driver.findElement(By.id("create")).click();
- driver.findElement(By.linkText("Nuevo Product")).click();
- //Third Product
- WebElement tp_barCode =driver.findElement(By.id("barCode"));
- tp_barCode.sendKeys("bar_code[2]");
- WebElement tp_description =driver.findElement(By.id("description"));
- tp_description.sendKeys("product[2]");
- driver.findElement(By.id("create")).click();
- FirstTestCase.validate_creation();
- //Random Numbers
- Random randomGenerator = new Random();
- //Create a new price to a product
- driver.findElement(By.linkText("Product Loader")).click();
- for(int j=0;j<3;j++){
- for(int i=0;i<10;i++){
- //Select a element in a dropdown list
- String aux="Bar code: "+bar_code[j]+", Description: "+product[j];
- new Select (driver.findElement(By.id("product"))).selectByVisibleText(aux);
- //Insert in input "Store"
- WebElement store = driver.findElement(By.id("store"));
- store.clear();
- store.sendKeys("1");
- int randomInt = randomGenerator.nextInt(100);
- //Insert in input "Price"
- WebElement price = driver.findElement(By.id("price"));
- price.clear();
- price.sendKeys(Integer.toString(randomInt));
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- driver.findElement(By.id("create")).click();
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- driver.findElement(By.linkText("Nuevo Registry")).click();
- }
- }
- */
- //First Product
- WebElement search_fp =driver.findElement(By.id("q"));
- search_fp.sendKeys("00000001");
- //Button:"Find a product"
- driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
- driver.findElement(By.xpath("//*[@id='list-product']/table/tbody/tr/td[1]/a")).click();
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement