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

Commit 3e8bc73

Browse files
authored
Merge pull request #82 from YauheniPo/feature/data_utils_keywords
Feature/data utils keywords
2 parents 265e2b1 + 6293b92 commit 3e8bc73

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.markusbernhardt.seleniumlibrary;
22

33
import com.github.markusbernhardt.seleniumlibrary.keywords.BrowserManagement;
4+
import com.github.markusbernhardt.seleniumlibrary.keywords.Logging;
45
import com.github.markusbernhardt.seleniumlibrary.keywords.Robot;
56
import org.openqa.selenium.WebDriver;
67

@@ -16,7 +17,8 @@ public class CustomRobotDriverElement {
1617

1718
private static SeleniumLibrary s;
1819
private static BrowserManagement b;
19-
private Robot robot = new Robot();
20+
protected Robot robot = new Robot();
21+
protected Logging logging = new Logging();
2022

2123
public CustomRobotDriverElement() throws NoSuchFieldException, IllegalAccessException {
2224
try {
@@ -41,9 +43,4 @@ private static SeleniumLibrary getLibraryInstance() throws ScriptException {
4143
protected WebDriver getCurrentBrowser() {
4244
return b.getCurrentWebDriver();
4345
}
44-
45-
protected Robot getRobot() {
46-
return robot;
47-
}
48-
4946
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.github.markusbernhardt.seleniumlibrary.keywords;
2+
3+
import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter;
4+
import org.robotframework.javalib.annotation.ArgumentNames;
5+
import org.robotframework.javalib.annotation.Autowired;
6+
import org.robotframework.javalib.annotation.RobotKeyword;
7+
import org.robotframework.javalib.annotation.RobotKeywords;
8+
9+
import java.util.ArrayList;
10+
import java.util.Collections;
11+
import java.util.List;
12+
import java.util.Locale;
13+
14+
@RobotKeywords
15+
public class DataUtils extends RunOnFailureKeywordsAdapter {
16+
17+
private static final String ASCENDING = "ascending";
18+
private static final String DESCENDING = "descending";
19+
20+
@Autowired
21+
protected Robot robot;
22+
23+
/**
24+
* Instantiated Logging keyword bean
25+
*/
26+
@Autowired
27+
protected Logging logging;
28+
29+
// ##############################
30+
// Keywords
31+
// ##############################
32+
33+
/**
34+
* Sort list of strings.
35+
*
36+
* @param jsonStringOfList json string of list strings
37+
* @param params sorting order
38+
* @return sorting list of strings
39+
*/
40+
@RobotKeyword("Returns sorting list of strings by ``order``.")
41+
@ArgumentNames({"list", "order=ascending"})
42+
public List<String> sortStrings(String jsonStringOfList, String... params) {
43+
List<String> listOfStrings = robot.parseRobotList(jsonStringOfList);
44+
String order = robot.getParamsValue(params, 0, ASCENDING);
45+
List<String> sortedList = new ArrayList<>(listOfStrings);
46+
if (order.equalsIgnoreCase(DESCENDING)) {
47+
listOfStrings.sort(Collections.reverseOrder());
48+
} else {
49+
Collections.sort(listOfStrings);
50+
}
51+
logging.info(String.format("Sorted list '%s' by %s", sortedList, order.toUpperCase(Locale.ENGLISH)));
52+
return sortedList;
53+
}
54+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,8 @@ public void xpathShouldMatchXTimes(String xpath, int expectedXpathCount, String.
934934
@RobotKeyword("Click to element from list elements by locator ``xpath``.")
935935
@ArgumentNames({"xpath", "index=0", "message=NONE"})
936936
public void clickElementByIndex(String xpath, String... params) {
937-
String message = robot.getParamsValue(params, 0, "");
938-
int index = robot.getParamsValue(params, 1, 0);
937+
int index = robot.getParamsValue(params, 0, 0);
938+
String message = robot.getParamsValue(params, 1, "");
939939
List<WebElement> elements = elementFind(xpath, false, false);
940940
if (elements.isEmpty()) {
941941
if (message.isEmpty()) {

0 commit comments

Comments
 (0)