Exemple #1
0
  @JavascriptEnabled
  @Ignore(
      value = {HTMLUNIT, SELENESE, ANDROID, OPERA, OPERA_MOBILE},
      reason = "untested user agents")
  @Test
  public void testChordReveseShiftHomeSelectionDeletes() {
    // FIXME: macs don't have HOME keys, would PGUP work?
    if (Platform.getCurrent().is(Platform.MAC)) {
      return;
    }

    driver.get(pages.javascriptPage);

    WebElement result = driver.findElement(By.id("result"));
    WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("done" + Keys.HOME);
    assertThat(element.getAttribute("value"), is("done"));

    element.sendKeys("" + Keys.SHIFT + "ALL " + Keys.HOME);
    assertThat(element.getAttribute("value"), is("ALL done"));

    element.sendKeys(Keys.DELETE);
    assertThat(element.getAttribute("value"), is("done"));

    element.sendKeys("" + Keys.END + Keys.SHIFT + Keys.HOME);
    assertThat(element.getAttribute("value"), is("done"));
    assertThat( // Note: trailing SHIFT up here
        result.getText().trim(), containsString(" up: 16"));

    element.sendKeys("" + Keys.DELETE);
    assertThat(element.getAttribute("value"), is(""));
  }
Exemple #2
0
  @JavascriptEnabled
  @Ignore(
      value = {HTMLUNIT, SELENESE, ANDROID, OPERA, OPERA_MOBILE},
      reason = "untested user agents")
  @Test
  public void testChordControlHomeShiftEndDelete() {
    // FIXME: macs don't have HOME keys, would PGUP work?
    if (Platform.getCurrent().is(Platform.MAC)) {
      return;
    }

    driver.get(pages.javascriptPage);

    WebElement result = driver.findElement(By.id("result"));
    WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG");

    element.sendKeys(Keys.HOME);
    element.sendKeys("" + Keys.SHIFT + Keys.END);
    assertThat(result.getText(), containsString(" up: 16"));

    element.sendKeys(Keys.DELETE);
    assertThat(element.getAttribute("value"), is(""));
  }
Exemple #3
0
  @JavascriptEnabled
  @Ignore(
      value = {HTMLUNIT, SELENESE, ANDROID, OPERA_MOBILE},
      reason = "untested user agents")
  @Test
  public void testHomeAndEndAndPageUpAndPageDownKeys() {
    // FIXME: macs don't have HOME keys, would PGUP work?
    if (Platform.getCurrent().is(Platform.MAC)) {
      return;
    }

    driver.get(pages.javascriptPage);

    WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys(
        "abc"
            + Keys.HOME
            + "0"
            + Keys.LEFT
            + Keys.RIGHT
            + Keys.PAGE_UP
            + Keys.PAGE_DOWN
            + Keys.END
            + "1"
            + Keys.HOME
            + "0"
            + Keys.PAGE_UP
            + Keys.END
            + "111"
            + Keys.HOME
            + "00");
    assertThat(element.getAttribute("value"), is("0000abc1111"));
  }
