daily pastebin goal
62%
SHARE
TWEET

Xpanxion Interview Program

CryptoJones Apr 7th, 2016 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package seleniumtest1;
  7.  
  8. import java.text.DateFormatSymbols;
  9. import java.util.List;
  10. import java.util.concurrent.TimeUnit;
  11. import org.openqa.selenium.By;
  12. import org.openqa.selenium.WebDriver;
  13. import org.openqa.selenium.WebElement;
  14. import org.openqa.selenium.firefox.FirefoxDriver;
  15.  
  16. /**
  17.  *
  18.  * @author akclark
  19.  */
  20. public class SeleniumTest1 {
  21.  
  22.     /**
  23.      * @param args the command line arguments
  24.      */
  25.     public static void main(String[] args) {
  26.  
  27.         String[] months = new DateFormatSymbols().getMonths();
  28.         for (int i = 0; i < 12; i++) {
  29.  
  30.             String month = months[i];
  31.             checkImages(month);
  32.             checkEmail(month);
  33.             checkDesc(month);
  34.             checkPrice(month);
  35.  
  36.         }
  37.     }
  38.  
  39.     public static int checkImages(String month) {
  40.         int exitCode;
  41.         int shoeCount = 0;
  42.         String baseURL = "http://shoestore-manheim.rhcloud.com/";
  43.         WebDriver driver = new FirefoxDriver();
  44.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  45.         driver.manage().window().maximize();
  46.         driver.get(baseURL);
  47.         driver.findElement(By.linkText(month)).click();
  48.  
  49.         try {
  50.             List<WebElement> allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li"));
  51.  
  52.             if (allElements.isEmpty()) {
  53.                 System.out.println("No shoes found for " + month);
  54.             }
  55.  
  56.             for (WebElement element : allElements) {
  57.                 shoeCount++;
  58.                 WebElement image = element.findElement(By.tagName("img"));
  59.  
  60.                 if (image.getAttribute("src").length() < 12) {
  61.                     System.out.println("No image Found for shoe # " + shoeCount + " in " + month);
  62.                 }
  63.             }
  64.  
  65.         } finally {
  66.             exitCode = 1;
  67.         }
  68.  
  69.         driver.close();
  70.         return exitCode;
  71.     }
  72.  
  73.     public static int checkDesc(String month) {
  74.         int shoeCount = 0;
  75.         int exitCode;
  76.         String baseURL = "http://shoestore-manheim.rhcloud.com/";
  77.         WebDriver driver = new FirefoxDriver();
  78.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  79.         driver.manage().window().maximize();
  80.         driver.get(baseURL);
  81.         driver.findElement(By.linkText(month)).click();
  82.  
  83.         try {
  84.             List<WebElement> allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li"));
  85.  
  86.             if (allElements.isEmpty()) {
  87.                 System.out.println("No shoes found for " + month);
  88.             }
  89.  
  90.             for (WebElement element : allElements) {
  91.                 shoeCount++;
  92.                 WebElement description = element.findElement(By.className("shoe_description"));
  93.                 if (description.getText().length() < 1) {
  94.                     System.out.println("No Desc Found for shoe # " + shoeCount + " in " + month);
  95.                 }
  96.             }
  97.  
  98.         } finally {
  99.             exitCode = 1;
  100.         }
  101.  
  102.         driver.close();
  103.         return exitCode;
  104.     }
  105.  
  106.     public static int checkPrice(String month) {
  107.         int exitCode;
  108.         int shoeCount = 0;
  109.         String baseURL = "http://shoestore-manheim.rhcloud.com/";
  110.         WebDriver driver = new FirefoxDriver();
  111.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  112.         driver.manage().window().maximize();
  113.         driver.get(baseURL);
  114.         driver.findElement(By.linkText(month)).click();
  115.  
  116.         try {
  117.             List<WebElement> allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li"));
  118.  
  119.             if (allElements.isEmpty()) {
  120.                 System.out.println("No shoes found for " + month);
  121.             }
  122.  
  123.             for (WebElement element : allElements) {
  124.                 shoeCount++;
  125.                 WebElement price = element.findElement(By.className("shoe_price"));
  126.                 if (price.getText().length() < 1) {
  127.                     System.out.println("No price found for shoe # " + shoeCount + " in " + month);
  128.                 }
  129.             }
  130.  
  131.         } finally {
  132.             exitCode = 1;
  133.         }
  134.         driver.close();
  135.         return exitCode;
  136.     }
  137.  
  138.     public static int checkEmail(String month) {
  139.         int exitCode;
  140.         String baseURL = "http://shoestore-manheim.rhcloud.com/";
  141.         WebDriver driver = new FirefoxDriver();
  142.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  143.         driver.manage().window().maximize();
  144.         driver.get(baseURL);
  145.         driver.findElement(By.linkText(month)).click();
  146.         WebElement email = driver.findElement(By.name("email"));
  147.         email.sendKeys("akclark@atbashservices.com");
  148.         email.submit();
  149.         if (driver.getPageSource().contains("Thanks! We will notify you of our new shoes at this email: akclark@atbashservices.com")) {
  150.             exitCode = 0;
  151.         } else {
  152.             exitCode = -1;
  153.         }
  154.         driver.close();
  155.         return exitCode;
  156.     }
  157. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top