Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
832 changes: 0 additions & 832 deletions doc/style/eclipse-java-style.xml

This file was deleted.

Empty file modified doc/style/intellij-java-style.xml
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion doc/style/style.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
<module name="CommentsIndentation"/>

<module name="JavadocTagContinuationIndentation"/>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target"
Expand Down
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-java</artifactId>
<version>1.20.0</version>
<version>4.0.0-beta-1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.frameworkium.core.htmlelements.annotations;

import java.lang.annotation.*;

/**
* Annotation that is used for setting waiting timeout value,
* which will be used for waiting an element to appear.
* <p>
* For example:
* <p/>
* <pre class="code">
* &#64;FindBy(css = "my_form_css")
* &#64;Timeout(3)
* public class MyForm extends HtmlElement {
* &#64;FindBy(css = "text_input_css")
* &#64;Timeout(3)
* private TextInput textInput;
* <p/>
* // Other elements and methods here
* }
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface Timeout {
int value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.frameworkium.core.htmlelements.element;

import org.openqa.selenium.WebElement;

/** Represents web page button control. */
public class Button extends TypifiedElement {

/**
* Specifies wrapped {@link WebElement}.
*
* @param wrappedElement {@code WebElement} to wrap.
*/
public Button(WebElement wrappedElement) {
super(wrappedElement);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.frameworkium.core.htmlelements.element;

import org.openqa.selenium.*;

import java.util.Optional;

/** Represents checkbox control. */
public class CheckBox extends TypifiedElement {

/**
* Specifies wrapped {@link WebElement}.
*
* @param wrappedElement {@code WebElement} to wrap.
*/
public CheckBox(WebElement wrappedElement) {
super(wrappedElement);
}

/**
* Finds label corresponding to this checkbox using "following-sibling::label" xpath.
*
* @return Optional of the {@code WebElement} representing label
*/
public Optional<WebElement> getLabel() {
try {
return Optional.of(getWrappedElement().findElement(By.xpath("following-sibling::label")));
} catch (NoSuchElementException e) {
return Optional.empty();
}
}

/**
* Finds the text of the checkbox label.
*
* @return Optional of the label text
*/
public Optional<String> getLabelText() {
return getLabel().map(WebElement::getText);
}

/**
* The same as {@link #getLabelText()}.
*
* @return Text of the checkbox label or {@code null} if no label has been found.
*/
public String getText() {
return getLabelText().orElse("");
}

/** Selects checkbox if it is not already selected. */
public void select() {
if (!isSelected()) {
getWrappedElement().click();
}
}

/** Deselects checkbox if it is not already deselected. */
public void deselect() {
if (isSelected()) {
getWrappedElement().click();
}
}

/** Selects checkbox if passed value is {@code true} and deselects otherwise. */
public void set(boolean value) {
if (value) {
select();
} else {
deselect();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.frameworkium.core.htmlelements.element;

import com.frameworkium.core.common.properties.Property;
import com.frameworkium.core.ui.UITestLifecycle;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.support.events.EventFiringWebDriver;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;

import static com.frameworkium.core.htmlelements.utils.HtmlElementUtils.*;

/** Represents web page file upload element. */
public class FileInput extends TypifiedElement {

/**
* Specifies wrapped {@link WebElement}.
*
* @param wrappedElement {@code WebElement} to wrap.
*/
public FileInput(WebElement wrappedElement) {
super(wrappedElement);
}

/**
* Sets a file to be uploaded.
* <p>
* File is searched in the following way: if a resource with a specified name exists in classpath,
* then this resource will be used, otherwise file will be searched on file system.
*
* @param fileName Name of a file or a resource to be uploaded.
*/
public void setFileToUpload(final String fileName) {
// Set local file detector in case of remote driver usage
setLocalFileDetectorIfRequired();

String filePath = getFilePath(fileName);
sendKeys(filePath);
}

/**
* Sets multiple files to be uploaded.
* <p>
* Files are searched in the following way:
* if a resource with a specified name exists in classpath,
* then this resource will be used, otherwise file will be searched on file system.
*
* @param fileNames a list of file Names to be uploaded.
*/
public void setFilesToUpload(List<String> fileNames) {
// Set local file detector in case of remote driver usage
setLocalFileDetectorIfRequired();

String filePaths = fileNames.stream()
.map(this::getFilePath)
.collect(Collectors.joining("\n"));
sendKeys(filePaths);
}

private void setLocalFileDetectorIfRequired() {
if (Property.GRID_URL.isSpecified()) {
WebDriver webDriver = UITestLifecycle.get().getWebDriver();
EventFiringWebDriver efDriver = (EventFiringWebDriver) webDriver;
RemoteWebDriver remoteDriver = (RemoteWebDriver) efDriver.getWrappedDriver();
remoteDriver.setFileDetector(new LocalFileDetector());
}
}

/**
* Submits selected file by simply submitting the whole form, which contains this file input.
*/
public void submit() {
getWrappedElement().submit();
}

private WebElement getNotProxiedInputElement() {
return getWrappedElement().findElement(By.xpath("."));
}

private void setLocalFileDetector(RemoteWebElement element) {
element.setFileDetector(new LocalFileDetector());
}

private String getFilePath(final String fileName) {
if (existsInClasspath(fileName)) {
return getPathForResource(fileName);
}
return getPathForSystemFile(fileName);
}

private String getPathForResource(final String fileName) {
return getResourceFromClasspath(fileName).getPath();
}

private String getPathForSystemFile(final String fileName) {
File file = new File(fileName);
return file.getPath();
}
}
115 changes: 115 additions & 0 deletions src/main/java/com/frameworkium/core/htmlelements/element/Form.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.frameworkium.core.htmlelements.element;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.*;

import static java.util.Objects.isNull;

/**
* Represents web page form tag.
* Provides handy way of filling form with data and submitting it.
*/
public class Form extends TypifiedElement {

private static final String CHECKBOX_FIELD = "checkbox";
private static final String RADIO_FIELD = "radio";
private static final String SELECT_FIELD = "select";
private static final String INPUT_FIELD = "input";
private static final String FILE_FIELD = "file";

/**
* Specifies {@link WebElement} representing form tag.
*
* @param wrappedElement {@code WebElement} to wrap.
*/
public Form(WebElement wrappedElement) {
super(wrappedElement);
}

/**
* Fills form with data contained in passed map.
* 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) {
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);
}
}

protected void fillElement(WebElement element, String value) {
String elementType = getElementType(element);

if (CHECKBOX_FIELD.equals(elementType)) {
fillCheckBox(element, value);
} else if (RADIO_FIELD.equals(elementType)) {
fillRadio(element, value);
} else if (INPUT_FIELD.equals(elementType)) {
fillInput(element, value);
} else if (SELECT_FIELD.equals(elementType)) {
fillSelect(element, value);
} else if (FILE_FIELD.equals(elementType)) {
fillFile(element, value);
}
}

protected String getElementType(WebElement element) {
String tagName = element.getTagName();
if ("input".equals(tagName)) {
String type = element.getAttribute("type");
if ("checkbox".equals(type)) {
return CHECKBOX_FIELD;
} else if ("radio".equals(type)) {
return RADIO_FIELD;
} else if ("file".equals(type)) {
return FILE_FIELD;
} else {
return INPUT_FIELD;
}
} else if ("select".equals(tagName)) {
return SELECT_FIELD;
} else if ("textarea".equals(tagName)) {
return INPUT_FIELD;
} else {
return null;
}
}

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

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

protected void fillInput(WebElement element, String value) {
TextInput input = new TextInput(element);
input.sendKeys(input.getClearCharSequence() + value);
}

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

protected void fillFile(WebElement element, String value) {
new FileInput(element).setFileToUpload(value);
}
}
Loading