@Test
  public void basicPromptConfirmHandlingAcceptTest() {

    WebElement promptButton;
    WebElement promptResult;

    promptButton = driver.findElement(By.id("promptexample"));
    promptResult = driver.findElement(By.id("promptreturn"));

    assertEquals("pret", promptResult.getText());
    promptButton.click();

    String alertMessage = "I prompt you";

    Alert promptAlert = driver.switchTo().alert();

    if (Driver.currentDriver != Driver.BrowserName.IE) {
      // no point doing this in IE as we know it isn't the actual prompt
      assertEquals(alertMessage, promptAlert.getText());
    }

    promptAlert.accept();

    assertEquals("change me", promptResult.getText());
  }
 private void SpecialNeeds() throws IOException {
   // Click Special Needs
   driver
       .findElement(
           By.xpath(
               "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Special Needs\")]"))
       .click();
   // Select Special Needs
   Select SpecialNeeds = new Select(driver.findElement(By.id("edit-special-needs")));
   // Select Learning Center
   SpecialNeeds.selectByVisibleText("Learning Center");
   // Select Early Syllabus
   SpecialNeeds.selectByVisibleText("Early syllabus");
   // Click Apply
   driver.findElement(By.id("edit-special-needs-apply-filter")).click();
   // Check Result Received or Not
   try {
     assertTrue(
         func.isTextPresent(driver.findElement(By.className("search-total-results")).getText()));
   } catch (Error e) {
     verificationErrors.append(e.toString());
   }
   // Click All Selections
   driver.findElement(By.linkText("Clear All Selections")).click();
 }
Example #3
0
  /**
   * Finds the menu that can be used by the owner to control the participant. Hovers over it. Finds
   * the mute link and mute it. Then checks in the second participant page whether it is muted
   */
  public void ownerMutesParticipantAndCheck() {
    System.err.println("Start ownerMutesParticipantAndCheck.");

    WebDriver owner = ConferenceFixture.getOwner();

    WebElement elem =
        owner.findElement(By.xpath("//div[@class='remotevideomenu']/i[@class='fa fa-angle-down']"));

    Actions action = new Actions(owner);
    action.moveToElement(elem);
    action.perform();

    TestUtils.waitForDisplayedElementByXPath(
        owner, "//ul[@class='popupmenu']/li/a[@class='mutelink']", 5);

    owner.findElement(By.xpath("//ul[@class='popupmenu']/li/a[@class='mutelink']")).click();

    // and now check whether second participant is muted
    TestUtils.waitForElementByXPath(
        ConferenceFixture.getSecondParticipant(),
        "//span[@class='audioMuted']/i[@class='icon-mic-disabled']",
        5);

    action.release();
  }
  @Test(expected = ElementNotVisibleException.class)
  public void throwExceptionWhenInteractingWithInvisibleElement() {
    server.setGetHandler(
        new HttpRequestCallback() {
          @Override
          public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            res.getOutputStream()
                .println(
                    "<!DOCTYPE html>"
                        + "<html>"
                        + "    <head>\n"
                        + "        <title>test</title>\n"
                        + "    </head>\n"
                        + "    <body>\n"
                        + "        <input id=\"visible\">\n"
                        + "        <input style=\"display:none\" id=\"invisible\">\n"
                        + "    </body>"
                        + "</html>");
          }
        });

    WebDriver d = getDriver();
    d.get(server.getBaseUrl());

    WebElement visibleInput = d.findElement(By.id("visible"));
    WebElement invisibleInput = d.findElement(By.id("invisible"));

    String textToType = "text to type";
    visibleInput.sendKeys(textToType);
    assertEquals(textToType, visibleInput.getAttribute("value"));

    invisibleInput.sendKeys(textToType);
  }
  @Test
  public void basicPromptConfirmHandlingDismissTest() {

    WebElement promptButton;
    WebElement promptResult;

    promptButton = driver.findElement(By.id("promptexample"));
    promptResult = driver.findElement(By.id("promptreturn"));

    assertEquals("pret", promptResult.getText());
    promptButton.click();

    String alertMessage = "I prompt you";

    Alert promptAlert = driver.switchTo().alert();

    if (Driver.currentDriver == Driver.BrowserName.IE) {
      // In IE the alert always returns "Script Prompt:" and not the
      // actual prompt text, so this line is just to alert me if the
      // functionality changes
      if (!promptAlert.getText().equals("Script Prompt:")) {
        throw new RuntimeException("IE now does not do Script Prompt");
      }

    } else {
      // only check the alert prompt if not in IE
      assertEquals(alertMessage, promptAlert.getText());
    }

    promptAlert.dismiss();

    assertEquals("pret", promptResult.getText());
  }
  @Test(expected = NoSuchElementException.class)
  public void shouldBeAbleToClickInAFrame() throws InterruptedException {
    WebDriver d = getDriver();

    d.get("http://docs.wpm.neustar.biz/testscript-api/index.html");
    assertEquals("__MAIN_FRAME__", getCurrentFrameName(d));

    d.switchTo().frame("classFrame");
    assertEquals("classFrame", getCurrentFrameName(d));

    // This should cause a reload in the frame "classFrame"
    d.findElement(By.linkText("HttpClient")).click();

    // Wait for new content to load in the frame.
    WebDriverWait wait = new WebDriverWait(d, 10);
    wait.until(ExpectedConditions.titleContains("HttpClient"));

    // Frame should still be "classFrame"
    assertEquals("classFrame", getCurrentFrameName(d));

    // Check if a link "clearCookies()" is there where expected
    assertEquals("clearCookies", d.findElement(By.linkText("clearCookies")).getText());

    // Make sure it was really frame "classFrame" which was replaced:
    // 1. move to the other frame "packageFrame"
    d.switchTo().defaultContent().switchTo().frame("packageFrame");
    assertEquals("packageFrame", getCurrentFrameName(d));
    // 2. the link "clearCookies()" shouldn't be there anymore
    d.findElement(By.linkText("clearCookies"));
  }
 @Test
 public void testSigninNotificador() throws Exception {
   driver.get(baseUrl + "/sincap/");
   driver.findElement(By.id("username")).clear();
   driver.findElement(By.id("username")).sendKeys("222.222.222-22");
   driver.findElement(By.id("password")).clear();
   driver.findElement(By.id("password")).sendKeys("abc123");
   driver.findElement(By.id("botaoLogin")).click();
 }
 private void runScenarioWithUnhandledAlert(String expectedAlertText) {
   driver2.get(pages.alertsPage);
   driver2.findElement(By.id("prompt-with-default")).click();
   try {
     driver2.findElement(By.id("text")).getText();
   } catch (UnhandledAlertException expected) {
   }
   waitFor(elementTextToEqual(driver2, By.id("text"), expectedAlertText));
 }
