Java Code Examples for org.openqa.selenium.interactions.Actions

The following are top voted examples for showing how to use org.openqa.selenium.interactions.Actions. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 9 votes vote down vote up
public void click() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)"));
}
 
Example 2
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 8 votes vote down vote up
public void draggedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_DRAGGED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");

    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    tclear();
    System.err.println("============================");
    new Actions(driver).clickAndHold(b).moveToElement(b).release().perform();
    System.err.println("============================");
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 3
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 7 votes vote down vote up
public void releaseGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_RELEASED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 4
Project: syndesis-qe   File: IntegrationFlowViewComponent.java   Source Code and License 7 votes vote down vote up
public void clickAddStepLink(int pos){

		List<WebElement> allStepInserts = getRootElement().findElements(Element.STEP_INSERT);
		WebElement stepElement = allStepInserts.get(pos);
		Actions action = new Actions(WebDriverRunner.getWebDriver());
		//to make ADD_STEP element visible:
		action.moveToElement(stepElement);

		getRootElement().$(Link.ADD_STEP).shouldBe(visible).click();
	}
 
Example 5
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 7 votes vote down vote up
/**
 * Drag and drop an element on top of other element
 * @param targetElement the target element
 */
@Override
@PublicAtsApi
public void dragAndDropTo(
                           HtmlElement targetElement ) {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement source = HiddenHtmlElementLocator.findElement(this);
    WebElement target = HiddenHtmlElementLocator.findElement(targetElement);

    Actions actionBuilder = new Actions(htmlUnitDriver);
    Action dragAndDropAction = actionBuilder.clickAndHold(source)
                                            .moveToElement(target, 1, 1)
                                            .release(target)
                                            .build();
    dragAndDropAction.perform();

    // drops the source element in the middle of the target, which in some cases is not doing drop on the right place
    // new Actions( htmlUnitDriver ).dragAndDrop( source, target ).perform();
}
 
Example 6
Project: BHBot   File: MainThread.java   Source Code and License 7 votes vote down vote up
private void scrollGameIntoView() {
	/*
	 * Bellow code doesn't work well (it does not scroll horizontally):
	 * 
	 * ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", game);
	 */
	Actions actions = new Actions(driver);
	actions.moveToElement(game);
	actions.perform();
}
 
Example 7
Project: teasy   File: BaseTeasyElement.java   Source Code and License 6 votes vote down vote up
private void clickForIgnoredScroll(WebDriverException ignoredOrNeedToScroll) {
    new Report("*****WebDriverException***** during click!-----Locator=" + locator.getBy()).jenkins();
    increment();
    //For Android error text is different and does not have any information related to clickable issue
    String ignoredOrNeedToScrollMessage = ignoredOrNeedToScroll.getMessage();
    if (ignoredOrNeedToScrollMessage.contains("is not clickable at point")) {
        new Report("*****Element is not clickable at point***** during click! Scrolling to element and trying again. ---Locator=" + locator.getBy()).jenkins();

        //This was added to fix cases when scrolling does not affect (in chrome when element is half hidden)
        //There is a chance that maximising will solve the case
        if (repeatLocateElementCounter == 10) {
            maximizeWindow();
            if (isChrome()) {
                //Some pages (e.g. in Administration Workspace) are reloaded after maximize window in Chrome
                waitForSomeTime(3000, "Wait for window maximized");
                againLocate();
            }
        }

        scrollIntoView(wrappedElement);
        scrollToElementLocation(wrappedElement);
    }
    if (ignoredOrNeedToScrollMessage.contains("Error: element is not attached to the page document")) {
        againLocate();
    }
    if (ignoredOrNeedToScrollMessage.contains("unknown error: no element reference returned by script")) {
        againLocate();
        executeScript("arguments[0].click();", wrappedElement);
    } else if (ignoredOrNeedToScrollMessage.contains("Other element would receive the click")) {
        //TODO NT: workaround for 2.49.1
        //If dropdown option element have bigger size then dropdown we get error 'Element is not clickable at point... Other element would receive the click...'
        Actions actions = new Actions(getWebDriver());
        actions
                .moveToElement(wrappedElement, 0, 0)
                .click()
                .perform();
    } else {
        click();
    }
}
 