Exemple #4
0
  /** Forcibly kills a process, using OS tools like "kill" as a last resort */
  public static int killProcess(Process process) {
    int exitValue;

    // first, wait a second to see if the process will die on it's own (we will likely have asked
    // the process to kill itself just before calling this method
    try {
      exitValue = waitForProcessDeath(process, 1000);
      if (exitValue == 0) {
        return exitValue;
      }
    } catch (Exception e) {
      // no? ok, no biggie, now let's force kill it...
    }

    process.destroy();
    try {
      exitValue = waitForProcessDeath(process, 10000);
    } catch (ProcessStillAliveException ex) {
      if (Platform.getCurrent().is(Platform.WINDOWS)) {
        throw ex;
      }
      try {
        System.out.println("Process didn't die after 10 seconds");
        kill9(process);
        exitValue = waitForProcessDeath(process, 10000);
      } catch (Exception e) {
        System.out.println("Process refused to die after 10 seconds, and couldn't kill9 it");
        e.printStackTrace();
        throw new RuntimeException(
            "Process refused to die after 10 seconds, and couldn't kill9 it: " + e.getMessage(),
            ex);
      }
    }
    return exitValue;
  }
 @JavascriptEnabled
 @Test
 public void testElementInDiv() {
   if (Platform.getCurrent().is(Platform.MAC)) {
     System.out.println("Skipping testElementInDiv on Mac: See issue 2281.");
     return;
   }
   driver.get(pages.dragAndDropPage);
   WebElement img = driver.findElement(By.id("test3"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 100, 100);
   assertEquals(expectedLocation, img.getLocation());
 }
Exemple #6
0
 /** retrieves the pid */
 public static int getProcessId(Process p) {
   if (Platform.getCurrent().is(Platform.WINDOWS)) {
     throw new IllegalStateException("UnixUtils may not be used on Windows");
   }
   try {
     Field f = p.getClass().getDeclaredField("pid");
     f.setAccessible(true);
     Integer pid = (Integer) f.get(p);
     return pid;
   } catch (Exception e) {
     throw new RuntimeException("Couldn't detect pid", e);
   }
 }
Exemple #7
0
  @JavascriptEnabled
  @Ignore(
      value = {HTMLUNIT, SELENESE, ANDROID, OPERA, OPERA_MOBILE},
      reason = "untested user agents")
  @Test
  public void testChordControlCutAndPaste() {
    // FIXME: macs don't have HOME keys, would PGUP work?
    if (Platform.getCurrent().is(Platform.MAC)) {
      return;
    }

    driver.get(pages.javascriptPage);

    WebElement element = driver.findElement(By.id("keyReporter"));
    WebElement result = driver.findElement(By.id("result"));

    String paste = "!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG";
    element.sendKeys(paste);
    assertThat(element.getAttribute("value"), is(paste));

    element.sendKeys(Keys.HOME);
    element.sendKeys("" + Keys.SHIFT + Keys.END);
    assertThat(result.getText().trim(), containsString(" up: 16"));

    element.sendKeys(Keys.CONTROL, "x");
    assertThat(element.getAttribute("value"), is(""));

    element.sendKeys(Keys.CONTROL, "v");
    waitFor(elementValueToEqual(element, paste));

    // Cut the last 3 letters.
    element.sendKeys("" + Keys.LEFT + Keys.LEFT + Keys.LEFT + Keys.SHIFT + Keys.END);

    element.sendKeys(Keys.CONTROL, "x");
    assertThat(element.getAttribute("value"), is(paste.substring(0, paste.length() - 3)));

    // Paste the last 3 letters.
    element.sendKeys(Keys.CONTROL, "v");
    assertThat(element.getAttribute("value"), is(paste));

    element.sendKeys(Keys.HOME);
    element.sendKeys(Keys.CONTROL, "v");
    element.sendKeys(Keys.CONTROL, "v" + "v");
    element.sendKeys(Keys.CONTROL, "v" + "v" + "v");
    assertThat(element.getAttribute("value"), is("EFGEFGEFGEFGEFGEFG" + paste));

    element.sendKeys("" + Keys.END + Keys.SHIFT + Keys.HOME + Keys.NULL + Keys.DELETE);
    assertThat(element.getAttribute("value"), is(""));
  }
Exemple #8
0
  @JavascriptEnabled
  @Ignore(value = {HTMLUNIT, SELENESE, OPERA, ANDROID, OPERA_MOBILE})
  @Test
  public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() {
    driver.get(pages.richTextPage);

    // not tested on mac
    if (Platform.getCurrent().is(Platform.MAC)) {
      return;
    }

    driver.switchTo().frame("editFrame");
    WebElement element = driver.switchTo().activeElement();
    element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT);
    element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!");

    assertEquals("Fishee!", element.getText());
  }
 @JavascriptEnabled
 @Test
 public void testDragAndDrop() throws Exception {
   if (Platform.getCurrent().is(Platform.MAC)) {
     System.out.println("Skipping testDragAndDrop on Mac: See issue 2281.");
     return;
   }
   driver.get(pages.dragAndDropPage);
   WebElement img = driver.findElement(By.id("test1"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 150, 200);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, -50, -25);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, 0, 0);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, 1, -1);
   waitFor(elementLocationToBe(img, expectedLocation));
 }