Advertisement
Guest User

qwertyuiop

a guest
Jul 6th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package automationFramework;
  2.  
  3. import java.util.Random;
  4. import java.util.concurrent.TimeUnit;
  5. import org.openqa.selenium.support.ui.Select;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.WebElement;
  9. import org.openqa.selenium.chrome.ChromeDriver;
  10. public class FirstTestCase {
  11.     static String [] bar_code= {"00000020","00000030","00000040"};
  12.     static String [] product= {"zapatilla","buzo","camiza"};
  13.    
  14.     /*
  15.     //Method to validate the correct creation of product
  16.     public static void validate_creation(){
  17.         //First Product
  18.         WebElement search_fp =driver.findElement(By.id("q"));
  19.         search_fp.sendKeys(bar_code[0]);
  20.         //Button:"Find a product"
  21.         driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
  22.         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  23.  
  24.         //Second Product
  25.         WebElement search_sp =driver.findElement(By.id("q"));
  26.         search_sp.clear();
  27.         search_sp.sendKeys(bar_code[1]);
  28.         driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
  29.         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  30.        
  31.         //Third Product
  32.         WebElement search_tp =driver.findElement(By.id("q"));
  33.         search_tp.clear();
  34.         search_tp.sendKeys(bar_code[2]);
  35.         driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
  36.         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);           
  37.     }
  38. */
  39.    
  40.     public static void main(String[] args) {
  41.         WebDriver driver= new ChromeDriver();
  42.         //Load Chromedriver
  43.         System.setProperty("webdriver.chrome.driver","C:\\Users\\Oing Oing\\Downloads\\ChromeDriver\\chromedriver.exe");
  44.        
  45.         //Implicit wait, any search for elements on the page could take the time the implicit wait is set for before throwing exception
  46.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  47.        
  48.         //Launch the Prizy Price Website
  49.         driver.get(" http://tomcat.jcor.com.ar/prizy-pricer/");
  50.        
  51.         /*
  52.         //Create a new product
  53.         driver.findElement(By.linkText("Create a new Product")).click();
  54.        
  55.         //First Product
  56.         WebElement fp_barCode =driver.findElement(By.id("barCode"));
  57.         fp_barCode.sendKeys("bar_code[0]");
  58.         WebElement fp_description =driver.findElement(By.id("description"));
  59.         fp_description.sendKeys("product[0]");
  60.         driver.findElement(By.id("create")).click();
  61.        
  62.         driver.findElement(By.linkText("Nuevo Product")).click();
  63.        
  64.         //Second Product
  65.         WebElement sp_barCode =driver.findElement(By.id("barCode"));
  66.         sp_barCode.sendKeys("bar_code[1]");
  67.         WebElement sp_description =driver.findElement(By.id("description"));
  68.         sp_description.sendKeys("product[1]");
  69.         driver.findElement(By.id("create")).click();
  70.        
  71.         driver.findElement(By.linkText("Nuevo Product")).click();
  72.        
  73.         //Third Product
  74.         WebElement tp_barCode =driver.findElement(By.id("barCode"));
  75.         tp_barCode.sendKeys("bar_code[2]");
  76.         WebElement tp_description =driver.findElement(By.id("description"));
  77.         tp_description.sendKeys("product[2]");
  78.  
  79.         driver.findElement(By.id("create")).click();
  80.        
  81.         FirstTestCase.validate_creation();
  82.        
  83.         //Random Numbers
  84.         Random randomGenerator = new Random();
  85.        
  86.         //Create a new price to a product
  87.         driver.findElement(By.linkText("Product Loader")).click();
  88.        
  89.         for(int j=0;j<3;j++){
  90.             for(int i=0;i<10;i++){
  91.                 //Select a element in a dropdown list
  92.                 String aux="Bar code: "+bar_code[j]+", Description: "+product[j];
  93.                 new Select (driver.findElement(By.id("product"))).selectByVisibleText(aux);
  94.                
  95.                 //Insert in input "Store"
  96.                 WebElement store = driver.findElement(By.id("store"));
  97.                 store.clear();
  98.                 store.sendKeys("1");
  99.                
  100.                 int randomInt = randomGenerator.nextInt(100);
  101.                 //Insert in input "Price"
  102.                 WebElement price = driver.findElement(By.id("price"));
  103.                 price.clear();
  104.                 price.sendKeys(Integer.toString(randomInt));
  105.                
  106.                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  107.                 driver.findElement(By.id("create")).click();
  108.                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  109.                 driver.findElement(By.linkText("Nuevo Registry")).click();
  110.             }
  111.         }
  112.         */
  113.         //First Product
  114.         WebElement search_fp =driver.findElement(By.id("q"));
  115.         search_fp.sendKeys("00000001");
  116.         //Button:"Find a product"
  117.         driver.findElement(By.xpath("//*[@id='productSearchForm']/input[2]")).click();
  118.        
  119.         driver.findElement(By.xpath("//*[@id='list-product']/table/tbody/tr/td[1]/a")).click();
  120.        
  121.         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  122.        
  123.     }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement