Skip to content

Commit

Permalink
Merge 06c1bf4 into f00b256
Browse files Browse the repository at this point in the history
  • Loading branch information
filipcynarski committed Mar 31, 2016
2 parents f00b256 + 06c1bf4 commit f217884
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 30 deletions.
91 changes: 72 additions & 19 deletions fluentlenium-core/src/main/java/org/fluentlenium/core/Fluent.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package org.fluentlenium.core;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.fluentlenium.core.action.FillConstructor;
Expand All @@ -24,13 +14,24 @@
import org.fluentlenium.core.search.Search;
import org.fluentlenium.core.search.SearchActions;
import org.fluentlenium.core.wait.FluentWait;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.support.events.EventFiringWebDriver;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
* Util Class which offers some shortcut to webdriver methods
*/
Expand Down Expand Up @@ -102,7 +103,6 @@ public Fluent() {
FluentThread.set(this);
}


public void setScreenshotPath(String path) {
this.screenshotPath = path;
}
Expand Down Expand Up @@ -132,8 +132,7 @@ public Fluent takeHtmlDump() {
/**
* Take a html dump of the browser DOM into a file given by the fileName param.
*
* @param fileName
* file name for html dump
* @param fileName file name for html dump
* @return fluent object
*/
public Fluent takeHtmlDump(String fileName) {
Expand Down Expand Up @@ -219,8 +218,8 @@ public Search getSearch() {

public EventsRegistry events() {
if (events == null) {
throw new IllegalStateException("An EventFiringWebDriver instance is required to use events. " +
"Please override getDefaultDriver() to provide it.");
throw new IllegalStateException("An EventFiringWebDriver instance is required to use events. "
+ "Please override getDefaultDriver() to provide it.");
}
return events;
}
Expand All @@ -247,7 +246,6 @@ public FluentWait await() {
return new FluentWait(this, getSearch());
}


/**
* Return the title of the page
*
Expand Down Expand Up @@ -300,7 +298,6 @@ public String pageSource() {
return getDriver().getPageSource();
}


public <P extends FluentPage> P goTo(P page) {
if (page == null) {
throw new IllegalArgumentException("Page is mandatory");
Expand Down Expand Up @@ -368,7 +365,6 @@ public FluentJavascript executeAsyncScript(String script, Object... args) {
return new FluentJavascript(this.getDriver(), true, script, args);
}


/**
* Central methods to find elements on the page. Can provide some filters. Able to use css1, css2, css3, see WebDriver restrictions
*
Expand All @@ -390,6 +386,17 @@ public FluentJavascript executeAsyncScript(String script, Object... args) {
return getSearch().find(filters);
}

/**
* Central methods to find elements on the page. Can provide some filters. Able to use css1, css2, css3, see WebDriver restrictions
*
* @param locator elements locator
* @param filters filters set
* @return fluent list of fluent web elements
*/
public FluentList<FluentWebElement> $(By locator, final Filter... filters) {
return getSearch().find(locator, filters);
}

/**
* Central methods a find element on the page, the number indicate the index of the desired element on the list.
* Can provide some filters. Able to use css1, css2, css3, see WebDriver restrictions
Expand All @@ -403,6 +410,18 @@ public FluentJavascript executeAsyncScript(String script, Object... args) {
return getSearch().find(name, number, filters);
}

/**
* Return the elements at the number position into the the lists corresponding to the cssSelector with it filters
*
* @param locator elements locator
* @param number index of element in the list
* @param filters filters set
* @return fluent web element
*/
public FluentWebElement $(By locator, Integer number, final Filter... filters) {
return getSearch().find(locator, number, filters);
}

/**
* Central method to find an element on the page with filters.
* The number indicates the index of the desired element on the list.
Expand All @@ -426,6 +445,17 @@ public FluentList<FluentWebElement> find(String name, final Filter... filters) {
return getSearch().find(name, filters);
}

/**
* Central methods to find elements on the page. Can provide some filters. Able to use css1, css2, css3, see WebDriver restrictions
*
* @param locator elements locator
* @param filters filters set
* @return fluent list of fluent web elements
*/
public FluentList<FluentWebElement> find(By locator, final Filter... filters) {
return getSearch().find(locator, filters);
}

/**
* Return the list filtered by the specified filters.
*
Expand All @@ -448,6 +478,18 @@ public FluentWebElement find(String name, Integer number, final Filter... filter
return getSearch().find(name, number, filters);
}

/**
* Return the elements at the number position into the the lists corresponding to the cssSelector with it filters
*
* @param locator elements locator
* @param number index of element in the list
* @param filters filters set
* @return fluent web element
*/
public FluentWebElement find(By locator, Integer number, final Filter... filters) {
return getSearch().find(locator, number, filters);
}

/**
* Return the element at the number position in the list filtered by the specified filters.
*
Expand Down Expand Up @@ -480,6 +522,18 @@ public FluentWebElement findFirst(final Filter... filters) {
return getSearch().findFirst(filters);
}

/**
* Return the first elements corresponding to the name and the filters
*
* @param locator element locator
* @param filters filters set
* @return fluent web element
*/
@Override
public FluentWebElement findFirst(By locator, final Filter... filters) {
return getSearch().findFirst(locator, filters);
}

/**
* Construct a FillConstructor in order to allow easy fill
* Be careful - only the visible elements are filled
Expand Down Expand Up @@ -737,7 +791,6 @@ public Fluent switchTo() {
return this;
}


/**
* Switch to the default element
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.fluentlenium.core.filter.Filter;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;

import java.util.ArrayList;
Expand Down Expand Up @@ -89,7 +90,6 @@ public FluentList<E> clearAll() {
return this;
}


/**
* {@inheritDoc}
*/
Expand All @@ -102,7 +102,6 @@ public void clear() {
}
}


/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -255,6 +254,18 @@ public FluentList<E> find(String name, Filter... filters) {
return new FluentListImpl<E>(finds);
}

/**
* {@inheritDoc}
*/
@Override
public FluentList<E> find(By locator, Filter... filters) {
List<E> finds = new ArrayList<E>();
for (FluentWebElement e : this) {
finds.addAll((Collection<E>) e.find(locator, filters));
}
return new FluentListImpl<E>(finds);
}

/**
* {@inheritDoc}
*/
Expand All @@ -274,7 +285,23 @@ public FluentList<E> find(Filter... filters) {
public E find(String name, Integer number, Filter... filters) {
FluentList<E> fluentList = find(name, filters);
if (number >= fluentList.size()) {
throw new NoSuchElementException("No such element with position: " + number + ". Number of elements available: " + fluentList.size() + ". Selector: " + name + ".");
throw new NoSuchElementException(
"No such element with position: " + number + ". Number of elements available: " + fluentList.size()
+ ". Selector: " + name + ".");
}
return fluentList.get(number);
}

/**
* {@inheritDoc}
*/
@Override
public E find(By locator, Integer number, Filter... filters) {
FluentList<E> fluentList = find(locator, filters);
if (number >= fluentList.size()) {
throw new NoSuchElementException(
"No such element with position: " + number + ". Number of elements available: " + fluentList
.size());
}
return fluentList.get(number);
}
Expand All @@ -286,11 +313,21 @@ public E find(String name, Integer number, Filter... filters) {
public E find(Integer number, Filter... filters) {
FluentList<E> fluentList = find(filters);
if (number >= fluentList.size()) {
throw new NoSuchElementException("No such element with position: " + number + ". Number of elements available: " + fluentList.size() + ".");
throw new NoSuchElementException(
"No such element with position: " + number + ". Number of elements available: " + fluentList.size()
+ ".");
}
return fluentList.get(number);
}

/**
* {@inheritDoc}
*/
@Override
public E findFirst(By locator, Filter... filters) {
return find(locator, 0, filters);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.fluentlenium.core.filter.Filter;
import org.fluentlenium.core.search.Search;
import org.fluentlenium.core.search.SearchActions;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
Expand Down Expand Up @@ -190,6 +191,17 @@ public Dimension getSize() {
return webElement.getSize();
}

/**
* find elements into the children with the corresponding filters
*
* @param locator elements locator
* @param filters filters set
* @return list of Fluent web elements
*/
public FluentList<FluentWebElement> find(By locator, Filter... filters) {
return search.find(locator, filters);
}

/**
* find elements into the children with the corresponding filters
*
Expand Down Expand Up @@ -222,6 +234,17 @@ public FluentWebElement find(String name, Integer number, Filter... filters) {
return search.find(name, number, filters);
}

/**
* find elements into the children with the corresponding filters at the given position
*
* @param locator elements locator
* @param filters filters set
* @return fluent web element
*/
public FluentWebElement find(By locator, Integer number, Filter... filters) {
return search.find(locator, number, filters);
}

/**
* find element in the children with the corresponding filters at the given position
*
Expand All @@ -244,6 +267,17 @@ public FluentWebElement findFirst(String name, Filter... filters) {
return search.findFirst(name, filters);
}

/**
* find elements into the children with the corresponding filters at the first position
*
* @param locator elements locator
* @param filters filters set
* @return fluent web element
*/
public FluentWebElement findFirst(By locator, Filter... filters) {
return search.findFirst(locator, filters);
}

/**
* find element in the children with the corresponding filters at the first position
*
Expand Down Expand Up @@ -279,7 +313,7 @@ public FillConstructor fill() {
* Be careful - only the visible elements are filled
*/
public FillSelectConstructor fillSelect() {
return new FillSelectConstructor(this, FluentThread.get().getDriver());
return new FillSelectConstructor(this, FluentThread.get().getDriver());
}

/**
Expand All @@ -288,8 +322,7 @@ public FillSelectConstructor fillSelect() {
* @return boolean value for is input file type
*/
private boolean isInputOfTypeFile() {
return ("input".equalsIgnoreCase(this.getTagName()) &&
"file".equalsIgnoreCase(this.getAttribute("type")));
return ("input".equalsIgnoreCase(this.getTagName()) && "file".equalsIgnoreCase(this.getAttribute("type")));
}

@Override
Expand Down
Loading

0 comments on commit f217884

Please sign in to comment.