Example #9
0
	/*
	Given: Logged into a valid account
	When: I look at the navigation bar
	Then: I will see a link for my user profile
	*/
	@Test
	public void testProfile(){
		driver.findElement(By.id("navbar_username")).clear();
		driver.findElement(By.id("navbar_username")).sendKeys("Aytros");
		driver.findElement(By.id("navbar_password")).clear();
		driver.findElement(By.id("navbar_password")).sendKeys("Mystra@428");
		driver.findElement(By.value("Log in")).click();
		String test = driver.findElement(By.linkText("Aytros")).getAttribute("title");
		assertTrue(test.contains("Profile"));
	}
 @Test
 public void testLoginMaster2() throws Exception {
   driver.get(baseUrl + "/login.html");
   driver.findElement(By.name("j_username")).clear();
   driver.findElement(By.name("j_username")).sendKeys("*****@*****.**");
   driver.findElement(By.name("j_password")).clear();
   driver.findElement(By.name("j_password")).sendKeys("master");
   driver.findElement(By.xpath("//input[@value='Login']")).click();
   driver.findElement(By.linkText("Sign out")).click();
 }
 @Test
 public void testBookSearch5() throws Exception {
   driver.get(baseUrl + "/proyectoBiblioteca/");
   new Select(driver.findElement(By.name("type"))).selectByVisibleText("Editorial");
   driver.findElement(By.name("search")).clear();
   driver.findElement(By.name("search")).sendKeys("De Bolsillo");
   driver.findElement(By.xpath("//button[@type='submit']")).click();
   assertEquals(
       "Libros Encontrados", driver.findElement(By.cssSelector("div.panel-heading")).getText());
 }
