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

In HtmlElementUtils.newInstance added optional parameter "outerObject". #136

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
adbfdd3
TypifiedElement implements WebElement
ham1 Jun 4, 2016
e922536
Merge pull request #121 from ham1/TypifiedElement_WebElement
artkoshelev Jun 6, 2016
b56acc3
StaleElementReferenceException fix
Jun 9, 2016
0a3dab3
Merge pull request #123 from eroshenkoam/refactoring
artkoshelev Jun 10, 2016
6092ea9
[maven-release-plugin] prepare release htmlelements-1.16
qatools-ci Jun 10, 2016
0ed4d9c
[maven-release-plugin] prepare for next development iteration
qatools-ci Jun 10, 2016
b9a2f3a
Updated README for 1.16 (#124)
ham1 Jun 10, 2016
62caaef
Removed unused dependencies. (#126)
ham1 Jun 13, 2016
3312d1d
Tidy up. Removed unused imports, replaced deprecated Exception, forma…
ham1 Jun 13, 2016
bf3f275
Fixes #94 (#99)
ham1 Jun 13, 2016
a121c78
[maven-release-plugin] prepare release htmlelements-1.17
qatools-ci Jun 13, 2016
250cdb5
[maven-release-plugin] prepare for next development iteration
qatools-ci Jun 13, 2016
a524895
upd readme to 1.17
lanwen Jun 13, 2016
c6f1acc
Fixed possible NPE in TextInput by using ofNullable (#127)
ham1 Jun 20, 2016
d086274
Fix array-out-of-bound error on getRowsMappedToHeaders(List)
iamanikeev Sep 12, 2016
c14abe5
Merge pull request #131 from iamanikeev/fix-array-out-of-bounds
artkoshelev Sep 19, 2016
483470f
Save getHeadingsAsString() result into variable to reduce unnecessar…
aanikeev Oct 14, 2016
b8adb3d
Merge pull request #132 from iamanikeev/fix-performance-issue-in-table
artkoshelev Oct 17, 2016
3cfbec9
HtmlElementUtils: remove final
Nov 27, 2016
19d7d5a
In HtmlElementUtils.newInstance added optional parameter "outerObject".
Nov 27, 2016
27b41a5
HtmlElementUtils.newInstance: change order of parameters for exclude …
Nov 27, 2016
dcd0111
In HtmlElementLoader.createHtmlElement added optional parameter "oute…
Nov 27, 2016
ddcaf1c
In HtmlElementDecorator.decorate added optional parameter "outerObject".
Nov 27, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
Html Elements framework
=======================
[![release](http://github-release-version.herokuapp.com/github/yandex-qatools/htmlelements/release.svg?style=flat)](https://github.com/yandex-qatools/htmlelements/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.htmlelements/htmlelements-java/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.htmlelements/htmlelements-java)
[![release](http://github-release-version.herokuapp.com/github/yandex-qatools/htmlelements/release.svg?style=flat)]
(https://github.com/yandex-qatools/htmlelements/releases/latest)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.htmlelements/htmlelements-java/badge.svg?style=flat)]
(https://maven-badges.herokuapp.com/maven-central/ru.yandex.qatools.htmlelements/htmlelements-java)



This framework is designed to provide an easy-to-use way of interacting with web-page elements in your tests. It can be
considered to be an extension of WebDriver Page Object.
This framework is designed to provide an easy-to-use way of interacting with web-page elements in your tests.
It can be considered to be an extension of WebDriver Page Object.

With the help of the Html Elements framework you can group web-page elements into blocks, encapsulate logic of interaction within them
and then easily use created blocks in page objects. It also provides a set of helpful matchers to use with web-page elements
and blocks. See [JavaDocs](https://oss.sonatype.org/service/local/repositories/releases/archive/ru/yandex/qatools/htmlelements/htmlelements-java/1.12/htmlelements-java-1.12-javadoc.jar/!/index.html)
and blocks. See [JavaDocs]
(https://oss.sonatype.org/service/local/repositories/releases/archive/ru/yandex/qatools/htmlelements/htmlelements-java/1.16/htmlelements-java-1.16-javadoc.jar/!/index.html)
and [Samples](https://github.com/yandex-qatools/htmlelements-examples) for more details.

You can ask your questions on StackOverflow with [![htmlelements](https://img.shields.io/badge/stackoverflow-htmlelements-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/htmlelements) tag.
You can ask your questions on StackOverflow with the [![htmlelements]
(https://img.shields.io/badge/stackoverflow-htmlelements-orange.svg?style=flat)]
(http://stackoverflow.com/questions/tagged/htmlelements) tag.

Other Languages
-------------
In case you are non-java guy, don't panic, there are still few options:
In case you are not a Java guy/gal, don't panic, there are still few options:

* [Html Elements .NET implementation](https://github.com/yandex-qatools/htmlelements-dotnet) - .NET port made by [Vadzim Hushchanskou](https://github.com/HardNorth)
* [Html Elements PHP implementation](https://github.com/qa-tools/qa-tools) - PHP port made by [Alexander Obuhovich](https://github.com/aik099)
* [bumblebee framework (C#)](https://github.com/patrickherrmann/Bumblebee) - same idea, nice implementation

Release Notes
-------------
* [Version 1.17 Release Notes](https://github.com/yandex-qatools/htmlelements/releases/tag/htmlelements-1.17)
* [Version 1.16 Release Notes](https://github.com/yandex-qatools/htmlelements/releases/tag/htmlelements-1.16)
* [Version 1.15 Release Notes](https://github.com/yandex-qatools/htmlelements/releases/tag/htmlelements-1.15)
* [Version 1.14 Release Notes](https://github.com/yandex-qatools/htmlelements/releases/tag/htmlelements-1.14)
* [Version 1.13 Release Notes](https://github.com/yandex-qatools/htmlelements/releases/tag/htmlelements-1.13)
Expand All @@ -40,7 +47,7 @@ Maven dependencies for Html Elements core:
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-java</artifactId>
<version>1.15</version>
<version>1.17</version>
</dependency>
```

Expand All @@ -50,7 +57,7 @@ And for Thucydides integration:
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-thucydides</artifactId>
<version>1.15</version>
<version>1.17</version>
</dependency>
```

Expand All @@ -60,11 +67,11 @@ Or you can include all modules at once if needed:
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-all</artifactId>
<version>1.15</version>
<version>1.17</version>
</dependency>
```

Since 1.15 it requires Java 8. Please use 1.14 for Java 7 support.
Since 1.15 Java 8 is required. Please use 1.14 for Java 7 support.

Create blocks of elements
-------------------------
Expand All @@ -74,6 +81,7 @@ For example, let's create a block for the search form on the page http://www.yan
@Name("Search form")
@FindBy(xpath = "//form")
public class SearchArrow extends HtmlElement {

@Name("Search request input")
@FindBy(id = "searchInput")
private TextInput requestInput;
Expand All @@ -95,8 +103,9 @@ You can easily use created blocks in page objects:

```java
public class SearchPage {

private SearchArrow searchArrow;
// Other blocks and elements here
// Other blocks and elements here ...

public SearchPage(WebDriver driver) {
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
Expand All @@ -106,16 +115,17 @@ public class SearchPage {
searchArrow.search(request);
}

// Other methods here
// Other methods here ...
}
```

Use page objects in your tests
------------------------------
Created page objects can be used in your tests. This makes tests more concise and easy to write.
Created page objects can be used in your tests. This makes tests more concise, easier to maintain, and easy to write.

```java
public class SampleTest {

private WebDriver driver = new FirefoxDriver();
private SearchPage searchPage = new SearchPage(driver);

Expand All @@ -139,4 +149,5 @@ public class SampleTest {

Questions?
----------
In case you can't find an answer in documentation and examples provided above, you can ask it on StackOverflow with [![htmlelements](https://img.shields.io/badge/stackoverflow-htmlelements-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/htmlelements) tag.
In case you can't find an answer in documentation and examples provided above, you can ask it on StackOverflow with the
[![htmlelements](https://img.shields.io/badge/stackoverflow-htmlelements-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/htmlelements) tag.
2 changes: 1 addition & 1 deletion htmlelements-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>htmlelements</artifactId>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<version>1.16-SNAPSHOT</version>
<version>1.18-SNAPSHOT</version>
</parent>

<artifactId>htmlelements-all</artifactId>
Expand Down
18 changes: 1 addition & 17 deletions htmlelements-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements</artifactId>
<version>1.16-SNAPSHOT</version>
<version>1.18-SNAPSHOT</version>
</parent>

<artifactId>htmlelements-java</artifactId>
Expand All @@ -23,27 +23,11 @@
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.3.3</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ public class Button extends TypifiedElement {
public Button(WebElement wrappedElement) {
super(wrappedElement);
}

/**
* Clicks the button.
*/
public void click() {
getWrappedElement().click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,4 @@ public void set(boolean value) {
deselect();
}
}

/**
* Indicates whether checkbox is selected.
*/
public boolean isSelected() {
return getWrappedElement().isSelected();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static java.util.Objects.isNull;

/**
* Represents web page form tag. Provides handy way of filling form with data and submitting it.
* Represents web page form tag.
* Provides handy way of filling form with data and submitting it.
*
* @author Artem Eroshenko [email protected]
* 3/14/13, 4:38 PM
Expand All @@ -33,34 +37,28 @@ public Form(WebElement wrappedElement) {

/**
* Fills form with data contained in passed map.
* For each map entry an input with a name coincident with entry key is searched and then found input
* is filled with string representation of entry value (toString() method is called). If input with such a name
* is not found corresponding entry is skipped.
* For each map entry if an input with a name coincident with entry key exists
* it is filled with string representation of entry value.
* If an input with such a name is not found the corresponding entry is skipped.
*
* @param data Map containing data to fill form inputs with.
*/
public void fill(Map<String, Object> data) {
for (String key : data.keySet()) {
WebElement elementToFill = findElementByKey(key);
if (elementToFill != null) {
fillElement(elementToFill, Objects.toString(data.get(key), ""));
}
}
}

/**
* Submits represented form.
*/
public void submit() {
getWrappedElement().submit();
data.entrySet().stream()
.map(e -> new AbstractMap.SimpleEntry<>(
findElementByKey(e.getKey()),
Objects.toString(e.getValue(), "")))
.filter(e -> !isNull(e.getKey()))
.forEach(e -> fillElement(e.getKey(), e.getValue()));
}

protected WebElement findElementByKey(String key) {
List<WebElement> elements = getWrappedElement().findElements(By.name(key));
if (elements.isEmpty()) {
return null;
} else {
return elements.get(0);
}
return elements.get(0);
}

protected void fillElement(WebElement element, String value) {
Expand All @@ -85,32 +83,28 @@ protected String getElementType(WebElement element) {
String type = element.getAttribute("type");
if ("checkbox".equals(type)) {
return CHECKBOX_FIELD;
}
if ("radio".equals(type)) {
} else if ("radio".equals(type)) {
return RADIO_FIELD;
}
if ("file".equals(type)) {
} else if ("file".equals(type)) {
return FILE_FIELD;
} else {
return INPUT_FIELD;
}
return INPUT_FIELD;
}
if ("select".equals(tagName)) {
} else if ("select".equals(tagName)) {
return SELECT_FIELD;
}
if ("textarea".equals(tagName)) {
} else if ("textarea".equals(tagName)) {
return INPUT_FIELD;
} else {
return null;
}
return null;
}

protected void fillCheckBox(WebElement element, String value) {
CheckBox checkBox = new CheckBox(element);
checkBox.set(Boolean.parseBoolean(value));
new CheckBox(element).set(Boolean.parseBoolean(value));
}

protected void fillRadio(WebElement element, String value) {
Radio radio = new Radio(element);
radio.selectByValue(value);
new Radio(element).selectByValue(value);
}

protected void fillInput(WebElement element, String value) {
Expand All @@ -119,12 +113,10 @@ protected void fillInput(WebElement element, String value) {
}

protected void fillSelect(WebElement element, String value) {
Select select = new Select(element);
select.selectByValue(value);
new Select(element).selectByValue(value);
}

protected void fillFile(WebElement element, String value) {
FileInput fileInput = new FileInput(element);
fileInput.setFileToUpload(value);
new FileInput(element).setFileToUpload(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,4 @@ public String getAlt() {
return getWrappedElement().getAttribute("alt");
}

/**
* Click on image
*/
public void click() {
getWrappedElement().click();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,4 @@ public Link(WebElement wrappedElement) {
public String getReference() {
return getWrappedElement().getAttribute("href");
}

/**
* Clicks the link.
*/
public void click() {
getWrappedElement().click();
}

/**
* Returns text of the link.
*/
public String getText() {
return getWrappedElement().getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.openqa.selenium.WebElement;

import java.util.List;
import java.util.Optional;

/**
* Represents a group of radio buttons.
Expand Down Expand Up @@ -72,13 +71,13 @@ public boolean hasSelectedButton() {
* @param value The value to match against.
*/
public void selectByValue(String value) {
Optional<WebElement> matchingButton = getButtons().stream()
WebElement matchingButton = getButtons().stream()
.filter(b -> value.equals(b.getAttribute("value")))
.findFirst();

selectButton(matchingButton
.findFirst()
.orElseThrow(() -> new NoSuchElementException(
String.format("Cannot locate radio button with value: %s", value))));
String.format("Cannot locate radio button with value: %s", value)));

selectButton(matchingButton);
}

/**
Expand All @@ -90,7 +89,8 @@ public void selectByIndex(int index) {
List<WebElement> buttons = getButtons();

if (index < 0 || index >= buttons.size()) {
throw new NoSuchElementException(String.format("Cannot locate radio button with index: %d", index));
throw new NoSuchElementException(
String.format("Cannot locate radio button with index: %d", index));
}

selectButton(buttons.get(index));
Expand Down
Loading