Example 8
Project: Learning-Spring-Boot-2.0-Second-Edition   File: EndToEndTests.java   Source Code and License 6 votes vote down vote up
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	driver.navigate().back();
}
 
Example 9
Project: Learning-Spring-Boot-2.0-Second-Edition   File: EndToEndTests.java   Source Code and License 6 votes vote down vote up
@Test
public void homePageShouldWork() throws IOException {
	driver.get("http://localhost:" + port);

	takeScreenshot("homePageShouldWork-1");

	assertThat(driver.getTitle())
		.isEqualTo("Learning Spring Boot: Spring-a-Gram");

	String pageContent = driver.getPageSource();

	assertThat(pageContent)
		.contains("<a href=\"/images/bazinga.png/raw\">");

	WebElement element = driver.findElement(
		By.cssSelector("a[href*=\"bazinga.png\"]"));
	Actions actions = new Actions(driver);
	actions.moveToElement(element).click().perform();

	takeScreenshot("homePageShouldWork-2");

	driver.navigate().back();
}
 
Example 10
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 6 votes vote down vote up
private void checkAltRightClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).keyDown(Keys.ALT).contextClick().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
    // Wait till the previous click is processed by the EDT
    Thread.sleep(500);
}
 
Example 11
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 6 votes vote down vote up
private void checkDoubleClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().contains("(2");
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).doubleClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 12
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 6 votes vote down vote up
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 13
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 6 votes vote down vote up
private void checkKeyEvent(int eventToCheck, String keysToSend, int... keysToPress)
        throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("enter-text"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(textField, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(textField, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    for (int keysToPres : keysToPress) {
        r.keyPress(keysToPres);
    }
    for (int i = keysToPress.length - 1; i >= 0; i--) {
        r.keyRelease(keysToPress[i]);
    }
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.sendKeys(keysToSend);
    System.out.println("Expected: " + expected);
    AssertJUnit.assertEquals(expected, t.getText());

    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 14
Project: marathonv5   File: JTreeDynamicTreeTest.java   Source Code and License 6 votes vote down vote up
public void expandTree() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("false", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(root, "expanded", "true"));
    AssertJUnit.assertEquals("true", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    new Actions(driver).doubleClick(node1).perform();
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Child 1", node2.getText());
    WebElement node3 = tree.findElement(By.cssSelector(".::nth-node(4)"));
    AssertJUnit.assertEquals("Child 2", node3.getText());
    WebElement node4 = tree.findElement(By.cssSelector(".::nth-node(5)"));
    AssertJUnit.assertEquals("Parent 2", node4.getText());
    new Actions(driver).doubleClick(node4).perform();
    WebElement node5 = tree.findElement(By.cssSelector(".::nth-node(6)"));
    AssertJUnit.assertEquals("Child 1", node5.getText());
    WebElement node6 = tree.findElement(By.cssSelector(".::nth-node(7)"));
    AssertJUnit.assertEquals("Child 2", node6.getText());
}
 
Example 15
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 6 votes vote down vote up
@Test(enabled = false) public void moveTo() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    new Actions(driver).moveToElement(element1).click().perform();
    buttonMouseActions.setLength(0);
    new Actions(driver).moveToElement(element1).perform();
    AssertJUnit.assertTrue(buttonMouseActions.length() > 0);
    AssertJUnit.assertEquals("moved-", buttonMouseActions.toString());
    new Actions(driver).moveToElement(element1, 10, 10).perform();
    AssertJUnit.assertEquals("moved-moved-", buttonMouseActions.toString());
}
 
Example 16
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 6 votes vote down vote up
public void keysWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            textField.requestFocusInWindow();
        }
    });
    AssertJUnit.assertEquals("", EventQueueWait.call(textField, "getText"));
    WebElement element1 = driver.findElement(By.name("text-field"));
    new Actions(driver).sendKeys(element1, "Hello World").perform();
    AssertJUnit.assertEquals("Hello World", EventQueueWait.call(textField, "getText"));
}
 
