Skip to content

Commit

Permalink
The final round of moving tests around
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Sep 6, 2013
1 parent c466c88 commit f972d7d
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 139 deletions.
70 changes: 70 additions & 0 deletions java/client/test/org/openqa/selenium/ChildrenFindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Ignore.Driver.REMOTE;


public class ChildrenFindingTest extends JUnit4TestBase {
Expand Down Expand Up @@ -232,4 +235,71 @@ public void testShouldBeAbleToFindElementsByCssSelector() {

assertEquals(2, elements.size());
}

@Test
public void testShouldBeAbleToFindChildrenOfANode() {
driver.get(pages.selectableItemsPage);
List<WebElement> elements = driver.findElements(By.xpath("/html/head"));
WebElement head = elements.get(0);
List<WebElement> importedScripts = head.findElements(By.tagName("script"));
assertThat(importedScripts.size(), equalTo(3));
}

@Test
public void testReturnAnEmptyListWhenThereAreNoChildrenOfANode() {
driver.get(pages.xhtmlTestPage);
WebElement table = driver.findElement(By.id("table"));
List<WebElement> rows = table.findElements(By.tagName("tr"));

assertThat(rows.size(), equalTo(0));
}

@Test
public void testShouldFindGrandChildren() {
driver.get(pages.formPage);
WebElement form = driver.findElement(By.id("nested_form"));
form.findElement(By.name("x"));
}

@Test
public void testShouldNotFindElementOutSideTree() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.name("login"));
try {
element.findElement(By.name("x"));
} catch (NoSuchElementException e) {
// this is expected
}
}

@Test
public void testFindingByTagNameShouldNotIncludeParentElementIfSameTagType() {
driver.get(pages.xhtmlTestPage);
WebElement parent = driver.findElement(By.id("my_span"));

assertEquals(2, parent.findElements(By.tagName("div")).size());
assertEquals(2, parent.findElements(By.tagName("span")).size());
}

@Test
public void testFindingByCssShouldNotIncludeParentElementIfSameTagType() {
driver.get(pages.xhtmlTestPage);
WebElement parent = driver.findElement(By.cssSelector("div#parent"));
WebElement child = parent.findElement(By.cssSelector("div"));

assertEquals("child", child.getAttribute("id"));
}

