Search in sources :

Example 6 with Mouse

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

the class fireFoxBrowseStart method test.

public static void test() {
    // Arrange
    // Act
    WebElement bar = driver.findElement(By.cssSelector("section.section-examples div.examples div.box-example-square div.box-body div.br-theme-bars-square"));
    assertTrue(bar.findElements(By.xpath("//a[@data-rating-value]")).size() > 7);
    List<WebElement> ratingElements = bar.findElements(// NOTE: relative
    By.xpath(".//a[@data-rating-value]"));
    // xpath selector
    assertTrue(ratingElements.size() > 0);
    // TODO: test that result set elements are unique ?
    Map<String, WebElement> ratings = ratingElements.stream().collect(Collectors.toMap(o -> o.getAttribute("data-rating-text"), Function.identity()));
    // 
    ratings.keySet().stream().forEach(o -> {
        System.err.println("Mouse over rating: " + o);
        WebElement r = ratings.get(o);
        // hover
        actions.moveToElement(r).build().perform();
        highlight(r);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    });
// Assert
}
Also used : ProfilesIni(org.openqa.selenium.firefox.internal.ProfilesIni) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers(org.hamcrest.CoreMatchers) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) CoreMatchers.endsWith(org.hamcrest.CoreMatchers.endsWith) WebElement(org.openqa.selenium.WebElement) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Locatable(org.openqa.selenium.internal.Locatable) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Matcher(java.util.regex.Matcher) Point(org.openqa.selenium.Point) Map(java.util.Map) Alert(org.openqa.selenium.Alert) Actions(org.openqa.selenium.interactions.Actions) Assert.assertFalse(org.testng.Assert.assertFalse) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Mouse(org.openqa.selenium.interactions.Mouse) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Collectors(java.util.stream.Collectors) 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) SearchContext(org.openqa.selenium.SearchContext) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) InvalidSelectorException(org.openqa.selenium.InvalidSelectorException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CapabilityType(org.openqa.selenium.remote.CapabilityType) Select(org.openqa.selenium.support.ui.Select) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Dimension(org.openqa.selenium.Dimension) Iterator(java.util.Iterator) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) Platform(org.openqa.selenium.Platform) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Assert.assertTrue(org.testng.Assert.assertTrue) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebElement(org.openqa.selenium.WebElement)

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