Search in sources :

Example 1 with Mouse

use of org.openqa.selenium.interactions.Mouse in project selenium_java by sergueik.

the class SuvianTest method test15_3.

// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.interactions.Mouse
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.interactions.internal.Coordinates
// http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium/selenium-api/2.40.0/org/openqa/selenium/interactions/Mouse.java#Mouse.mouseMove%28org.openqa.selenium.interactions.internal.Coordinates%2Clong%2Clong%29
@Test(enabled = true)
public void test15_3() {
    // Arrange
    driver.get("http://suvian.in/selenium/2.5resize.html");
    WebElement textAreaElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h3 textarea"))));
    assertThat(textAreaElement, notNullValue());
    System.err.println(textAreaElement.getSize().width);
    System.err.println(textAreaElement.getSize().height);
    WebElement lineElement = driver.findElement(By.cssSelector(".container .row .intro-message h3 hr.intro-divider"));
    assertThat(lineElement, notNullValue());
    // Act
    int distance = (lineElement.getSize().width - textAreaElement.getSize().width) / 2;
    highlight(textAreaElement);
    int xOffset = textAreaElement.getSize().getWidth() - 1;
    int yOffset = textAreaElement.getSize().getHeight() - 1;
    Mouse mouse = ((HasInputDevices) driver).getMouse();
    Locatable locatable = (Locatable) textAreaElement;
    Coordinates coords = locatable.getCoordinates();
    System.err.println(String.format("Mouse down at: (%d,%d)", coords.inViewPort().x, coords.inViewPort().y));
    mouse.mouseMove(coords, xOffset, yOffset);
    sleep(1000);
    mouse.mouseDown(coords);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    mouse.mouseUp(coords);
    mouse.click(coords);
    sleep(1000);
}
Also used : Mouse(org.openqa.selenium.interactions.Mouse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) WebElement(org.openqa.selenium.WebElement) Point(org.openqa.selenium.Point) Locatable(org.openqa.selenium.internal.Locatable) Test(org.testng.annotations.Test)

Example 2 with Mouse

use of org.openqa.selenium.interactions.Mouse in project selenium_java by sergueik.

the class SuvianTest method test15_2.

@Test(enabled = true)
public void test15_2() {
    // Arrange
    driver.get("http://suvian.in/selenium/1.1link.html");
    String cssSelector = ".container .row .intro-message h3 a";
    WebElement element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h3 a"))));
    assertTrue(element.getText().equalsIgnoreCase("click here"), element.getText());
    // Act
    highlight(element);
    Mouse mouse = ((HasInputDevices) driver).getMouse();
    Coordinates coords = ((Locatable) element).getCoordinates();
    System.err.println(String.format("Mouse click at: (%-4d, %-4d)", coords.inViewPort().x, coords.inViewPort().y));
    mouse.click(coords);
    // Wait page to load
    try {
        wait.until(ExpectedConditions.urlContains("1.1link_validate.html"));
    } catch (UnreachableBrowserException e) {
    }
    // Assert
    try {
        wait.until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver d) {
                return d.findElement(By.className("intro-message")).getText().contains("Link Successfully clicked");
            }
        });
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Mouse(org.openqa.selenium.interactions.Mouse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebElement(org.openqa.selenium.WebElement) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebDriverException(org.openqa.selenium.WebDriverException) InvalidSelectorException(org.openqa.selenium.InvalidSelectorException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) Locatable(org.openqa.selenium.internal.Locatable) Test(org.testng.annotations.Test)

Example 3 with Mouse

use of org.openqa.selenium.interactions.Mouse in project selenium_java by sergueik.

the class SuvianTest method test14_2.

// https://docs.google.com/a/jazzteam.org/document/d/1PdfKMDfoqFIlF4tN1jKrOf1iZ1rqESy2xVMIj3uuV3g/pub#h.qkrwckq52qpd
// http://sqa.stackexchange.com/questions/14247/how-can-i-get-the-value-of-the-tooltip
@Test(enabled = true)
public void test14_2() {
    // Arrange
    driver.get("http://yuilibrary.com/yui/docs/charts/charts-pie.html");
    WebElement elementWithTooltip = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[contains(@class,'yui3-svgSvgPieSlice')][@fill = '#66007f']"))));
    assertThat(elementWithTooltip, notNullValue());
    WebElement chartTitle = driver.findElement(By.cssSelector("div#doc div.content h1"));
    // Act
    actions.moveToElement(chartTitle).build().perform();
    sleep(100);
    // Assert
    // the tooltip element is present on the page regardless of mouse position,
    // but is not visible.
    assertThat((int) driver.findElements(By.cssSelector("div[class $= 'chart-tooltip']")).stream().filter(o -> {
        return (Boolean) (o.getAttribute("style").indexOf("visibility: hidden;") == -1);
    }).count(), is(0));
    // Act
    actions.moveToElement(elementWithTooltip).build().perform();
    sleep(100);
    // Assert
    List<WebElement> tooltips = driver.findElements(By.xpath("//div[contains(@id, '_tooltip')]"));
    assertThat(tooltips.size(), is(1));
    // TODO: visibility check
    assertThat(tooltips.get(0).getText(), containsString("day: Monday"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) StringUtils(org.apache.commons.lang3.StringUtils) Locatable(org.openqa.selenium.internal.Locatable) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Matcher(java.util.regex.Matcher) Point(org.openqa.selenium.Point) Map(java.util.Map) Method(java.lang.reflect.Method) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) FindBy(org.openqa.selenium.support.FindBy) SoftAssert(org.testng.asserts.SoftAssert) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) Predicate(java.util.function.Predicate) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) Mouse(org.openqa.selenium.interactions.Mouse) Collectors(java.util.stream.Collectors) FindBys(org.openqa.selenium.support.FindBys) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) InvalidSelectorException(org.openqa.selenium.InvalidSelectorException) ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) Select(org.openqa.selenium.support.ui.Select) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LinkedList(java.util.LinkedList) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) ByChained(org.openqa.selenium.support.pagefactory.ByChained) Iterator(java.util.Iterator) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) Consumer(java.util.function.Consumer) Assert.assertTrue(org.testng.Assert.assertTrue) Comparator(java.util.Comparator) Collections(java.util.Collections) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test)