Example 17
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 6 votes vote down vote up
public void clickWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(new JavaProfile(), caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)")
            || buttonMouseActions.toString().contains("released(3-popup)"));
}
 
Example 18
Project: marathonv5   File: DragAndDropTest.java   Source Code and License 6 votes vote down vote up
public void dndWithMove() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    driver.clearlogs(LogType.DRIVER);
    System.err.println("About to sleep");
    new Actions(driver).dragAndDrop(listitem1, listitem5).perform();
    waitTillDropCompletes(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
Example 19
Project: marathonv5   File: DragAndDropTest.java   Source Code and License 6 votes vote down vote up
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
Example 20
Project: Cognizant-Intelligent-Test-Scripter   File: CommonMethods.java   Source Code and License 6 votes vote down vote up
@Action(object = ObjectType.SELENIUM, desc = "Drad and drop the element [<Object>] at location [<Data>]", input = InputType.YES)
public void dragAndDropBy() {
    try {
        if (elementPresent()) {
            String[] coords = Data.split(",", 2);
            new Actions(Driver).dragAndDropBy(Element, Integer.parseInt(coords[0]), Integer.parseInt(coords[1]))
                    .build().perform();
            Report.updateTestLog(Action, "Element [" + ObjectName + "] dropped at '"
                    + Data + "' ", Status.PASS);

        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
        }
    } catch (Exception e) {
        Report.updateTestLog(Action, e.getMessage(), Status.DEBUG);
        Logger.getLogger(CommonMethods.class.getName()).log(Level.SEVERE, null, e);
    }

}
 
Example 21
Project: Cognizant-Intelligent-Test-Scripter   File: CommonMethods.java   Source Code and License 6 votes vote down vote up
@Action(object = ObjectType.SELENIUM, desc = "Drops the Dragged Object to [<Object>]")
public void dropElement() {
    if (elementPresent()) {
        if (!getRunTimeElement().empty()) {
            new Actions(Driver)
                    .dragAndDrop(getRunTimeElement().pop(), Element)
                    .build().perform();
            Report.updateTestLog(Action, "Element  dropped to '"
                    + ObjectName + "' ", Status.DONE);
        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, "Drop Target");
        }
    } else {
        throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
    }
}
 
Example 22
Project: marathonv5   File: JMenuTest.java   Source Code and License 6 votes vote down vote up
public void checkBoxMenuItemClick() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));
    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("check-box-menu-item"));
    int i = menuItems.size();
    assertMenuItemClick(menuItems, --i,
            "Event source: Another one (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    WebElement currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));

    new Actions(driver).moveToElement(menu).click().perform();
    assertMenuItemClick(menuItems, --i,
            "Event source: A check box menu item (an instance of JCheckBoxMenuItem)\n    New state: selected\n");
    currRadioButton = menuItems.get(i);
    AssertJUnit.assertEquals("true", currRadioButton.getAttribute("selected"));
}
 
Example 23
Project: marathonv5   File: JMenuTest.java   Source Code and License 6 votes vote down vote up
public void subMenu() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));

    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("menu"));
    int i = 2;
    assertMenuItem(menuItems, i++, "A submenu", "", "83");

    /*
     * NOTE: Clicking on the menu again to ensure that MenuManager sets the
     * state of this menu to closed. Without this call the state of the menu
     * remains open and this test or the next test which clicks on the same
     * menu and perform any actions or request attributes will fail. This
     * behavior is noticed on OSX
     */
    new Actions(driver).moveToElement(menu).click().perform();
}
 
