Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SearchContext so that findElements can return a list that sub-classes WebElement #604

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/SearchContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

import java.util.List;

public interface SearchContext {
public interface SearchContext{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

/**
* Find all elements within the current context using the given mechanism.
*
* @param by The locating mechanism to use
* @return A list of all {@link WebElement}s, or an empty list if nothing matches
* @see org.openqa.selenium.By
*/
List<WebElement> findElements(By by);
<W extends WebElement> List<W> findElements(By by);


/**
Expand Down
72 changes: 72 additions & 0 deletions java/client/test/org/openqa/selenium/SearchContextTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.openqa.selenium;

import org.junit.Test;

import java.util.List;

// this class just tests we can compile the code
public class SearchContextTest {

private final SubClassingSearchContext subClassingSearchContext = new SubClassingSearchContext();
private final SameClassSearchContext sameClassSearchContext = new SameClassSearchContext() {
@Override
public List<WebElement> findElements(By by) {
return null;
}

@Override
public WebElement findElement(By by) {
return null;
}
};

private interface TestWebElement extends WebElement {

}

private static class SubClassingSearchContext implements SearchContext {

@Override
public List<TestWebElement> findElements(By by) {
return null;
}

@Override
public TestWebElement findElement(By by) {
return null;
}
}

private interface SameClassSearchContext extends SearchContext {

}

@Test
public void makeSureFindElementsIsBackwardsCompatible() throws Exception {

@SuppressWarnings("unused")
List<? extends WebElement> elements = sameClassSearchContext.findElements(null);
}

@Test
public void makeSureFindElementIsBackwardsCompatible() throws Exception {

@SuppressWarnings("unused")
WebElement element = sameClassSearchContext.findElement(null);
}

@Test
public void makeSureFindElementsCanUseSuperClass() throws Exception {
@SuppressWarnings("unused")
List<TestWebElement> elements = subClassingSearchContext.findElements(null);
}

@Test
public void makeSureFindElementCanUseSuperClass() throws Exception {

@SuppressWarnings("unused")
WebElement element = subClassingSearchContext.findElement(null);


}
}