Exemplo n.º 1
0
  @JavascriptEnabled
  @Test
  public void testDragAndDrop() throws InterruptedException {
    driver.get(pages.droppableItems);

    long waitEndTime = System.currentTimeMillis() + 15000;

    while (!isElementAvailable(driver, By.id("draggable"))
        && (System.currentTimeMillis() < waitEndTime)) {
      Thread.sleep(200);
    }

    if (!isElementAvailable(driver, By.id("draggable"))) {
      throw new RuntimeException("Could not find draggable element after 15 seconds.");
    }

    WebElement toDrag = driver.findElement(By.id("draggable"));
    WebElement dropInto = driver.findElement(By.id("droppable"));

    Action holdDrag = getBuilder(driver).clickAndHold(toDrag).build();

    Action move = getBuilder(driver).moveToElement(dropInto).build();

    Action drop = getBuilder(driver).release(dropInto).build();

    holdDrag.perform();
    move.perform();
    drop.perform();

    dropInto = driver.findElement(By.id("droppable"));
    String text = dropInto.findElement(By.tagName("p")).getText();

    assertEquals("Dropped!", text);
  }
Exemplo n.º 2
0
  private void performDragAndDropWithMouse() {
    driver.get(pages.draggableLists);

    WebElement dragReporter = driver.findElement(By.id("dragging_reports"));

    WebElement toDrag = driver.findElement(By.id("rightitem-3"));
    WebElement dragInto = driver.findElement(By.id("sortable1"));

    Action holdItem = getBuilder(driver).clickAndHold(toDrag).build();

    Action moveToSpecificItem =
        getBuilder(driver).moveToElement(driver.findElement(By.id("leftitem-4"))).build();

    Action moveToOtherList = getBuilder(driver).moveToElement(dragInto).build();

    Action drop = getBuilder(driver).release(dragInto).build();

    assertEquals("Nothing happened.", dragReporter.getText());

    try {
      holdItem.perform();
      moveToSpecificItem.perform();
      moveToOtherList.perform();

      String text = dragReporter.getText();
      assertTrue(text, text.matches("Nothing happened. (?:DragOut *)+"));
    } finally {
      drop.perform();
    }
  }
Exemplo n.º 3
0
 public static void performAction(Action action) {
   for (Metrics metric : values()) {
     if (metric.isActive()) {
       action.perform(metric);
     }
   }
 }
 public void runAction(Action f) {
   run(
       operationState -> {
         f.perform(operationState);
         return null;
       });
 }
 public void runOnce(Action f) {
   runOnce(
       Void.class,
       taskState -> {
         f.perform(taskState);
         return null;
       });
 }
Exemplo n.º 6
0
  /*
   * Extracts the requested action and (depending on whether the user is logged in)
   * perform it (or make the user login).
   * @param request
   * @return the next page (the view)
   */
  private String performTheAction(HttpServletRequest request) {
    HttpSession session = request.getSession(true);
    String servletPath = request.getServletPath();
    String action = getActionName(servletPath);

    // System.out.println("servletPath="+servletPath+" requestURI="+request.getRequestURI()+"
    // user="+user);

    // Let the logged in user run his chosen action
    return Action.perform(action, request);
  }
Exemplo n.º 7
0
  @JavascriptEnabled
  @Test
  public void testDoubleClick() {
    driver.get(pages.javascriptPage);

    WebElement toDoubleClick = driver.findElement(By.id("doubleClickField"));

    Action dblClick = getBuilder(driver).doubleClick(toDoubleClick).build();

    dblClick.perform();
    String testFieldContent = shortWait.until(elementValueToEqual(toDoubleClick, "DoubleClicked"));
    assertEquals("Value should change to DoubleClicked.", "DoubleClicked", testFieldContent);
  }
Exemplo n.º 8
0
  @JavascriptEnabled
  @Test
  public void testDoubleClickThenGet() {
    // Fails in ff3 if WebLoadingListener removes browser listener
    driver.get(pages.javascriptPage);

    WebElement toClick = driver.findElement(By.id("clickField"));

    Action dblClick = getBuilder(driver).doubleClick(toClick).build();
    dblClick.perform();

    driver.get(pages.droppableItems);
  }
Exemplo n.º 9
0
 @Override
 protected void continuePreviousActions(Vehicle vehicle, TimeLapse time) {
   synchronized (this) {
     if (pendingVehicleActions.containsKey(vehicle)) {
       final Action action = pendingVehicleActions.get(vehicle);
       action.perform(time);
       if (action.isDone()) {
         pendingVehicleActions.remove(vehicle);
         checkState(!pendingVehicleActions.containsKey(vehicle));
         checkState(vehicleState.get(vehicle) == VehicleState.IDLE);
       }
     }
   }
 }
Exemplo n.º 10
0
  @JavascriptEnabled
  @Ignore({CHROME, IE})
  @Test
  public void testCannotMoveToANullLocator() {
    driver.get(pages.javascriptPage);

    try {
      Action contextClick = getBuilder(driver).moveToElement(null).build();

      contextClick.perform();
      fail("Shouldn't be allowed to click on null element.");
    } catch (IllegalArgumentException expected) {
      // Expected.
    }
  }
Exemplo n.º 11
0
  @JavascriptEnabled
  @Test
  public void testMoveAndClick() {
    driver.get(pages.javascriptPage);

    WebElement toClick = driver.findElement(By.id("clickField"));

    Action contextClick = getBuilder(driver).moveToElement(toClick).click().build();

    contextClick.perform();

    wait.until(elementValueToEqual(toClick, "Clicked"));

    assertEquals("Value should change to Clicked.", "Clicked", toClick.getAttribute("value"));
  }
Exemplo n.º 12
0
  @JavascriptEnabled
  @Test
  public void testContextClick() {
    driver.get(pages.javascriptPage);

    WebElement toContextClick = driver.findElement(By.id("doubleClickField"));

    Action contextClick = getBuilder(driver).contextClick(toContextClick).build();

    contextClick.perform();
    assertEquals(
        "Value should change to ContextClicked.",
        "ContextClicked",
        toContextClick.getAttribute("value"));
  }
Exemplo n.º 13
0
 /** performs PropertiesAction with this node */
 public void properties() {
   propertiesAction.perform(this);
 }
Exemplo n.º 14
0
 public void edit() {
   editAction.perform(this);
 }
Exemplo n.º 15
0
 /** performs ViewAction with this node */
 public void view() {
   viewAction.perform(this);
 }