Example 24
Project: Cognizant-Intelligent-Test-Scripter   File: Basic.java   Source Code and License 6 votes vote down vote up
@Action(object = ObjectType.SELENIUM,
        desc = "Move the Browser View to the specified element [<Object>]")
public void moveTo() {
    if (elementDisplayed()) {
        if (Data != null && Data.matches("(\\d)+,(\\d)+")) {
            int x = Integer.valueOf(Data.split(",")[0]);
            int y = Integer.valueOf(Data.split(",")[1]);
            new Actions(Driver).moveToElement(Element, x, y).build().perform();
        } else {
            new Actions(Driver).moveToElement(Element).build().perform();
        }
        Report.updateTestLog(Action, "Viewport moved to" + ObjectName, Status.DONE);
    } else {
        throw new ElementException(ExceptionType.Element_Not_Visible, ObjectName);
    }
}
 
Example 25
Project: ats-framework   File: MobileCheckBox.java   Source Code and License 6 votes vote down vote up
/**
 * Check the check box
 */
@Override
@PublicAtsApi
public void check() {

    new MobileElementState(this).waitToBecomeExisting();

    try {
        WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
        if (!checkboxElement.isSelected()) {
            if (appiumDriver instanceof AndroidDriver) {

                // checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
                new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
            } else {

                checkboxElement.click();
            }
        }
    } catch (Exception se) {
        throw new MobileOperationException(this, "check", se);
    }

    UiEngineUtilities.sleep();
}
 
Example 26
Project: ats-framework   File: MobileCheckBox.java   Source Code and License 6 votes vote down vote up
/**
 * Uncheck the check box
 */
@Override
@PublicAtsApi
public void unCheck() {

    new MobileElementState(this).waitToBecomeExisting();

    try {
        WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
        if (checkboxElement.isSelected()) {
            if (appiumDriver instanceof AndroidDriver) {

                // checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
                new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
            } else {

                checkboxElement.click();
            }
        }
    } catch (Exception se) {
        throw new MobileOperationException(this, "unCheck", se);
    }

    UiEngineUtilities.sleep();
}
 
Example 27
Project: SWET   File: SwetTest.java   Source Code and License 6 votes vote down vote up
@BeforeClass
public static void beforeSuiteMethod() throws Exception {

	// browser selection is hard-coded

	System.err.println("os: " + osName);
	if (osName.startsWith("windows")) {
		driver = BrowserDriver.initialize(browser);
	} else if (osName.startsWith("mac")) {
		driver = BrowserDriver.initialize("safari");
	} else {
		driver = BrowserDriver.initialize("firefox");
	}
	driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
	wait = new WebDriverWait(driver, flexibleWait);
	wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
	actions = new Actions(driver);
}
 
Example 28
Project: hippo   File: GranularityCmsWidget.java   Source Code and License 6 votes vote down vote up
public void addGranularityField() {
    // get element
    WebElement addButton = helper.findElement(By.xpath(ROOT_ELEMENT_XPATH + "//a[contains(@class, 'add-link')]"));

    // scroll to element, to preven errors like "Other element would receive the click"
    new Actions(webDriver)
        .moveToElement(addButton)
        .moveByOffset(0, 200)
        .perform();

    // click
    addButton.click();

    // wait after click for the dropdown to appear
    helper.findElement(By.xpath(DROPDOWN_XPATH));
}
 
Example 29
Project: hippo   File: InformationTypeCmsWidget.java   Source Code and License 6 votes vote down vote up
public void addInformationTypeField() {
    // get element
    WebElement addButton = helper.findElement(By.xpath(ROOT_ELEMENT_XPATH + "//a[contains(@class, 'add-link')]"));

    // scroll to element, to prevent errors like "Other element would receive the click"
    new Actions(webDriver)
        .moveToElement(addButton)
        .moveByOffset(0, 200)
        .perform();

    // click
    addButton.click();

    // wait after click for the dropdown to appear
    helper.findElement(By.xpath(DROPDOWN_XPATH));
}
 
