Advertisement
Raizen

Untitled

May 9th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.util.regex.Pattern;
  2. import java.util.concurrent.TimeUnit;
  3. import org.junit.*;
  4. import static org.junit.Assert.*;
  5. import org.openqa.selenium.*;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7. import org.openqa.selenium.support.ui.Select;
  8.  
  9. public class SeleniumTest {
  10.   private WebDriver driver;
  11.   private String baseUrl;
  12.   private boolean acceptNextAlert = true;
  13.   private StringBuffer verificationErrors = new StringBuffer();
  14.  
  15.   @Before
  16.   public void setUp() throws Exception {
  17.     driver = new FirefoxDriver();
  18.     baseUrl = "https://addons.mozilla.org/";
  19.     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  20.   }
  21.  
  22.   @Test
  23.   public void test() throws Exception {
  24.     driver.navigate().to("https://notepad-plus-plus.org/");
  25.     driver.findElement(By.linkText("download")).click();
  26.   }
  27.  
  28.   @After
  29.   public void tearDown() throws Exception {
  30.     driver.quit();
  31.     String verificationErrorString = verificationErrors.toString();
  32.     if (!"".equals(verificationErrorString)) {
  33.       fail(verificationErrorString);
  34.     }
  35.   }
  36.  
  37.   private boolean isElementPresent(By by) {
  38.     try {
  39.       driver.findElement(by);
  40.       return true;
  41.     } catch (NoSuchElementException e) {
  42.       return false;
  43.     }
  44.   }
  45.  
  46.   private boolean isAlertPresent() {
  47.     try {
  48.       driver.switchTo().alert();
  49.       return true;
  50.     } catch (NoAlertPresentException e) {
  51.       return false;
  52.     }
  53.   }
  54.  
  55.   private String closeAlertAndGetItsText() {
  56.     try {
  57.       Alert alert = driver.switchTo().alert();
  58.       String alertText = alert.getText();
  59.       if (acceptNextAlert) {
  60.         alert.accept();
  61.       } else {
  62.         alert.dismiss();
  63.       }
  64.       return alertText;
  65.     } finally {
  66.       acceptNextAlert = true;
  67.     }
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement