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

Commit 4a911cb

Browse files
committed
Added local HTML for test
Fixes #52 Added input field types from Python version Some refactoring
1 parent cc46f64 commit 4a911cb

File tree

8 files changed

+41
-12
lines changed

8 files changed

+41
-12
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
<variables>
228228
<variable>browser:${browser}</variable>
229229
<variable>downloadWebDriver:${downloadWebDriver}</variable>
230+
<variable>testHTMLDirectory:${project.basedir}/src/test/resources</variable>
230231
</variables>
231232
<report>target/robotframework-reports/${browser}_report.html</report>
232233
<log>target/robotframework-reports/${browser}_log.html</log>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public String getRemoteCapabilities() {
319319
// Null returned from jbrowserdriver
320320
if (getCurrentWebDriver() instanceof RemoteWebDriver
321321
&& ((RemoteWebDriver) getCurrentWebDriver()).getCapabilities() != null) {
322-
System.out.println(getCurrentWebDriver());
322+
logging.info(getCurrentWebDriver());
323323
return ((RemoteWebDriver) getCurrentWebDriver()).getCapabilities().toString();
324324
} else {
325325
return "No remote session id or capabilities available";

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

Lines changed: 1 addition & 2 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;
@@ -520,7 +519,7 @@ public String getValue(String locator) {
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;

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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected void error(String msg) {
198198
protected void log(String msg, String logLevel) {
199199
String[] methodParameters = VALID_LOG_LEVELS.get(logLevel.toLowerCase());
200200
if (methodParameters != null) {
201-
System.out.printf("*%s* %s ", logLevel.toUpperCase(), msg);
201+
System.out.println(String.format("*%s* %s", logLevel.toUpperCase(), msg));
202202
} else {
203203
throw new SeleniumLibraryNonFatalException(String.format("Given log level %s is invalid.", logLevel));
204204
}

src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/ElementFinder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected static boolean elementMatches(WebElement element, FindByCoordinates fi
158158

159159
if (findByCoordinates.constraints != null) {
160160
for (String name : findByCoordinates.constraints.keySet()) {
161-
if (!element.getAttribute(name).equals(findByCoordinates.constraints.get(name))) {
161+
if (findByCoordinates.constraints.get(name) != null && !Arrays.asList(findByCoordinates.constraints.get(name).split(",")).contains(element.getAttribute(name))) {
162162
return false;
163163
}
164164
}
@@ -184,17 +184,18 @@ protected static List<WebElement> findByKeyAttrs(WebDriver webDriver, FindByCoor
184184
List<String> xpathConstraints = new ArrayList<>();
185185
if (findByCoordinates.constraints != null) {
186186
for (Entry<String, String> entry : findByCoordinates.constraints.entrySet()) {
187-
xpathConstraints.add(String.format("@%s='%s'", entry.getKey(), entry.getValue()));
187+
for (String value: entry.getValue().split(",")) {
188+
xpathConstraints.add(String.format("@%s='%s'", entry.getKey(), value));
189+
}
188190
}
189191
}
190192
List<String> xpathSearchers = new ArrayList<>();
191193
for (String attr : keyAttrs.getKeyAttrs()) {
192194
xpathSearchers.add(String.format("%s=%s", attr, xpathCriteria));
193195
}
194196
xpathSearchers.addAll(getAttrsWithUrl(webDriver, keyAttrs, findByCoordinates.criteria));
195-
String xpath = String.format("//%s[%s(%s)]", xpathTag, Python.join(" and ", xpathConstraints)
196-
+ (xpathConstraints.size() > 0 ? " and " : ""), Python.join(" or ", xpathSearchers));
197-
197+
String xpath = String.format("//%s[(%s)%s(%s)]", xpathTag, Python.join(" or ", xpathConstraints)
198+
,(xpathConstraints.size() > 0 ? " and " : ""), Python.join(" or ", xpathSearchers));
198199
return webDriver.findElements(By.xpath(xpath));
199200
}
200201

@@ -319,7 +320,7 @@ protected static void parseTag(FindByCoordinates findByCoordinates, String tag)
319320
break;
320321
case "text field":
321322
tag = "input";
322-
constraints.put("type", "text");
323+
constraints.put("type", "date,datetime-local,email,month,number,password,search,tel,text,time,url,week,file");
323324
break;
324325
case "file upload":
325326
tag = "input";

src/test/resources/formtest.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html><head>
2+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
3+
<title></title>
4+
5+
</head>
6+
<body>
7+
First name:<br>
8+
<input type="text" name="firstname" value="Mickey">
9+
<br>
10+
Last name:<br>
11+
<input type="text" name="lastname" value="Mouse">
12+
<br><br>
13+
Add your homepage:
14+
<input type="url" name="homepage" value="http://example.com">
15+
</body></html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*** Settings ***
2+
Suite Teardown Close All Browsers
3+
Resource ../../settings/Settings.robot
4+
5+
*** Variables ***
6+
${URL Application} http://www.w3schools.com
7+
8+
*** Test Cases ***
9+
Check Form
10+
Open Browser file:///${testHTMLDirectory}/formtest.html ${browser}
11+
Textfield Value Should Be name:firstname Mickey
12+
Textfield Value Should Be name:homepage http://example.com

0 commit comments

Comments
 (0)