Example 30
Project: Cognizant-Intelligent-Test-Scripter   File: CommonMethods.java   Source Code and License 6 votes vote down vote up
@Action(object = ObjectType.SELENIUM, desc = "drag and drop operation of ", input = InputType.YES)
public void dragToAndDropElement() {
    try {
        String Page = Data.split(":", 2)[0];
        String Object = Data.split(":", 2)[1];
        if (elementPresent()) {
            WebElement DropElement = AObject.findElement(Object, Page);
            if (DropElement != null) {
                new Actions(Driver).dragAndDrop(Element, DropElement)
                        .build().perform();
                Report.updateTestLog(Action, "'" + ObjectName
                        + "' has been dragged and dropped to '" + Object + "'",
                        Status.PASS);
            } else {
                throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Object);
            }
        } else {
            throw new ElementException(ElementException.ExceptionType.Element_Not_Found, ObjectName);
        }
    } catch (Exception e) {
        Report.updateTestLog(Action, e.getMessage(), Status.FAIL);
        Logger.getLogger(CommonMethods.class.getName()).log(Level.SEVERE, e.getMessage(), e);
    }
}
 
Example 31
Project: teasy   File: AbstractPageElement.java   Source Code and License 5 votes vote down vote up
@Deprecated
protected void hoverOverElement(WebElement webElement) {
    maximizeWindow();
    Actions builder = new Actions(getDriver());
    Actions hoverOverWebElement = builder.moveToElement(webElement);
    hoverOverWebElement.perform();
}
 
Example 32
Project: akita   File: DefaultSteps.java   Source Code and License 5 votes vote down vote up
/**
 * Выполняется переход в конец страницы
 */
@И("^совершен переход в конец страницы$")
public void scrollDown() {
    Actions actions = new Actions(getWebDriver());
    actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).build().perform();
    actions.keyUp(Keys.CONTROL).perform();
}
 
Example 33
Project: POM_HYBRID_FRAMEOWRK   File: MouseOperations.java   Source Code and License 5 votes vote down vote up
public static void hoverMouseOnWebElement(WebDriver driver, ExtentTest logger, WebElement element) {
	try {
		Actions action = new Actions(driver);
		action.moveToElement(element).build().perform();
	} catch (Exception e) {
		logger.log(LogStatus.ERROR, "Error hovering over the element</br>" + e.getCause());
	}
}
 
Example 34
Project: phoenix.webui.framework   File: SeleniumKeyBoard.java   Source Code and License 5 votes vote down vote up
@Override
public void enter(Element element)
{
	WebDriver driver = engine.getDriver();
	
	new Actions(driver).keyDown(Keys.ENTER).perform();
}
 
Example 35
Project: marathonv5   File: JScrollBarTest.java   Source Code and License 5 votes vote down vote up
public void getAttributes() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> scrollBars = driver.findElements(By.cssSelector("scroll-bar"));
    WebElement scrollbar = scrollBars.get(0);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(0, 40).click().perform();
    int scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 100);

    scrollbar = scrollBars.get(1);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(80, 0).click().perform();
    scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 10);
}
 
Example 36
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
private void checkAltClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    tclear();
    Point locationButton = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension sizeButton = EventQueueWait.call_noexc(button, "getSize");
    Point locationTextArea = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension sizeTextArea = EventQueueWait.call_noexc(actionsArea, "getSize");

    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(locationButton.x + sizeButton.width / 2 + 1, locationButton.y + sizeButton.height / 2 + 1);
    robot.mouseMove(locationButton.x + sizeButton.width / 2, locationButton.y + sizeButton.height / 2);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = weTextArea.getText();
    tclear();
    System.err.println("================================");
    System.err.println(expected);
    System.err.println("=================================");
    new Actions(driver).moveToElement(weButton).keyDown(Keys.ALT).click().keyUp(Keys.ALT).moveToElement(weTextArea).perform();
    AssertJUnit.assertEquals(expected, weTextArea.getText());
}
 
