Example usage for org.openqa.selenium.interactions Actions clickAndHold

List of usage examples for org.openqa.selenium.interactions Actions clickAndHold

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions clickAndHold.

Prototype

public Actions clickAndHold(WebElement target) 

Source Link

Document

Clicks (without releasing) in the middle of the given element.

Usage

From source file:org.richfaces.ui.extendedDataTable.ITTableState.java

License:Open Source License

@Test
public void table_order_server_side() throws InterruptedException {
    // given//from  www.j  a v a 2s.co  m
    browser.get(contextPath.toExternalForm());
    WebElement column1 = header.findElement(By.cssSelector(".rf-edt-hdr-c.rf-edt-c-column1"));
    WebElement column3 = header.findElement(By.cssSelector(".rf-edt-c-column3 .rf-edt-hdr-c-cnt"));

    Actions builder = new Actions(browser);

    final Action dragAndDrop = builder.clickAndHold(column3).moveToElement(column1).release(column1).build();

    // when / then
    Warp.initiate(new Activity() {
        public void perform() {
            guardAjax(dragAndDrop).perform();
        }
    }).group().observe(request().uri().contains("index")).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;

        @Inject
        IterationTableStateBean bean;

        @AfterPhase(Phase.INVOKE_APPLICATION)
        public void verify_bean_executed() {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            AbstractExtendedDataTable edtComponent = (AbstractExtendedDataTable) facesContext.getViewRoot()
                    .findComponent("myForm").findComponent("edt");
            ExtendedDataTableState tableState = new ExtendedDataTableState(edtComponent);
            String[] expectedOrder = { "column3", "column1", "column2" };
            Assert.assertArrayEquals(expectedOrder, tableState.getColumnsOrder());
        }
    }).execute();

    List<WebElement> columns = browser.findElements(By.cssSelector(".rf-edt-hdr-c"));
    assertThat(columns.get(0).getAttribute("class"), containsString("rf-edt-c-column3"));
    assertThat(columns.get(1).getAttribute("class"), containsString("rf-edt-c-column1"));
    assertThat(columns.get(2).getAttribute("class"), containsString("rf-edt-c-column2"));
}

From source file:org.senchalabs.gwt.gwtdriver.gxt.models.TreeDndTest.java

License:Apache License

@Test
public void testDragAndDrop() {
    Tree t = new Tree(driver, driver.findElement(new ByChained(By.xpath("//body/*"),
            new ByWidget(driver, com.sencha.gxt.widget.core.client.tree.Tree.class))));

    Item root = t.findItemWithText("root");
    root.toggleExpand();//w w w  . j ava  2 s.  c o m
    Assert.assertEquals(2, root.getChildren().size());

    Item foo = root.getChildren().get(0);
    foo.toggleExpand();

    Item bar = foo.getChildren().get(0);
    foo.getElement();
    Actions a = new Actions(driver);
    a.clickAndHold(bar.getElement());
    a.moveToElement(root.getElement());
    a.release();

    a.perform();

    Assert.assertEquals(3, root.getChildren().size());

}

From source file:org.senchalabs.gwt.gwtdriver.gxt.models.TreeDndTest.java

License:Apache License

@Test
public void testDragExpandAndDrop() throws InterruptedException {
    Tree t = new Tree(driver, driver.findElement(new ByChained(By.xpath("//body/*"),
            new ByWidget(driver, com.sencha.gxt.widget.core.client.tree.Tree.class))));

    Item root = t.findItemWithText("root");
    Item other = t.getRootChildren().get(1);

    //drag, still holding
    Actions a = new Actions(driver);
    a.clickAndHold(other.getElement());
    a.moveToElement(root.getElement());/*from ww  w.ja va2s .  co m*/
    a.perform();

    //wait until expanded (800ms by default, wait 1 second)
    Thread.sleep(1000);

    Assert.assertEquals(2, root.getChildren().size());
    Item foo = root.getChildren().get(0);

    a = new Actions(driver);
    a.moveToElement(foo.getElement());
    a.release();
    a.perform();

    Assert.assertEquals(1, t.getRootChildren().size());
    Assert.assertEquals(false, foo.isExpanded());
    Assert.assertEquals(2, root.getChildren().size());

    foo.toggleExpand();
    Assert.assertEquals(2, foo.getChildren().size());
}