Skip to content

Commit

Permalink
Add more unit tests and fix API inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Jul 28, 2016
1 parent 42d589f commit 21d91ab
Show file tree
Hide file tree
Showing 13 changed files with 1,388 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public Fluent clear(String cssSelector, Filter... filters) {
* @return fluent object
*/
public Fluent clear(Filter... filters) {
$(filters).clear();
$(filters).clearAll();
return this;
}

Expand Down Expand Up @@ -732,7 +732,7 @@ public Fluent click(FluentDefaultActions fluentObject) {
* @return fluent object
*/
public Fluent clear(FluentList<FluentWebElement> fluentObject) {
fluentObject.clear();
fluentObject.clearAll();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -14,13 +13,9 @@
*/
public class FluentJavascript extends Fluent {
private final Object result;
private final Object[] args;
private final String script;

public FluentJavascript(WebDriver driver, boolean async, String script, Object... args) {
super(driver);
this.script = script;
this.args = Arrays.copyOf(args, args.length);
if (async) {
this.result = ((JavascriptExecutor) driver).executeAsyncScript(script, args);
} else {
Expand Down Expand Up @@ -109,24 +104,19 @@ public String getStringResult() {
}

/**
* @return the result of javascript execution cast as List.
* @return result of javascript execution cast as String.
* @see org.openqa.selenium.JavascriptExecutor#executeScript(java.lang.String, java.lang.Object...)
*/
public List getListResult() {
return (List) result;
public List<?> getListResult() {
return (List<?>) result;
}

/**
* @return script executed by the caller.
*/
public String getScript() {
return script;
}

/**
* @return args used by the caller.
* @param <T> type of list elements
* @return the result of javascript execution cast as List.
* @see org.openqa.selenium.JavascriptExecutor#executeScript(java.lang.String, java.lang.Object...)
*/
public Object[] getArgs() {
return args;
public <T> List<T> getListResult(Class<T> listType) {
return (List<T>) result;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.fluentlenium.core.domain;

import org.fluentlenium.core.action.FluentDefaultActions;
import org.fluentlenium.core.conditions.FluentConditions;
import org.fluentlenium.core.conditions.FluentListConditions;
import org.fluentlenium.core.filter.Filter;
import org.fluentlenium.core.search.SearchActions;
import org.openqa.selenium.WebElement;

import java.lang.reflect.Constructor;
import java.util.List;

/**
Expand All @@ -24,6 +22,22 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
*/
E first();

/**
* Return the last element of the list.
* If none, return NoSuchElementException
*
* @return last element
* @throws org.openqa.selenium.NoSuchElementException when element not found
*/
E last();

/**
* Creates a list of Selenium {@link WebElement} from this list
*
* @return list of selenium elements
*/
List<WebElement> toElements();

/**
* Click on all elements on the list
* Only the visible elements are filled
Expand Down Expand Up @@ -75,6 +89,13 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
*/
List<String> getNames();

/**
* Return the tag name of elements on the list
*
* @return list of string values
*/
List<String> getTagNames();

/**
* Return the texts of list elements
*
Expand Down Expand Up @@ -118,18 +139,33 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
*/
String getName();

/**
* Return the tag name of the first element on the list
*
* @return tag name of the first element
*/
String getTagName();

/**
* Return the text of the first element on the list
*
* @return text of the first element on the list
*/
String getText();


/**
* Return the text content of the first element on the list
*
* @return text content of the first element on the list
*/
String getTextContent();

/**
* find elements into the children with the corresponding filters
*
* @param selector element name
* @param filters set of filters
* @param selector element name
* @param filters set of filters
* @return extended by FluentWebElement objects list
*/
@Override
Expand All @@ -147,9 +183,9 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
/**
* find elements into the children with the corresponding filters at the position indicated by the number
*
* @param selector element name
* @param number set of filters
* @param filters set of filters
* @param selector element name
* @param number set of filters
* @param filters set of filters
* @return extended by FluentWebElement object
*/
@Override
Expand All @@ -158,7 +194,7 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
/**
* find element in the children with the corresponding filters at the position indicated by the number
*
* @param index element name
* @param index element name
* @param filters set of filters
* @return extended by FluentWebElement object
*/
Expand All @@ -168,8 +204,8 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD
/**
* find elements into the children with the corresponding filters at the first position
*
* @param selector element name
* @param filters set of filters
* @param selector element name
* @param filters set of filters
* @return extended by FluentWebElement object
*/
@Override
Expand All @@ -186,26 +222,38 @@ public interface FluentList<E extends FluentWebElement> extends List<E>, FluentD

/**
* Clear all elements on the list
* Only the visible elements are filled
* <p>
* Only the visible elements are cleared.
*
* @return extended by FluentWebElement object
*/
FluentList<E> clearAll();

/**
* Clear all elements on the list
* <p>
* Only the visible elements are cleared.
*
* @return extended by FluentWebElement object
*/
@Override
void clear();

/**
* Calls {@link List#clear()} from underlying List implementation.
*
* @see List#clear()
*/
void clearList();

/**
* Wrap all underlying elements in a componen..
*
* @param componentClass component class
* @param <T> type of component
* @return fluent list of elements as components.
*/
public <T extends FluentWebElement> FluentList<T> as(Class<T> componentClass);

/**
* Clear all elements on the list
* Only the visible elements are filled
*/
void clear();
<T extends FluentWebElement> FluentList<T> as(Class<T> componentClass);

/**
* Get a condition object on this element list that will match if each underlying element match.
Expand Down
Loading

0 comments on commit 21d91ab

Please sign in to comment.