Example 37
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
public void exitedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_EXITED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");

    String expected = t.getText();
    tclear();
    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).moveToElement(t).keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 38
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).contextClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 39
Project: marathonv5   File: JSliderTest.java   Source Code and License 5 votes vote down vote up
public void getAttributes() throws Throwable {
    driver = new JavaDriver();
    WebElement slider = driver.findElement(By.cssSelector("slider"));
    AssertJUnit.assertEquals("15", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_RIGHT);
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_LEFT);
    AssertJUnit.assertEquals("15", slider.getAttribute("value"));
    slider.sendKeys(Keys.ARROW_UP);
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_DOWN);
    }
    AssertJUnit.assertEquals("1", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_UP);
    }
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_LEFT);
    }
    AssertJUnit.assertEquals("1", slider.getAttribute("value"));

    for (int i = 0; i < 15; i++) {
        slider.sendKeys(Keys.ARROW_RIGHT);
    }
    AssertJUnit.assertEquals("16", slider.getAttribute("value"));

    new Actions(driver).moveToElement(slider).moveByOffset(40, 0).click().perform();
    int sliderValue = Integer.parseInt(slider.getAttribute("value"));
    AssertJUnit.assertTrue(sliderValue > 16);

}
 
Example 40
Project: marathonv5   File: JTreeDynamicTreeTest.java   Source Code and License 5 votes vote down vote up
public void expandANode() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(tree, "rowCount", 3 + ""));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
}
 
Example 41
Project: Cognizant-Intelligent-Test-Scripter   File: CommonMethods.java   Source Code and License 5 votes vote down vote up
@Action(object = ObjectType.SELENIUM,
        desc = "Release the dragged element over the [<Object>] element ")
public void releaseElement() {
    if (elementEnabled()) {
        new Actions(Driver).release(Element).build().perform();
        Report.updateTestLog(Action, "releaseElement action is done", Status.DONE);
    } else {
        throw new ElementException(ElementException.ExceptionType.Element_Not_Enabled, ObjectName);
    }
}
 
Example 42
Project: marathonv5   File: JListXTest.java   Source Code and License 5 votes vote down vote up
public void listMultipleSelect() throws Throwable {
    driver = new JavaDriver();
    WebElement listItem;
    Logger.getLogger(JListXTest.class.getName()).info("List Multiple Select");
    listItem = driver.findElement(By.cssSelector("#list-1::nth-item(21)"));
    WebElement listItem2 = driver.findElement(By.cssSelector("#list-1::nth-item(3)"));
    new Actions(driver).click(listItem).keyDown(Keys.SHIFT).click(listItem2).keyUp(Keys.SHIFT).perform();
    ArrayList<Integer> al = new ArrayList<Integer>();
    int[] selectedIndices = EventQueueWait.call(list, "getSelectedIndices");
    for (int i : selectedIndices) {
        al.add(i);
    }
    assertEquals(al.toString(), driver.findElement(By.cssSelector("#list-1")).getAttribute("selectedIndices"));
}
 
Example 43
Project: Cognizant-Intelligent-Test-Scripter   File: CommonMethods.java   Source Code and License 5 votes vote down vote up
@Action(object = ObjectType.SELENIUM, desc = "Click and hold the [<Object>] element ")
public void clickAndHoldElement() {
    if (elementEnabled()) {
        new Actions(Driver).clickAndHold(Element).build().perform();
        Report.updateTestLog(Action, "Click and hold done", Status.DONE);
    } else {
        throw new ElementException(ElementException.ExceptionType.Element_Not_Enabled, ObjectName);
    }
}
 