Example #12
0
  @Test
  public void testSearchFeature() {

    // find search, check if search works by sending a search time, see that results exist

    WebElement element = driver.findElement(By.name("search_block_form"));
    element.sendKeys("Laboon");
    element.sendKeys(Keys.RETURN);
    assert (driver.findElement(By.name("Laboon")) != null); // is it good enough?
  }
Example #13
0
 public void mouseHoverByXpath(String locator) {
   try {
     WebElement element = driver.findElement(By.xpath(locator));
     Actions action = new Actions(driver);
     Actions hover = action.moveToElement(element);
   } catch (Exception ex) {
     System.out.println("First attempt has been done, This is second try");
     WebElement element = driver.findElement(By.cssSelector(locator));
     Actions action = new Actions(driver);
     action.moveToElement(element).perform();
   }
 }
Example #14
0
  private void runImport() {
    System.out.println("Importerer RFMDB dump");

    Select s = new Select(driver.findElement(new By.ByXPath("//select")));
    s.selectByIndex(2);

    driver.findElement(new By.ByXPath("//input[@value='Importer data']")).click();

    selenium.waitForFrameToLoad("content", "30000");

    captureScreenshot();
  }
Example #15
0
 @Test
 public void switchToFrameByElement() {
   WebDriver d = getDriver();
   d.get("http://docs.wpm.neustar.biz/testscript-api/index.html");
   assertEquals("__MAIN_FRAME__", getCurrentFrameName(d));
   d.switchTo().frame(d.findElement(By.name("packageFrame")));
   assertEquals("packageFrame", getCurrentFrameName(d));
   d.switchTo().defaultContent();
   assertEquals("__MAIN_FRAME__", getCurrentFrameName(d));
   d.switchTo().frame(d.findElement(By.name("packageFrame")));
   assertEquals("packageFrame", getCurrentFrameName(d));
 }
