Skip to content

Commit

Permalink
Add a test for mouseover/out behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Oct 30, 2013
1 parent 8e6ae27 commit d1baa24
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
16 changes: 16 additions & 0 deletions common/src/web/mouseOver.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<body style="margin: 0; padding: 0;">
<div style="position: absolute; overflow: hidden;
left: 0; top: 0; width: 250px; height: 250px;
background: green">
<div style="position: relative; left: 75px; top: 75px;
width: 75px; height: 75px;
background: green"
id="redbox">
</div>
<script>
var redbox = document.getElementById('redbox');
redbox.onmouseover = function() { redbox.style.background = 'red'; };
redbox.onmouseout = function() { redbox.style.background = 'green'; };
</script>
</div>
2 changes: 2 additions & 0 deletions java/client/test/org/openqa/selenium/Pages.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Pages {
public String mapVisibilityPage;
public String metaRedirectPage;
public String missedJsReferencePage;
public String mouseOverPage;
public String mouseTrackerPage;
public String nestedPage;
public String readOnlyPage;
Expand Down Expand Up @@ -112,6 +113,7 @@ public Pages(AppServer appServer) {
mapVisibilityPage = appServer.whereIs("map_visibility.html");
metaRedirectPage = appServer.whereIs("meta-redirect.html");
missedJsReferencePage = appServer.whereIs("missedJsReference.html");
mouseOverPage = appServer.whereIs("mouseOver.html");
mouseTrackerPage = appServer.whereIs("mousePositionTracker.html");
nestedPage = appServer.whereIs("nestedElements.html");
readOnlyPage = appServer.whereIs("readOnlyPage.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@

package org.openqa.selenium.interactions;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NeedsFreshDriver;
import org.openqa.selenium.NoDriverAfterTest;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.Platform;
import org.openqa.selenium.TestWaiter;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.JavascriptEnabled;
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.TestUtilities;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.awt.Robot;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -66,6 +43,32 @@
import static org.openqa.selenium.testing.TestUtilities.isFirefox35;
import static org.openqa.selenium.testing.TestUtilities.isNativeEventsEnabled;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NeedsFreshDriver;
import org.openqa.selenium.NoDriverAfterTest;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.Platform;
import org.openqa.selenium.TestWaiter;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.Color;
import org.openqa.selenium.support.Colors;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.JavascriptEnabled;
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.TestUtilities;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.awt.*;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
* Tests operations that involve mouse and keyboard.
*/
Expand Down Expand Up @@ -601,6 +604,31 @@ public void testMoveRelativeToBody() {
}
}

@JavascriptEnabled
@Test
@Ignore(value = {HTMLUNIT, OPERA, SAFARI, MARIONETTE},
reason = "Advanced mouse actions only implemented in rendered browsers",
issues = {4136})
@NoDriverAfterTest
public void canMouseOverAndOutOfAnElement() {
driver.get(pages.mouseOverPage);

WebElement redbox = driver.findElement(By.id("redbox"));
Dimension size = redbox.getSize();

assertEquals(
Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

new Actions(driver).moveToElement(redbox).perform();
assertEquals(
Colors.RED.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

new Actions(driver).moveToElement(redbox, size.getWidth() + 1, size.getHeight() + 1)
.perform();
assertEquals(
Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));
}

private boolean fuzzyPositionMatching(int expectedX, int expectedY, String locationTouple) {
String[] splitString = locationTouple.split(",");
int gotX = Integer.parseInt(splitString[0].trim());
Expand Down

0 comments on commit d1baa24

Please sign in to comment.