Example 44
Project: marathonv5   File: JListXTest.java   Source Code and License 5 votes vote down vote up
public void listCheckoutDragDrop() throws InterruptedException {
    driver = new JavaDriver();
    WebElement listItem, textfield;
    listItem = driver.findElement(By.cssSelector("#list-1::nth-item(6)"));
    textfield = driver.findElement(By.cssSelector("text-field"));
    new Actions(driver).dragAndDrop(listItem, textfield).perform();
    assertEquals("List Item - 6", textfield.getText());
    Thread.sleep(1000);
}
 
Example 45
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 5 votes vote down vote up
public void keys() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            textField.requestFocusInWindow();
        }
    });
    AssertJUnit.assertEquals("", EventQueueWait.call(textField, "getText"));
    WebElement element1 = driver.findElement(By.name("text-field"));
    new Actions(driver).sendKeys(element1, "Hello World").perform();
    AssertJUnit.assertEquals("Hello World", EventQueueWait.call(textField, "getText"));
}
 
Example 46
Project: marathonv5   File: JavaDriverTest.java   Source Code and License 5 votes vote down vote up
public void buttonDownUp() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            button.requestFocusInWindow();
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    buttonMouseActions.setLength(0);
    new Actions(driver).clickAndHold(element1).moveByOffset(10, 10).release().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString().matches(".*dragged.*released.*"));
}
 
Example 47
Project: marathonv5   File: JPopupMenuTest.java   Source Code and License 5 votes vote down vote up
public void getText() throws Throwable {
    driver = new JavaDriver();
    WebElement panel = driver.findElement(By.cssSelector("text-area"));
    AssertJUnit.assertNotNull(panel);
    new Actions(driver).contextClick(panel).perform();
    WebElement menu = driver.findElement(By.cssSelector("popup-menu"));
    AssertJUnit.assertNotNull(menu);
    List<WebElement> items = menu.findElements(By.cssSelector("menu-item"));
    AssertJUnit.assertEquals(2, items.size());
    AssertJUnit.assertEquals("A popup menu item", items.get(0).getText());
    AssertJUnit.assertEquals("Another popup menu item", items.get(1).getText());
    items.get(1).click();
    AssertJUnit.assertEquals(true, panel.getText().contains("Another popup menu"));
}
 
Example 48
Project: marathonv5   File: JMenuTest.java   Source Code and License 5 votes vote down vote up
public void menuItemClicks() throws Throwable {
    driver = new JavaDriver();
    WebElement menu = driver.findElement(By.cssSelector("menu"));
    AssertJUnit.assertEquals("A Menu", menu.getText());
    new Actions(driver).moveToElement(menu).click().perform();

    List<WebElement> menuItems = driver.findElements(By.cssSelector("menu-item"));
    int i = 0;
    assertMenuItemClick(menuItems, i++, "A text-only menu item (an instance of JMenuItem)\n");
    new Actions(driver).moveToElement(menu).click().perform();
    assertMenuItemClick(menuItems, i++, "Both text and icon (an instance of JMenuItem)\n");
    new Actions(driver).moveToElement(menu).click().perform();
    assertMenuItemClick(menuItems, i++, "Event source:  (an instance of JMenuItem)\n");
}
 
Example 49
Project: dashboard1b   File: SeleniumUtils.java   Source Code and License 5 votes vote down vote up
static public void clickSubopcionMenuHover(WebDriver driver, String submenu, String opcionclick)
{
	//Pasamos el raton por el submenu de Gestion de alumnos	para
	//que aparezca el menu desplegable
	Actions builder = new Actions(driver);
	WebElement hoverElement = driver.findElement(By.id(submenu));
	builder.moveToElement(hoverElement).perform();		
	//Pinchamos la opcion opcionclick
	By locator = By.id(opcionclick);
	driver.findElement(locator).click();			
}
 