Example #16
0
  private void sendEmails() {
    System.out.println("Trying to send 50 batch e-mails");

    selenium.selectFrame("content");

    driver.findElement(new By.ByName("batch_count")).sendKeys("50");
    driver.findElement(new By.ByXPath("//form[@name='activate']")).submit();

    selenium.waitForFrameToLoad("content", "30000");

    captureScreenshot();
  }
 @Test
 public void testMyFirstWebDriver() throws Exception {
   driver.get(baseUrl + "/HotelApp/");
   driver.findElement(By.linkText("New User Register Here")).isDisplayed();
   driver.findElement(By.xpath(".//*[@id='username']")).clear();
   driver.findElement(By.xpath(".//*[@id='username']")).sendKeys("");
   driver.findElement(By.id("password")).clear();
   driver.findElement(By.id("password")).sendKeys("");
   driver.findElement(By.id("login")).click();
   //   actualText = driver.findElement(By.id("username_span")).getText();
   actualText = driver.findElement(By.cssSelector(".login_error")).getText();
   assertEquals(expectedText, actualText);
 }
 private void TypesOfSchool() throws IOException {
   // Click Type of School
   driver.findElement(By.cssSelector("strong")).click();
   // Click Private
   driver.findElement(By.id("edit-public-private-private")).click();
   // Move School Size Slider
   // TODO Slider not working properly
   WebElement Slider1 = driver.findElement(By.id("population_jq_slider"));
   Actions moveSlider1 = new Actions(driver);
   Action action1 = moveSlider1.dragAndDropBy(Slider1, 0, 10).build();
   action1.perform();
   // Select Religious Affiliation
   new Select(driver.findElement(By.id("edit-religious-affiliation")))
       .selectByVisibleText("Church of Christ");
   // Move Tuition Range Slider
   // TODO Slider not working properly
   WebElement Slider2 = driver.findElement(By.id("tuition_range_jq_slider"));
   Actions moveSlider2 = new Actions(driver);
   Action action2 = moveSlider2.dragAndDropBy(Slider2, 0, 10).build();
   action2.perform();
   // Click Apply
   driver.findElement(By.id("edit-type-of-school-apply-filter")).click();
   // Check Result Received or Not
   try {
     assertTrue(
         func.isTextPresent(driver.findElement(By.className("search-total-results")).getText()));
   } catch (Error e) {
     verificationErrors.append(e.toString());
   }
   // Click All Selections
   driver.findElement(By.linkText("Clear All Selections")).click();
 }
  @Test
  @Ignore(
      "I would love for this to work consistently but it fails too often between releases to use as an example")
  public void multiSelectWithUserInteractions() {

    WebElement multiSelect;

    multiSelect = driver.findElement(By.cssSelector("select[multiple='multiple']"));
    List<WebElement> multiSelectOptions = multiSelect.findElements(By.tagName("option"));

    // in real life, clicking on a multi select item without holding down
    // CTRL will deselect all others and select only that one item

    Actions actions = new Actions(driver);

    actions
        .click(multiSelectOptions.get(0))
        .click(multiSelectOptions.get(1))
        .click(multiSelectOptions.get(2))
        .perform();

    clickSubmitButton();

    new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs("Processed Form Details"));

    assertEquals(
        "Expected only 1 match",
        1,
        driver.findElements(By.cssSelector("[id^='_valuemultipleselect']")).size());
  }
 private void SearchButton() throws IOException {
   // Enter Text To Be Search
   driver.findElement(By.id("edit-keys")).clear();
   driver.findElement(By.id("edit-keys")).sendKeys("Abilene");
   // Click Search
   driver.findElement(By.id("edit-submit")).click();
   // Check Result Received or Not
   try {
     assertTrue(
         func.isTextPresent(driver.findElement(By.className("search-total-results")).getText()));
   } catch (Error e) {
     verificationErrors.append(e.toString());
   }
   // Click All Selections
   driver.findElement(By.linkText("Clear All Selections")).click();
 }
  // Q: what happens if I send text to alert?
  // A: ElementNotVisibleException  in Firefox
  // A: in Chrome the text is sent
  @Test
  public void basicAlertHandlingKeysTest() {

    WebElement alertButton;
    WebElement alertResult;

    alertButton = driver.findElement(By.id("alertexamples"));

    alertButton.click();

    String alertMessage = "I am an alert box!";

    assertEquals(alertMessage, driver.switchTo().alert().getText());

    if (Driver.currentDriver == Driver.BrowserName.FIREFOX) {
      try {
        driver.switchTo().alert().sendKeys("Hello keys Accept");
        fail("expected a ElementNotVisibleException thrown");
      } catch (ElementNotVisibleException e) {
        assertTrue("Expected to get an exception", true);
      }
    }

    if (Driver.currentDriver == Driver.BrowserName.GOOGLECHROME) {
      // chrome seems happy to send in text to an alert
      driver.switchTo().alert().sendKeys("Hello keys Accept");
    }

    driver.switchTo().alert().accept();
  }
 /**
  * Returns the whole chat transcript.
  *
  * @return
  */
 public String getTranscript() {
   String divisionName = "logwrapper";
   WebElement chatTranscript = driver.findElement(By.className(divisionName));
   String transcript = chatTranscript.getText();
   transcript = transcript.replaceAll(ConstantTextStrings.STRANGER_TYPING, "").trim();
   return transcript;
 }
  public static void main(String[] args) {
    String baseUrl = "http://newtours.demoaut.com/";
    WebDriver driver = new FirefoxDriver();
    String underConsTitle = "Under Construction: Mercury Tours"; // Creates result string
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    driver.get(baseUrl);
    List<WebElement> linkElements =
        driver.findElements(By.tagName("a")); // Creates lists from <a> tags
    String[] linkTexts = new String[linkElements.size()];
    int i = 0;

    // extract the link texts of each link element
    for (WebElement e : linkElements) {
      linkTexts[i] = e.getText();
      i++;
    }

    // test each link by looping over them
    for (String t : linkTexts) {
      driver.findElement(By.linkText(t)).click();
      if (driver.getTitle().equals(underConsTitle)) {
        System.out.println("\"" + t + "\"" + " is under construction.");
      } else {
        System.out.println(
            "\""
                + t
                + "\"" // print results to console
                + " is working.");
      }
      driver.navigate().back();
    }
    driver.quit();
  }
