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

Commit 7164c25

Browse files
authored
Merge pull request #95 from Hi-Fi/logging_utf8
Using Java's printing for logging
2 parents 9844ad4 + 6160afc commit 7164c25

File tree

16 files changed

+442
-408
lines changed

16 files changed

+442
-408
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.project
22
.settings
33
.classpath
4+
.vscode
45
target
56
webdriver
67
/libspecs/

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@
145145
<artifactId>webdrivermanager</artifactId>
146146
<version>3.4.0</version>
147147
</dependency>
148+
<dependency>
149+
<groupId>org.apache.commons</groupId>
150+
<artifactId>commons-lang3</artifactId>
151+
<version>3.9</version>
152+
</dependency>
148153
</dependencies>
149154

150155
<build>
@@ -227,6 +232,7 @@
227232
<variables>
228233
<variable>browser:${browser}</variable>
229234
<variable>downloadWebDriver:${downloadWebDriver}</variable>
235+
<variable>testHTMLDirectory:${project.basedir}/src/test/resources</variable>
230236
</variables>
231237
<report>target/robotframework-reports/${browser}_report.html</report>
232238
<log>target/robotframework-reports/${browser}_log.html</log>

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java

Lines changed: 115 additions & 115 deletions
Large diffs are not rendered by default.

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5-
import java.util.Iterator;
65
import java.util.List;
76

87
import org.apache.commons.lang3.StringUtils;
@@ -201,8 +200,8 @@ protected void pageShouldContainElement(String locator, String tag, String messa
201200
}
202201
}
203202

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

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

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

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

330-
@RobotKeyword("Verify the element identified by ``locator`` is not visible.\r\n" +
331-
"\r\n" +
332-
"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" +
333-
"\r\n" +
329+
@RobotKeyword("Verify the element identified by ``locator`` is not visible.\r\n" +
330+
"\r\n" +
331+
"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" +
332+
"\r\n" +
334333
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
335334
@ArgumentNames({ "locator", "message=NONE" })
336335
public void elementShouldNotBeVisible(String locator, String...params) {
@@ -346,8 +345,8 @@ public void elementShouldNotBeVisible(String locator, String...params) {
346345
}
347346
}
348347

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

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

403-
@RobotKeyword("Verify the text of the element identified by ``locator`` is not exactly ``text``.\r\n" +
404-
"\r\n" +
405-
"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" +
406-
"\r\n" +
402+
@RobotKeyword("Verify the text of the element identified by ``locator`` is not exactly ``text``.\r\n" +
403+
"\r\n" +
404+
"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" +
405+
"\r\n" +
407406
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
408407
@ArgumentNames({ "locator", "text", "message=NONE", "ignore_case=False" })
409408
public void elementTextShouldNotBe(String locator, String text, String...params) {
@@ -511,16 +510,16 @@ public int getHorizontalPosition(String locator) {
511510
return elements.get(0).getLocation().getX();
512511
}
513512

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

522521
protected String getValue(String locator, String tag) {
523-
List<WebElement> elements = elementFind(locator, true, false, tag);
522+
List<WebElement> elements = elementFind(locator, true, true, tag);
524523

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

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

546-
@RobotKeyword("Returns vertical position of element identified by ``locator``.\r\n" +
547-
"\r\n" +
548-
"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" +
549-
"\r\n" +
545+
@RobotKeyword("Returns vertical position of element identified by ``locator``.\r\n" +
546+
"\r\n" +
547+
"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" +
548+
"\r\n" +
550549
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
551550
@ArgumentNames({ "locator" })
552551
public int getVerticalPosition(String locator) {
@@ -564,8 +563,8 @@ public int getVerticalPosition(String locator) {
564563
// Keywords - Mouse Input/Events
565564
// ##############################
566565

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

578-
@RobotKeyword("Click on the element identified by locator at the coordinates ``xOffset`` and ``yOffset``.\r\n" +
579-
"\r\n" +
580-
"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" +
581-
"\r\n" +
577+
@RobotKeyword("Click on the element identified by locator at the coordinates ``xOffset`` and ``yOffset``.\r\n" +
578+
"\r\n" +
579+
"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" +
580+
"\r\n" +
582581
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
583582
@ArgumentNames({ "locator", "xOffset", "yOffset" })
584583
public void clickElementAtCoordinates(String locator, String xOffset, String yOffset) {
@@ -590,8 +589,8 @@ public void clickElementAtCoordinates(String locator, String xOffset, String yOf
590589
action.moveToElement(element).moveByOffset(Integer.parseInt(xOffset), Integer.parseInt(yOffset)).perform();
591590
}
592591

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

674-
@RobotKeyword("Simulates moving the mouse away from the element identified by ``locator``.\r\n" +
675-
"\r\n" +
673+
@RobotKeyword("Simulates moving the mouse away from the element identified by ``locator``.\r\n" +
674+
"\r\n" +
676675
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
677676
@ArgumentNames({ "locator" })
678677
public void mouseOut(String locator) {
@@ -1128,7 +1127,7 @@ protected CharSequence mapAsciiKeyCodeToKey(int keyCode) {
11281127
public static String escapeXpathValue(String value) {
11291128
if (value.contains("\"") && value.contains("'")) {
11301129
String[] partsWoApos = value.split("'");
1131-
return String.format("concat('%s')", Python.join("', \"'\", '", Arrays.asList(partsWoApos)));
1130+
return String.format("concat('%s')", StringUtils.join(partsWoApos, "', \"'\", '"));
11321131
}
11331132
if (value.contains("'")) {
11341133
return String.format("\"%s\"", value);

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/FormElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.util.List;
55

6+
import org.apache.commons.lang3.StringUtils;
67
import org.openqa.selenium.WebElement;
78
import org.robotframework.javalib.annotation.ArgumentNames;
89
import org.robotframework.javalib.annotation.Autowired;
@@ -252,8 +253,8 @@ public void pageShouldNotContainTextfield(String locator, String...params) {
252253
public void textfieldValueShouldBe(String locator, String text, String...params) {
253254
String message = robot.getParamsValue(params, 0, "");
254255
String actual = element.getValue(locator, "text field");
255-
if (!actual.contains(text)) {
256-
if (message == null) {
256+
if (actual == null || !actual.contains(text)) {
257+
if (StringUtils.isEmpty(message)) {
257258
message = String.format("Value of text field '%s' should have been '%s' but was '%s'", locator, text,
258259
actual);
259260
}

0 commit comments

Comments
 (0)