Example 50
Project: dashboard1b   File: SeleniumUtils.java   Source Code and License 5 votes vote down vote up
static public void ClickSubopcionMenuHover(WebDriver driver, String submenu, String opcionclick) {
	// Pasamos el raton por el submenu de Gestion de alumnos para
	// que aparezca el menu desplegable
	Actions builder = new Actions(driver);
	WebElement hoverElement = driver.findElement(By.id(submenu));
	builder.moveToElement(hoverElement).perform();
	// Pinchamos la opcion opcionclick
	By locator = By.id(opcionclick);
	driver.findElement(locator).click();
}
 
Example 51
Project: cerebro   File: Utils.java   Source Code and License 5 votes vote down vote up
public static void clickWhenReady(WebDriver driver, WebElement webElement){
    new WebDriverWait(driver,DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(webElement));
    Actions actions = new Actions(driver);
    actions.moveToElement(webElement);
    new WebDriverWait(driver,DEFAULT_WAITING_TIME).until(ExpectedConditions.elementToBeClickable(webElement));
    webElement.click();
}
 
Example 52
Project: cucumber-framework-java   File: ControllerBase.java   Source Code and License 5 votes vote down vote up
public void getFocus(String locator) {
    WebElement element = waitForElement(locator);
    if ("input".equals(element.getTagName())) {
        element.sendKeys("");
    } else {
        new Actions(driver).moveToElement(element).perform();

    }
}
 
Example 53
Project: ToDoMVCEmberJS   File: BasicTodoMvcPage.java   Source Code and License 5 votes vote down vote up
@Step("Edit item in search todo box")
public boolean editTodoItem(String itemName, String updatedText){

    WebElement label = driver.findElement(By.xpath("//label[.='" + itemName + "']"));
    Assert.assertTrue(label.isDisplayed());
    actions = new Actions(driver);
    actions.doubleClick(label).build().perform();
    editTodo.clear();
    editTodo.sendKeys(updatedText);
    editTodo.sendKeys(Keys.ENTER);
    return driver.findElement(By.xpath("//label[.='" + updatedText + "']")).isDisplayed();
}
 
Example 54
Project: SilkAppDriver   File: NotepadDemoTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testActionAPI() {
	WebElement textField = driver.findElement(By.xpath("//TextField"));
	textField.sendKeys("hello");
	
	Actions actions = new Actions(driver);

	actions.moveByOffset(100, 100).moveByOffset(10, 10).click().perform();
}
 
Example 55
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Set the content of the element
 * @param content the new content
 */
@PublicAtsApi
public void setTextContent(
                            String content ) {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);
    new Actions(htmlUnitDriver).sendKeys(element, content).perform();
}
 
Example 56
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Simulate mouse right click action
 */
@Override
@PublicAtsApi
public void rightClick() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);

    new Actions(htmlUnitDriver).contextClick(element).perform();
}
 
Example 57
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Simulate Enter key
 */
@Override
@PublicAtsApi
public void pressEnterKey() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);
    new Actions(htmlUnitDriver).sendKeys(element, "\r").perform();
    //        new Actions( htmlUnitDriver ).sendKeys( element, Keys.RETURN ).perform();
}
 
Example 58
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Simulate Space key
 */
@Override
@PublicAtsApi
public void pressSpaceKey() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);
    new Actions(htmlUnitDriver).sendKeys(element, Keys.SPACE).perform();
}
 
Example 59
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Simulate Tab key
 */
@Override
@PublicAtsApi
public void pressTabKey() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);
    new Actions(htmlUnitDriver).sendKeys(element, Keys.TAB).perform();
}
 
Example 60
Project: ats-framework   File: HiddenHtmlElement.java   Source Code and License 5 votes vote down vote up
/**
 * Simulate Escape key
 */
@Override
@PublicAtsApi
public void pressEscapeKey() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    WebElement element = HiddenHtmlElementLocator.findElement(this);
    new Actions(htmlUnitDriver).sendKeys(element, Keys.ESCAPE).perform();
}