Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Using Java's printing for logging #95

Merged
merged 3 commits into from
Nov 12, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.project
.settings
.classpath
.vscode
target
webdriver
/libspecs/
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<artifactId>webdrivermanager</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -227,6 +232,7 @@
<variables>
<variable>browser:${browser}</variable>
<variable>downloadWebDriver:${downloadWebDriver}</variable>
<variable>testHTMLDirectory:${project.basedir}/src/test/resources</variable>
</variables>
<report>target/robotframework-reports/${browser}_report.html</report>
<log>target/robotframework-reports/${browser}_log.html</log>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -201,8 +200,8 @@ protected void pageShouldContainElement(String locator, String tag, String messa
}
}

@RobotKeyword("Verify the element identified by ``locator`` is not found on the current page\r\n" +
"\r\n" +
@RobotKeyword("Verify the element identified by ``locator`` is not found on the current page\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about log levels and locators.")
@ArgumentNames({ "locator", "message=NONE", "logLevel=INFO" })
public void pageShouldNotContainElement(String locator, String...params) {
Expand Down Expand Up @@ -255,7 +254,7 @@ public void elementShouldBeEnabled(String locator) {
}

@RobotKeyword("Verify the element identified by ``locator`` is disabled.\r\n" +
"\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public void elementShouldBeDisabled(String locator) {
Expand All @@ -275,7 +274,7 @@ public void elementShouldBeFocused(String locator) {
}

@RobotKeyword("Verify the element identified by ``locator`` is selected.\r\n" +
"\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "message=NONE" })
public void elementShouldBeSelected(String locator, String...params) {
Expand All @@ -292,7 +291,7 @@ public void elementShouldBeSelected(String locator, String...params) {
}

@RobotKeyword("Verify the element identified by ``locator`` is not selected.\r\n" +
"\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "message=NONE" })
public void elementShouldNotBeSelected(String locator, String...params) {
Expand Down Expand Up @@ -327,10 +326,10 @@ public void elementShouldBeVisible(String locator, String...params) {
}
}

@RobotKeyword("Verify the element identified by ``locator`` is not visible.\r\n" +
"\r\n" +
"Herein, visible means that the element is logically visible, not optically visible in the current browser viewport. For example, an element that carries display:none is not logically visible, so using this keyword on that element would fail.\r\n" +
"\r\n" +
@RobotKeyword("Verify the element identified by ``locator`` is not visible.\r\n" +
"\r\n" +
"Herein, visible means that the element is logically visible, not optically visible in the current browser viewport. For example, an element that carries display:none is not logically visible, so using this keyword on that element would fail.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "message=NONE" })
public void elementShouldNotBeVisible(String locator, String...params) {
Expand All @@ -346,8 +345,8 @@ public void elementShouldNotBeVisible(String locator, String...params) {
}
}

@RobotKeyword("Verify the element identified by ``locator`` is clickable.\r\n" +
"\r\n" +
@RobotKeyword("Verify the element identified by ``locator`` is clickable.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "message=NONE" })
public void elementShouldBeClickable(String locator, String...params) {
Expand All @@ -363,8 +362,8 @@ public void elementShouldBeClickable(String locator, String...params) {
}
}

@RobotKeyword("Verify the element identified by ``locator`` is not clickable.\r\n" +
"\r\n" +
@RobotKeyword("Verify the element identified by ``locator`` is not clickable.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "message=NONE" })
public void elementShouldNotBeClickable(String locator, String...params) {
Expand Down Expand Up @@ -400,10 +399,10 @@ public void elementTextShouldBe(String locator, String text, String...params) {
}
}

@RobotKeyword("Verify the text of the element identified by ``locator`` is not exactly ``text``.\r\n" +
"\r\n" +
"In contrast to `Element Should Not Contain`, this keyword does not try a substring match but an exact match on the element identified by locator.\r\n" +
"\r\n" +
@RobotKeyword("Verify the text of the element identified by ``locator`` is not exactly ``text``.\r\n" +
"\r\n" +
"In contrast to `Element Should Not Contain`, this keyword does not try a substring match but an exact match on the element identified by locator.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "text", "message=NONE", "ignore_case=False" })
public void elementTextShouldNotBe(String locator, String text, String...params) {
Expand Down Expand Up @@ -511,16 +510,16 @@ public int getHorizontalPosition(String locator) {
return elements.get(0).getLocation().getX();
}

@RobotKeyword("Returns the value attribute of the element identified by ``locator``..\r\n" +
"\r\n" +
@RobotKeyword("Returns the value attribute of the element identified by ``locator``..\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public String getValue(String locator) {
return getValue(locator, null);
}

protected String getValue(String locator, String tag) {
List<WebElement> elements = elementFind(locator, true, false, tag);
List<WebElement> elements = elementFind(locator, true, true, tag);

if (elements.size() == 0) {
return null;
Expand All @@ -529,8 +528,8 @@ protected String getValue(String locator, String tag) {
return elements.get(0).getAttribute("value");
}

@RobotKeyword("Returns the text of the element identified by ``locator``..\r\n" +
"\r\n" +
@RobotKeyword("Returns the text of the element identified by ``locator``..\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public String getText(String locator) {
Expand All @@ -543,10 +542,10 @@ public String getText(String locator) {
return elements.get(0).getText();
}

@RobotKeyword("Returns vertical position of element identified by ``locator``.\r\n" +
"\r\n" +
"The position is returned in pixels off the left side of the page, as an integer. Fails if the matching element is not found.\r\n" +
"\r\n" +
@RobotKeyword("Returns vertical position of element identified by ``locator``.\r\n" +
"\r\n" +
"The position is returned in pixels off the left side of the page, as an integer. Fails if the matching element is not found.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public int getVerticalPosition(String locator) {
Expand All @@ -564,8 +563,8 @@ public int getVerticalPosition(String locator) {
// Keywords - Mouse Input/Events
// ##############################

@RobotKeyword("Click on the element identified by ``locator``.\r\n" +
"\r\n" +
@RobotKeyword("Click on the element identified by ``locator``.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public void clickElement(String locator) {
Expand All @@ -575,10 +574,10 @@ public void clickElement(String locator) {
elements.get(0).click();
}

@RobotKeyword("Click on the element identified by locator at the coordinates ``xOffset`` and ``yOffset``.\r\n" +
"\r\n" +
"The cursor is moved at the center of the element and the to the given x/y offset from that point. Both offsets are specified as negative (left/up) or positive (right/down) number.\r\n" +
"\r\n" +
@RobotKeyword("Click on the element identified by locator at the coordinates ``xOffset`` and ``yOffset``.\r\n" +
"\r\n" +
"The cursor is moved at the center of the element and the to the given x/y offset from that point. Both offsets are specified as negative (left/up) or positive (right/down) number.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator", "xOffset", "yOffset" })
public void clickElementAtCoordinates(String locator, String xOffset, String yOffset) {
Expand All @@ -590,8 +589,8 @@ public void clickElementAtCoordinates(String locator, String xOffset, String yOf
action.moveToElement(element).moveByOffset(Integer.parseInt(xOffset), Integer.parseInt(yOffset)).perform();
}

@RobotKeyword("Double-Click on the element identified by ``locator``.\r\n" +
"\r\n" +
@RobotKeyword("Double-Click on the element identified by ``locator``.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public void doubleClickElement(String locator) {
Expand Down Expand Up @@ -671,8 +670,8 @@ public void mouseDown(String locator) {
action.clickAndHold(elements.get(0)).perform();
}

@RobotKeyword("Simulates moving the mouse away from the element identified by ``locator``.\r\n" +
"\r\n" +
@RobotKeyword("Simulates moving the mouse away from the element identified by ``locator``.\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
@ArgumentNames({ "locator" })
public void mouseOut(String locator) {
Expand Down Expand Up @@ -1128,7 +1127,7 @@ protected CharSequence mapAsciiKeyCodeToKey(int keyCode) {
public static String escapeXpathValue(String value) {
if (value.contains("\"") && value.contains("'")) {
String[] partsWoApos = value.split("'");
return String.format("concat('%s')", Python.join("', \"'\", '", Arrays.asList(partsWoApos)));
return String.format("concat('%s')", StringUtils.join(partsWoApos, "', \"'\", '"));
}
if (value.contains("'")) {
return String.format("\"%s\"", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.WebElement;
import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.Autowired;
Expand Down Expand Up @@ -252,8 +253,8 @@ public void pageShouldNotContainTextfield(String locator, String...params) {
public void textfieldValueShouldBe(String locator, String text, String...params) {
String message = robot.getParamsValue(params, 0, "");
String actual = element.getValue(locator, "text field");
if (!actual.contains(text)) {
if (message == null) {
if (actual == null || !actual.contains(text)) {
if (StringUtils.isEmpty(message)) {
message = String.format("Value of text field '%s' should have been '%s' but was '%s'", locator, text,
actual);
}
Expand Down
Loading