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

Commit 9b83f26

Browse files
committed
Corrected by review comments
1 parent c7961e0 commit 9b83f26

File tree

6 files changed

+133
-75
lines changed

6 files changed

+133
-75
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public String getCookies() {
4747
ArrayList<org.openqa.selenium.Cookie> cookies = new ArrayList<>(browserManagement
4848
.getCurrentWebDriver().manage().getCookies());
4949
for (int i = 0; i < cookies.size(); i++) {
50-
ret.append(cookies.get(i).getName()).append("=").append(cookies.get(i).getValue());
50+
ret.append(cookies.get(i).getName()).append('=').append(cookies.get(i).getValue());
5151
if (i != cookies.size() - 1) {
5252
ret.append("; ");
5353
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5+
import java.util.Collections;
56
import java.util.List;
67

78
import org.openqa.selenium.NoSuchElementException;
@@ -222,6 +223,7 @@ public void selectFromList(String locator, String... items) {
222223
} catch (NoSuchElementException e2) {
223224
nonExistingItems.add(item);
224225
lastItemFound = false;
226+
continue;
225227
}
226228
}
227229
}
@@ -256,7 +258,8 @@ public void selectFromListByIndex(String locator, String... indexes) {
256258
throw new SeleniumLibraryNonFatalException("No index given.");
257259
}
258260

259-
List<String> tmp = new ArrayList<>(Arrays.asList(indexes));
261+
List<String> tmp = new ArrayList<>();
262+
Collections.addAll(tmp, indexes);
260263
String items = String.format("index(es) '%s'", Python.join(", ", tmp));
261264
logging.info(String.format("Selecting %s from list '%s'.", items, locator));
262265

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

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.github.markusbernhardt.seleniumlibrary.keywords;
22

3+
import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter;
4+
import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException;
5+
import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework;
36
import org.apache.commons.lang3.exception.ExceptionUtils;
47
import org.openqa.selenium.JavascriptExecutor;
58
import org.robotframework.javalib.annotation.ArgumentNames;
69
import org.robotframework.javalib.annotation.Autowired;
710
import org.robotframework.javalib.annotation.RobotKeyword;
811
import org.robotframework.javalib.annotation.RobotKeywords;
912

10-
import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter;
11-
import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException;
12-
import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework;
13-
1413
@RobotKeywords
1514
public class Waiting extends RunOnFailureKeywordsAdapter {
1615

@@ -52,8 +51,10 @@ public void waitForCondition(final String condition, String...params) {
5251
if (message == null) {
5352
message = String.format("Condition '%s' did not become true in <TIMEOUT>", condition);
5453
}
55-
waitUntil(timeout, message, () -> Boolean.TRUE.equals(((JavascriptExecutor) browserManagement.getCurrentWebDriver())
56-
.executeScript(condition)));
54+
waitUntil(
55+
timeout,
56+
message,
57+
() -> Boolean.TRUE.equals(((JavascriptExecutor) browserManagement.getCurrentWebDriver()).executeScript(condition)));
5758
}
5859

5960
@RobotKeyword("Waits until the current page contains ``text``.\r\n" +
@@ -68,7 +69,10 @@ public void waitUntilPageContains(final String text, String...params) {
6869
if (message == null) {
6970
message = String.format("Text '%s' did not appear in <TIMEOUT>", text);
7071
}
71-
waitUntil(timeout, message, () -> element.isTextPresent(text));
72+
waitUntil(
73+
timeout,
74+
message,
75+
() -> element.isTextPresent(text));
7276
}
7377

7478
@RobotKeyword("Waits until the current page does not contain ``text``.\r\n" +
@@ -83,7 +87,10 @@ public void waitUntilPageNotContains(final String text, String...params) {
8387
if (message == null) {
8488
message = String.format("Text '%s' did not disappear in <TIMEOUT>", text);
8589
}
86-
waitUntil(timeout, message, () -> !element.isTextPresent(text));
90+
waitUntil(
91+
timeout,
92+
message,
93+
() -> !element.isTextPresent(text));
8794
}
8895

8996
@RobotKeyword("Waits until the current page does not contain ``text``.\r\n" +
@@ -110,7 +117,10 @@ public void waitUntilPageContainsElement(final String locator, String...params)
110117
if (message == null) {
111118
message = String.format("Element '%s' did not appear in <TIMEOUT>", locator);
112119
}
113-
waitUntil(timeout, message, () -> element.isElementPresent(locator));
120+
waitUntil(
121+
timeout,
122+
message,
123+
() -> element.isElementPresent(locator));
114124
}
115125

116126
@RobotKeyword("Waits until the element identified by ``locator`` is not found on the current page.\r\n" +
@@ -125,7 +135,10 @@ public void waitUntilPageNotContainsElement(final String locator, String...param
125135
if (message == null) {
126136
message = String.format("Element '%s' did not disappear in <TIMEOUT>", locator);
127137
}
128-
waitUntil(timeout, message, () -> !element.isElementPresent(locator));
138+
waitUntil(
139+
timeout,
140+
message,
141+
() -> !element.isElementPresent(locator));
129142
}
130143

131144
@RobotKeyword("Waits until the element identified by ``locator`` is not found on the current page.\r\n" +
@@ -152,7 +165,10 @@ public void waitUntilElementIsVisible(final String locator, String...params) {
152165
if (message == null) {
153166
message = String.format("Element '%s' not visible in <TIMEOUT>", locator);
154167
}
155-
waitUntil(timeout, message, () -> element.isVisible(locator));
168+
waitUntil(
169+
timeout,
170+
message,
171+
() -> element.isVisible(locator));
156172
}
157173

158174
@RobotKeyword("Waits until the element identified by ``locator`` is not visible.\r\n" +
@@ -167,7 +183,10 @@ public void waitUntilElementIsNotVisible(final String locator, String...params)
167183
if (message == null) {
168184
message = String.format("Element '%s' still visible in <TIMEOUT>", locator);
169185
}
170-
waitUntil(timeout, message, () -> !element.isVisible(locator));
186+
waitUntil(
187+
timeout,
188+
message,
189+
() -> !element.isVisible(locator));
171190
}
172191

173192
@RobotKeyword("Waits until the element identified by ``locator`` is clickable.\r\n" +
@@ -182,7 +201,10 @@ public void waitUntilElementIsClickable(final String locator, String...params) {
182201
if (message == null) {
183202
message = String.format("Element '%s' not clickable in <TIMEOUT>", locator);
184203
}
185-
waitUntil(timeout, message, () -> element.isClickable(locator));
204+
waitUntil(
205+
timeout,
206+
message,
207+
() -> element.isClickable(locator));
186208
}
187209

188210
@RobotKeyword("Waits until the element identified by ``locator`` is not clickable.\r\n" +
@@ -197,7 +219,10 @@ public void waitUntilElementIsNotClickable(final String locator, String...params
197219
if (message == null) {
198220
message = String.format("Element '%s' still clickable in <TIMEOUT>", locator);
199221
}
200-
waitUntil(timeout, message, () -> !element.isClickable(locator));
222+
waitUntil(
223+
timeout,
224+
message,
225+
() -> !element.isClickable(locator));
201226
}
202227

203228
@RobotKeyword("Waits until the element identified by ``locator`` is succesfully clicked on.\r\n" +
@@ -212,10 +237,13 @@ public void waitUntilElementIsSuccessfullyClicked(final String locator, String..
212237
if (message == null) {
213238
message = String.format("Element '%s' not successfully clicked in <TIMEOUT>", locator);
214239
}
215-
waitUntil(timeout, message, () -> {
216-
element.clickElement(locator);
217-
return true;
218-
});
240+
waitUntil(
241+
timeout,
242+
message,
243+
() -> {
244+
element.clickElement(locator);
245+
return true;
246+
});
219247
}
220248

221249
@RobotKeyword("Waits until the element identified by ``locator`` is selected.\r\n" +
@@ -230,7 +258,10 @@ public void waitUntilElementIsSelected(final String locator, String...params) {
230258
if (message == null) {
231259
message = String.format("Element '%s' not selected in <TIMEOUT>", locator);
232260
}
233-
waitUntil(timeout, message, () -> element.isSelected(locator));
261+
waitUntil(
262+
timeout,
263+
message,
264+
() -> element.isSelected(locator));
234265
}
235266

236267
@RobotKeyword("Waits until the element identified by ``locator`` is not selected.\r\n" +
@@ -245,7 +276,10 @@ public void waitUntilElementIsNotSelected(final String locator, String...params)
245276
if (message == null) {
246277
message = String.format("Element '%s' still selected in <TIMEOUT>", locator);
247278
}
248-
waitUntil(timeout, message, () -> !element.isSelected(locator));
279+
waitUntil(
280+
timeout,
281+
message,
282+
() -> !element.isSelected(locator));
249283
}
250284

251285
@RobotKeyword("Waits until the current page title contains ``title``.\r\n" +
@@ -260,10 +294,13 @@ public void waitUntilTitleContains(final String title, String...params) {
260294
if (message == null) {
261295
message = String.format("Title '%s' did not appear in <TIMEOUT>", title);
262296
}
263-
waitUntil(timeout, message, () -> {
264-
String currentTitle = browserManagement.getTitle();
265-
return currentTitle != null && currentTitle.contains(title);
266-
});
297+
waitUntil(
298+
timeout,
299+
message,
300+
() -> {
301+
String currentTitle = browserManagement.getTitle();
302+
return currentTitle != null && currentTitle.contains(title);
303+
});
267304
}
268305

269306
@RobotKeyword("Waits until the current page title does not contain ``title``.\r\n" +
@@ -278,10 +315,13 @@ public void waitUntilTitleNotContains(final String title, String...params) {
278315
if (message == null) {
279316
message = String.format("Title '%s' did not appear in <TIMEOUT>", title);
280317
}
281-
waitUntil(timeout, message, () -> {
282-
String currentTitle = browserManagement.getTitle();
283-
return currentTitle == null || !currentTitle.contains(title);
284-
});
318+
waitUntil(
319+
timeout,
320+
message,
321+
() -> {
322+
String currentTitle = browserManagement.getTitle();
323+
return currentTitle == null || !currentTitle.contains(title);
324+
});
285325
}
286326

287327
@RobotKeyword("Waits until the current page title is exactly ``title``.\r\n" +
@@ -296,10 +336,13 @@ public void waitUntilTitleIs(final String title, String...params) {
296336
if (message == null) {
297337
message = String.format("Title '%s' did not appear in <TIMEOUT>", title);
298338
}
299-
waitUntil(timeout, message, () -> {
300-
String currentTitle = browserManagement.getTitle();
301-
return currentTitle != null && currentTitle.equals(title);
302-
});
339+
waitUntil(
340+
timeout,
341+
message,
342+
() -> {
343+
String currentTitle = browserManagement.getTitle();
344+
return currentTitle != null && currentTitle.equals(title);
345+
});
303346
}
304347

305348
@RobotKeyword("Waits until the current page title is not exactly ``title``.\r\n" +
@@ -314,10 +357,13 @@ public void waitUntilTitleIsNot(final String title, String...params) {
314357
if (message == null) {
315358
message = String.format("Title '%s' did not appear in <TIMEOUT>", title);
316359
}
317-
waitUntil(timeout, message, () -> {
318-
String currentTitle = browserManagement.getTitle();
319-
return currentTitle == null || !currentTitle.equals(title);
320-
});
360+
waitUntil(
361+
timeout,
362+
message,
363+
() -> {
364+
String currentTitle = browserManagement.getTitle();
365+
return currentTitle == null || !currentTitle.equals(title);
366+
});
321367
}
322368

323369
// ##############################
@@ -348,6 +394,7 @@ protected void waitUntil(String timestr, String message, WaitUntilFunction funct
348394
}
349395
}
350396

397+
@FunctionalInterface
351398
protected interface WaitUntilFunction {
352399

353400
boolean isFinished();

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -296,36 +296,36 @@ protected static void parseTag(FindByCoordinates findByCoordinates, String tag)
296296

297297
tag = tag.toLowerCase();
298298
Map<String, String> constraints = new TreeMap<>();
299-
switch (tag) {
300-
case "link":
301-
tag = "a";
302-
break;
303-
case "image":
304-
tag = "img";
305-
break;
306-
case "list":
307-
tag = "select";
308-
break;
309-
case "text area":
310-
tag = "textarea";
311-
break;
312-
case "radio button":
313-
tag = "input";
314-
constraints.put("type", "radio");
315-
break;
316-
case "checkbox":
317-
tag = "input";
318-
constraints.put("type", "checkbox");
319-
break;
320-
case "text field":
321-
tag = "input";
322-
constraints.put("type", "text");
323-
break;
324-
case "file upload":
325-
tag = "input";
326-
constraints.put("type", "file");
327-
break;
328-
}
299+
switch(tag) {
300+
case "link":
301+
tag = "a";
302+
break;
303+
case "image":
304+
tag = "img";
305+
break;
306+
case "list":
307+
tag = "select";
308+
break;
309+
case "text area":
310+
tag = "textarea";
311+
break;
312+
case "radio button":
313+
tag = "input";
314+
constraints.put("type", "radio");
315+
break;
316+
case "checkbox":
317+
tag = "input";
318+
constraints.put("type", "checkbox");
319+
break;
320+
case "text field":
321+
tag = "input";
322+
constraints.put("type", "text");
323+
break;
324+
case "file upload":
325+
tag = "input";
326+
constraints.put("type", "file");
327+
break;
328+
}
329329
findByCoordinates.tag = tag;
330330
findByCoordinates.constraints = constraints;
331331
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static WebElement findByCol(WebDriver webDriver, String tableLocator, int
7272
}
7373

7474
protected static void addLocatorSuffix(Map<String, List<String>> locatorSuffixesMap, String key, String... values) {
75-
List<String> list = new ArrayList<>(Arrays.asList(values));
75+
List<String> list = new ArrayList<>();
76+
Collections.addAll(list, values);
7677
locatorSuffixesMap.put(key, list);
7778
}
7879

0 commit comments

Comments
 (0)