Skip to content

Commit

Permalink
Merge pull request #239 from FluentLenium/feature/mouseOver1
Browse files Browse the repository at this point in the history
Feature/mouse over1
  • Loading branch information
filipcynarski committed Apr 2, 2016
2 parents be04464 + 13859f5 commit 05ca5b3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ This will submit all the enabled fields returned by the search.
find("#create-button").doubleClick()
```

### Mouse over
```java
find("#create-button").mouseOver()
```

## Events

Selenium has a driver wrapper named `EventFiringWebDriver` that is able to generate events and register listeners.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.fluentlenium.core.action;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class MouseActions {

private final WebDriver webDriver;

public MouseActions(WebDriver webDriver) {
this.webDriver = webDriver;
}

public Action mouseOver(WebElement webElement) {
return new Actions(webDriver).moveToElement(webElement).build();
}

public Action doubleClick(WebElement webElement) {
return new Actions(webDriver).doubleClick(webElement).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.fluentlenium.core.action.FillConstructor;
import org.fluentlenium.core.action.FillSelectConstructor;
import org.fluentlenium.core.action.FluentDefaultActions;
import org.fluentlenium.core.action.MouseActions;
import org.fluentlenium.core.axes.Axes;
import org.fluentlenium.core.filter.Filter;
import org.fluentlenium.core.search.Search;
Expand All @@ -12,10 +13,8 @@
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
* WebElementCustom include a Selenium WebElement. It provides a lot of shortcuts to make selenium more fluent
Expand Down Expand Up @@ -63,7 +62,8 @@ public <T> T as(Class<T> componentClass) {
Constructor<T> constructor = componentClass.getConstructor(WebElement.class);
return constructor.newInstance(getElement());
} catch (Exception e) {
throw new IllegalArgumentException(componentClass.getName() + " is not a valid component class. It should have a single WebElement parameter constructor.", e);
throw new IllegalArgumentException(componentClass.getName()
+ " is not a valid component class. It should have a single WebElement parameter constructor.", e);
}
}

Expand All @@ -73,7 +73,20 @@ public <T> T as(Class<T> componentClass) {
* @return fluent web element
*/
public FluentWebElement doubleClick() {
Action action = new Actions(FluentThread.get().getDriver()).doubleClick(webElement).build();
MouseActions mouseActions = new MouseActions(FluentThread.get().getDriver());
Action action = mouseActions.doubleClick(webElement);
action.perform();
return this;
}

/**
* Double Click on the element
*
* @return fluent web element
*/
public FluentWebElement mouseOver() {
MouseActions mouseActions = new MouseActions(FluentThread.get().getDriver());
Action action = mouseActions.mouseOver(webElement);
action.perform();
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public void checkDoubleClickAction() {
assertThat(title()).isEqualTo("Page 2");
}

@Test
public void checkMouseOverAction() {
goTo(DEFAULT_URL);
assertThat(title()).contains("Selenium");
assertThat($("#id3").getText()).isEqualTo("This text should change on MouseOver");
$("#mouseover").first().mouseOver();
assertThat($("#id3").getText()).isEqualTo("abc");
}

@Test
public void checkTextAction() {
goTo(DEFAULT_URL);
Expand Down
3 changes: 3 additions & 0 deletions fluentlenium-core/src/test/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<h1>Heading</h1>

<span id="oneline">A single line of text</span>
<span id="mouseover" onmouseover="javascript:document.getElementById('id3').innerHTML='abc'">Sample line of text</span>

<span id="location">Pharmacy</span>
<span class="small" id="id" name="name">Small 1</span>
Expand Down Expand Up @@ -54,5 +55,7 @@ <h1>Heading</h1>
<input type="file" id="fileUpload"/>
<INPUT TYPE="FILE" ID="fileUpload2"/>

<span class="dynamic" id="id3">This text should change on MouseOver</span>

</body>
</html>

0 comments on commit 05ca5b3

Please sign in to comment.