Example #24
0
  @Ignore(
      value = {ANDROID, IPHONE, OPERA_MOBILE, PHANTOMJS, SAFARI},
      reason = "Android/Iphone/PhantomJS - not tested," + "Opera mobile/Safari - not implemented")
  @NeedsLocalEnvironment
  @Test
  public void canConfigureProxyThroughPACFile() {
    WebServer helloServer =
        createSimpleHttpServer("<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>");
    WebServer pacFileServer =
        createPacfileServer(
            Joiner.on('\n')
                .join(
                    "function FindProxyForURL(url, host) {",
                    "  return 'PROXY " + getHostAndPort(helloServer) + "';",
                    "}"));

    Proxy proxy = new Proxy();
    proxy.setProxyAutoconfigUrl("http://" + getHostAndPort(pacFileServer) + "/proxy.pac");

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(PROXY, proxy);

    WebDriver driver = new WebDriverBuilder().setDesiredCapabilities(caps).get();
    registerDriverTeardown(driver);

    driver.get(pages.mouseOverPage);
    assertEquals(
        "Should follow proxy to another server",
        "Hello, world!",
        driver.findElement(By.tagName("h3")).getText());
  }
Example #25
0
 private boolean isElementPresent(By by) {
   try {
     driver.findElement(by);
     return true;
   } catch (NoSuchElementException e) {
     return false;
   }
 }
Example #26
0
 public boolean elementExists(By locator) {
   try {
     driver.findElement(locator);
   } catch (NoSuchElementException e) {
     return false;
   }
   return true;
 }
Example #27
0
  private void runDownload() {

    System.out.println("Downloader RFMDB dump");

    selenium.selectFrame("content");

    Select s = new Select(driver.findElement(new By.ByXPath("//select")));
    s.selectByVisibleText("Download RFMDB dump");

    selenium.waitForFrameToLoad("content", "30000");

    driver.findElement(new By.ByXPath("//input[@value='Download RFMDB data']")).click();

    selenium.waitForFrameToLoad("content", "30000");

    captureScreenshot();
  }
Example #28
0
  private void login(String user, String passwd) {

    String loginLink = "http://www.orange-scene.dk/typo3";

    System.out.println("Opening: " + loginLink);
    driver.navigate().to(loginLink);

    waitForElementFound(new By.ById("username")).sendKeys(user);

    driver.findElement(new By.ById("password")).sendKeys(passwd);

    driver.findElement(new By.ByName("loginform")).submit();

    selenium.waitForPageToLoad("30000");

    captureScreenshot();
  }
 @Test
 public void testAddCampaign() throws Exception {
   driver.get(baseUrl + "/");
   driver.findElement(By.id("username")).clear();
   driver.findElement(By.id("username")).sendKeys("test");
   driver.findElement(By.id("password")).clear();
   driver.findElement(By.id("password")).sendKeys("test");
   driver.findElement(By.cssSelector("button.btn.btn-default")).click();
   driver.findElement(By.linkText("Campaigns")).click();
   driver.findElement(By.cssSelector("button.btn.btn-default")).click();
   driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
   driver.findElement(By.cssSelector("div.input-group > input.form-control")).clear();
   driver.findElement(By.cssSelector("div.input-group > input.form-control")).sendKeys("test2");
   driver.findElement(By.cssSelector("span.input-group-btn > button.btn.btn-default")).click();
   new Select(driver.findElement(By.cssSelector("select.form-control")))
       .selectByVisibleText("test2");
   driver.findElement(By.xpath("//button[@type='button']")).click();
 }
Example #30
0
  @Test
  public void testWeather() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.linkText("Edmonton")).click();
    for (int second = 0; ; second++) {
      if (second >= 60) fail("timeout");
      try {
        if (isElementPresent(By.id("cityjump"))) break;
      } catch (Exception e) {
      }
      Thread.sleep(1000);
    }

    // Warning: verifyTextPresent may require manual changes
    try {
      assertTrue(
          driver
              .findElement(By.cssSelector("BODY"))
              .getText()
              .matches("^[\\s\\S]*Current Conditions[\\s\\S]*$"));
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    // Warning: verifyTextPresent may require manual changes
    try {
      assertTrue(
          driver
              .findElement(By.cssSelector("BODY"))
              .getText()
              .matches("^[\\s\\S]*Forecast[\\s\\S]*$"));
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    // Warning: verifyTextPresent may require manual changes
    try {
      assertTrue(
          driver
              .findElement(By.cssSelector("BODY"))
              .getText()
              .matches("^[\\s\\S]*Edmonton City Centre Airport[\\s\\S]*$"));
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
  }