Java tutorial
/* * 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 automation; import static com.thoughtworks.selenium.SeleneseTestBase.fail; import java.io.File; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.NoAlertPresentException; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; import utils.FileWriter; /** * * @author motamedi */ public class Zayo extends Launcher implements LauncherInterface { private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); private String cssSelector = ".page > div:nth-child(1) > pre:nth-child(5) > code:nth-child(1)"; public Zayo() { result = "fail"; } public Zayo(String line, String folder) { super(line, folder); } /** * * @param line * @param folder */ @Override public void config(String line, String folder) { configure(line, folder); } /** * * @return */ @Override public String launch() { try { setUp(); test(); tearDown(); } catch (Exception ex) { Logger.getLogger(Zayo.class.getName()).log(Level.SEVERE, null, ex); } return result; } @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "http://lg.zayo.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @Test public void test() throws Exception { System.out.println(dstIP); System.out.println(locVar); driver.get(baseUrl + "lg.cgi"); // ERROR: Caught exception [Error: Dom locators are not implemented yet!] driver.findElement(By.name("protocol")).click(); driver.findElement(By.name("addr")).clear(); driver.findElement(By.name("addr")).sendKeys(dstIP); new Select(driver.findElement(By.name("router"))).selectByVisibleText(locVar); driver.findElement(By.name("submit")).click(); // driver.get(baseUrl + "/"); // driver.findElement(By.id(locVar)).click(); // driver.findElement(By.id("command_traceroute")).click(); // driver.findElement(By.id("raw")).click(); // driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); } @After public void tearDown() throws Exception { try { result = driver.findElement(By.cssSelector(cssSelector)).getAttribute("innerHTML"); } catch (Exception e) { Logger.getLogger(Peer1.class.getName()).log(Level.SEVERE, null, e); } finally { super.store(); driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } } private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } private boolean isAlertPresent() { try { driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } } private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } } }