Skip to content

Commit

Permalink
More test refactoring (moving test cases to more appropriate classes)
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Sep 5, 2013
1 parent 1a2a14c commit f4a77f2
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 453 deletions.
83 changes: 83 additions & 0 deletions java/client/test/org/openqa/selenium/CssValueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2007-2009 Selenium committers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.openqa.selenium;

import org.junit.Test;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.JavascriptEnabled;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Ignore.Driver.IPHONE;
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;

public class CssValueTest extends JUnit4TestBase {

@JavascriptEnabled
@Ignore({ANDROID, HTMLUNIT, OPERA, MARIONETTE})
@Test
public void testShouldPickUpStyleOfAnElement() {
driver.get(pages.javascriptPage);

WebElement element = driver.findElement(By.id("green-parent"));
String backgroundColour = element.getCssValue("background-color");

assertEquals("rgba(0, 128, 0, 1)", backgroundColour);

element = driver.findElement(By.id("red-item"));
backgroundColour = element.getCssValue("background-color");

assertEquals("rgba(255, 0, 0, 1)", backgroundColour);
}

@JavascriptEnabled
@Ignore({ANDROID, HTMLUNIT, OPERA, MARIONETTE})
@Test
public void testGetCssValueShouldReturnStandardizedColour() {
driver.get(pages.colorPage);

WebElement element = driver.findElement(By.id("namedColor"));
String backgroundColour = element.getCssValue("background-color");
assertEquals("rgba(0, 128, 0, 1)", backgroundColour);

element = driver.findElement(By.id("rgb"));
backgroundColour = element.getCssValue("background-color");
assertEquals("rgba(0, 128, 0, 1)", backgroundColour);

}

@JavascriptEnabled
@Ignore({ANDROID, IPHONE, OPERA, HTMLUNIT, MARIONETTE})
@Test
public void testShouldAllowInheritedStylesToBeUsed() {
driver.get(pages.javascriptPage);

WebElement element = driver.findElement(By.id("green-item"));
String backgroundColour = element.getCssValue("background-color");

// TODO: How should this be standardized? Should it be standardized?
assertThat(backgroundColour, anyOf(
equalTo("transparent"),
equalTo("rgba(0, 0, 0, 0)")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Ignore.Driver.FIREFOX;
import static org.openqa.selenium.testing.Ignore.Driver.IE;
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
import static org.openqa.selenium.testing.Ignore.Driver.IPHONE;
Expand All @@ -35,10 +40,11 @@
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.JavascriptEnabled;

@Ignore(value = {HTMLUNIT, OPERA_MOBILE, ANDROID, IPHONE, MARIONETTE},
reason = "HtmlUnit: Getting coordinates requires rendering, others: not tested")
public class CoordinatesTest extends JUnit4TestBase {
public class PositionAndSizeTest extends JUnit4TestBase {

@Test
public void testShouldGetCoordinatesOfAnElementInViewPort() {
Expand Down Expand Up @@ -119,6 +125,40 @@ public void testShouldGetCoordinatesOfAnElementWithFixedPosition() {
assertThat(getLocationOnPage(By.id("fixed")).getY(), greaterThan(0));
}

@JavascriptEnabled
@Test
public void testShouldCorrectlyIdentifyThatAnElementHasWidthAndHeight() {
driver.get(pages.xhtmlTestPage);

WebElement shrinko = driver.findElement(By.id("linkId"));
Dimension size = shrinko.getSize();
assertTrue("Width expected to be greater than 0", size.width > 0);
assertTrue("Height expected to be greater than 0", size.height > 0);
}

// TODO: This test's value seems dubious at best. The CSS spec does not define how browsers
// should handle sub-pixel rendering, and every browser seems to be different anyhow:
// http://ejohn.org/blog/sub-pixel-problems-in-css/
@JavascriptEnabled
@Ignore({IE, CHROME, IPHONE, OPERA, ANDROID, SAFARI, OPERA_MOBILE, PHANTOMJS, MARIONETTE})
// Reason for Chrome: WebKit bug 28804
@Test
public void testShouldHandleNonIntegerPositionAndSize() {
driver.get(pages.rectanglesPage);

WebElement r2 = driver.findElement(By.id("r2"));
String left = r2.getCssValue("left");
assertTrue("left (\"" + left + "\") should start with \"10.9\".", left.startsWith("10.9"));
String top = r2.getCssValue("top");
assertTrue("top (\"" + top + "\") should start with \"10.1\".", top.startsWith("10.1"));
assertEquals(new Point(11, 10), r2.getLocation());
String width = r2.getCssValue("width");
assertTrue("width (\"" + left + "\") should start with \"48.6\".", width.startsWith("48.6"));
String height = r2.getCssValue("height");
assertTrue("height (\"" + left + "\") should start with \"49.3\".", height.startsWith("49.3"));
assertEquals(r2.getSize(), new Dimension(49, 49));
}

private Point getLocationInViewPort(By locator) {
WebElement element = driver.findElement(locator);
return ((Locatable) element).getCoordinates().inViewPort();
Expand Down
Loading

0 comments on commit f4a77f2

Please sign in to comment.