Example 4 with Mouse

use of org.openqa.selenium.interactions.Mouse in project selenium_java by sergueik.

the class SuvianTest method test20_4.

// Attempt #4
@Test(enabled = true)
public void test20_4() {
    // Arrange
    driver.get("http://suvian.in/selenium/2.10dragAndDrop.html");
    WebElement draggableElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h5#drag1 strong"))));
    assertThat(draggableElement, notNullValue());
    assertThat(draggableElement.getText(), containsString("This is a draggable text."));
    WebElement dropElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='div1']"))));
    assertThat(dropElement, notNullValue());
    assertThat(dropElement.getText(), containsString("Drop Here"));
    // Act
    Mouse mouse = ((HasInputDevices) driver).getMouse();
    Coordinates source_coords = ((Locatable) draggableElement).getCoordinates();
    Coordinates target_coords = ((Locatable) dropElement).getCoordinates();
    System.err.println(String.format("Mouse down at: (%-4d, %-4d)", source_coords.inViewPort().x, source_coords.inViewPort().y));
    mouse.mouseDown(source_coords);
    mouse.mouseMove(source_coords, 0, target_coords.inViewPort().y - source_coords.inViewPort().y);
    System.err.println(String.format("Mouse up at: (%-4d, %-4d)", target_coords.inViewPort().x + 10, target_coords.inViewPort().y + 10));
    mouse.mouseUp(target_coords);
    sleep(1000);
    System.err.println("Result: " + dropElement.getAttribute("innerHTML"));
// Assert
}
Also used : Mouse(org.openqa.selenium.interactions.Mouse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) WebElement(org.openqa.selenium.WebElement) Locatable(org.openqa.selenium.internal.Locatable) Test(org.testng.annotations.Test)

Example 5 with Mouse

use of org.openqa.selenium.interactions.Mouse in project selenium_java by sergueik.

the class SuvianTest method test22_4.

// Few failing attempts. Warning: Timing out with Firefox
@Test(enabled = true)
public void test22_4() {
    // Arrange
    driver.get("http://suvian.in/selenium/3.2dragAndDrop.html");
    WebElement draggableElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("drag1"))));
    assertThat(draggableElement, notNullValue());
    assertThat(draggableElement.getAttribute("src"), containsString("img/img_logo.gif"));
    WebElement dropElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='div1']"))));
    assertThat(dropElement, notNullValue());
    // Attempt #3
    Point source_location = draggableElement.getLocation();
    highlight(draggableElement);
    Point target_location = dropElement.getLocation();
    actions.dragAndDropBy(draggableElement, 0, target_location.y - source_location.y).build().perform();
    actions.release().build();
    actions.perform();
    // Attempt #4
    Mouse mouse = ((HasInputDevices) driver).getMouse();
    Coordinates source_coords = ((Locatable) draggableElement).getCoordinates();
    Coordinates target_coords = ((Locatable) dropElement).getCoordinates();
    System.err.println(String.format("Mouse down at: (%-4d, %-4d)", source_coords.inViewPort().x, source_coords.inViewPort().y));
    mouse.mouseDown(source_coords);
    mouse.mouseMove(source_coords, 0, target_location.y - source_location.y);
    System.err.println(String.format("Mouse up at: (%-4d, %-4d)", target_coords.inViewPort().x + 10, target_coords.inViewPort().y + 10));
    mouse.mouseUp(target_coords);
// Assert
}
Also used : Mouse(org.openqa.selenium.interactions.Mouse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) Point(org.openqa.selenium.Point) WebElement(org.openqa.selenium.WebElement) Locatable(org.openqa.selenium.internal.Locatable) Test(org.testng.annotations.Test)

Aggregations

WebElement (org.openqa.selenium.WebElement)6 HasInputDevices (org.openqa.selenium.interactions.HasInputDevices)6 Mouse (org.openqa.selenium.interactions.Mouse)6 Coordinates (org.openqa.selenium.interactions.internal.Coordinates)6 Locatable (org.openqa.selenium.internal.Locatable)6 Test (org.testng.annotations.Test)5 Point (org.openqa.selenium.Point)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2