@Ignore({REMOTE, MARIONETTE})
@Test
public void testFindMultipleElements() {
driver.get(pages.simpleTestPage);
WebElement elem = driver.findElement(By.id("links"));

List<WebElement> elements =
elem.findElements(By.partialLinkText("link"));
assertNotNull(elements);
assertEquals(6, elements.size());
}

}
55 changes: 33 additions & 22 deletions java/client/test/org/openqa/selenium/ClickTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.TestWaiter.waitFor;
import static org.openqa.selenium.WaitingConditions.newWindowIsOpened;
import static org.openqa.selenium.WaitingConditions.pageSourceToContain;
import static org.openqa.selenium.WaitingConditions.pageTitleToBe;
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
Expand All @@ -60,15 +62,15 @@ public void tearDown() throws Exception {
public void testCanClickOnALinkAndFollowIt() {
driver.findElement(By.id("normal")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Ignore(value = {OPERA, MARIONETTE}, reason = "Not tested.")
@Test
public void testCanClickOnALinkThatOverflowsAndFollowIt() {
driver.findElement(By.id("overflowLink")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@JavascriptEnabled
Expand All @@ -95,7 +97,7 @@ public void testCanClickOnALinkThatUpdatesAnotherFrame() {
driver.findElement(By.id("otherframe")).click();
driver.switchTo().defaultContent().switchTo().frame("target");

waitFor(WaitingConditions.pageSourceToContain(driver, "Hello WebDriver"));
waitFor(pageSourceToContain(driver, "Hello WebDriver"));
}

@JavascriptEnabled
Expand All @@ -112,8 +114,7 @@ public void testElementsFoundByJsCanLoadUpdatesInAnotherFrame() {
toClick.click();
driver.switchTo().defaultContent().switchTo().frame("target");

assertTrue("Target did not reload",
driver.getPageSource().contains("Hello WebDriver"));
waitFor(pageSourceToContain(driver, "Hello WebDriver"));
}

@JavascriptEnabled
Expand All @@ -133,8 +134,7 @@ public void testJsLocatedElementsCanUpdateFramesIfFoundSomehowElse() {
toClick.click();
driver.switchTo().defaultContent().switchTo().frame("target");

assertTrue("Target did not reload",
driver.getPageSource().contains("Hello WebDriver"));
waitFor(pageSourceToContain(driver, "Hello WebDriver"));
}

@JavascriptEnabled
Expand All @@ -154,7 +154,7 @@ public void testCanClickOnAnElementWithTopSetToANegativeNumber() {
@Test
public void testShouldClickOnFirstBoundingClientRectWithNonZeroSize() {
driver.findElement(By.id("twoClientRects")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@JavascriptEnabled
Expand Down Expand Up @@ -217,34 +217,34 @@ public void testClickingLabelShouldSetCheckbox() {
public void testCanClickOnALinkWithEnclosedImage() {
driver.findElement(By.id("link-with-enclosed-image")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
public void testCanClickOnAnImageEnclosedInALink() {
driver.findElement(By.id("link-with-enclosed-image")).findElement(By.tagName("img")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
public void testCanClickOnALinkThatContainsTextWrappedInASpan() {
driver.findElement(By.id("link-with-enclosed-span")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
public void testCanClickOnALinkThatContainsEmbeddedBlockElements() {
driver.findElement(By.id("embeddedBlock")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
public void testCanClickOnAnElementEnclosedInALink() {
driver.findElement(By.id("link-with-enclosed-span")).findElement(By.tagName("span")).click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

// See http://code.google.com/p/selenium/issues/attachmentText?id=2700
Expand All @@ -266,7 +266,7 @@ public void testShouldBeAbleToClickOnAnElementInTheViewport() {
public void testClicksASurroundingStrongTag() {
driver.get(appServer.whereIs("ClickTest_testClicksASurroundingStrongTag.html"));
driver.findElement(By.tagName("a")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
Expand All @@ -275,15 +275,15 @@ public void testClicksASurroundingStrongTag() {
public void testCanClickAnImageMapArea() {
driver.get(appServer.whereIs("click_tests/google_map.html"));
driver.findElement(By.id("rectG")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "Target Page 1"));
waitFor(pageTitleToBe(driver, "Target Page 1"));

driver.get(appServer.whereIs("click_tests/google_map.html"));
driver.findElement(By.id("circleO")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "Target Page 2"));
waitFor(pageTitleToBe(driver, "Target Page 2"));

driver.get(appServer.whereIs("click_tests/google_map.html"));
driver.findElement(By.id("polyLE")).click();
waitFor(WaitingConditions.pageTitleToBe(driver, "Target Page 3"));
waitFor(pageTitleToBe(driver, "Target Page 3"));
}

@Test
Expand All @@ -297,7 +297,7 @@ public void testShouldBeAbleToClickOnAnElementGreaterThanTwoViewports() {

element.click();

waitFor(WaitingConditions.pageTitleToBe(driver, "clicks"));
waitFor(pageTitleToBe(driver, "clicks"));
}

@Test
Expand All @@ -315,7 +315,7 @@ public void testShouldBeAbleToClickOnAnElementInFrameGreaterThanTwoViewports() {
WebElement element = driver.findElement(By.id("click"));
element.click();

waitFor(WaitingConditions.pageTitleToBe(driver, "clicks"));
waitFor(pageTitleToBe(driver, "clicks"));
}

@Test
Expand All @@ -327,7 +327,7 @@ public void testShouldBeAbleToClickOnRTLLanguageLink() {
WebElement element = driver.findElement(By.id("ar_link"));
element.click();

waitFor(WaitingConditions.pageTitleToBe(driver, "clicks"));
waitFor(pageTitleToBe(driver, "clicks"));
}

@Test
Expand All @@ -340,7 +340,7 @@ public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() {
WebElement element = driver.findElement(By.id("link"));
element.click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@Test
Expand All @@ -353,7 +353,18 @@ public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMod
WebElement element = driver.findElement(By.id("link"));
element.click();

waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
waitFor(pageTitleToBe(driver, "XHTML Test Page"));
}

@JavascriptEnabled
@Test
public void testShouldBeAbleToClickOnLinksWithNoHrefAttribute() {
driver.get(pages.javascriptPage);

WebElement element = driver.findElement(By.linkText("No href"));
element.click();

waitFor(pageTitleToBe(driver, "Changed"));
}

}
Loading

0 comments on commit f972d7d

Please sign in to comment.