/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package seleniumtest1; import java.text.DateFormatSymbols; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; /** * * @author akclark */ public class SeleniumTest1 { /** * @param args the command line arguments */ public static void main(String[] args) { String[] months = new DateFormatSymbols().getMonths(); for (int i = 0; i < 12; i++) { String month = months[i]; checkImages(month); checkEmail(month); checkDesc(month); checkPrice(month); } } public static int checkImages(String month) { int exitCode; int shoeCount = 0; String baseURL = "http://shoestore-manheim.rhcloud.com/"; WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(baseURL); driver.findElement(By.linkText(month)).click(); try { List allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li")); if (allElements.isEmpty()) { System.out.println("No shoes found for " + month); } for (WebElement element : allElements) { shoeCount++; WebElement image = element.findElement(By.tagName("img")); if (image.getAttribute("src").length() < 12) { System.out.println("No image Found for shoe # " + shoeCount + " in " + month); } } } finally { exitCode = 1; } driver.close(); return exitCode; } public static int checkDesc(String month) { int shoeCount = 0; int exitCode; String baseURL = "http://shoestore-manheim.rhcloud.com/"; WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(baseURL); driver.findElement(By.linkText(month)).click(); try { List allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li")); if (allElements.isEmpty()) { System.out.println("No shoes found for " + month); } for (WebElement element : allElements) { shoeCount++; WebElement description = element.findElement(By.className("shoe_description")); if (description.getText().length() < 1) { System.out.println("No Desc Found for shoe # " + shoeCount + " in " + month); } } } finally { exitCode = 1; } driver.close(); return exitCode; } public static int checkPrice(String month) { int exitCode; int shoeCount = 0; String baseURL = "http://shoestore-manheim.rhcloud.com/"; WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(baseURL); driver.findElement(By.linkText(month)).click(); try { List allElements = driver.findElements(By.xpath("//*[@id='shoe_list']/li")); if (allElements.isEmpty()) { System.out.println("No shoes found for " + month); } for (WebElement element : allElements) { shoeCount++; WebElement price = element.findElement(By.className("shoe_price")); if (price.getText().length() < 1) { System.out.println("No price found for shoe # " + shoeCount + " in " + month); } } } finally { exitCode = 1; } driver.close(); return exitCode; } public static int checkEmail(String month) { int exitCode; String baseURL = "http://shoestore-manheim.rhcloud.com/"; WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(baseURL); driver.findElement(By.linkText(month)).click(); WebElement email = driver.findElement(By.name("email")); email.sendKeys("akclark@atbashservices.com"); email.submit(); if (driver.getPageSource().contains("Thanks! We will notify you of our new shoes at this email: akclark@atbashservices.com")) { exitCode = 0; } else { exitCode = -1; } driver.close(); return exitCode; } }