diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java index 2f2d194..5a20a16 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java @@ -1,6 +1,7 @@ package com.github.markusbernhardt.seleniumlibrary; import com.github.markusbernhardt.seleniumlibrary.keywords.BrowserManagement; +import com.github.markusbernhardt.seleniumlibrary.keywords.Logging; import com.github.markusbernhardt.seleniumlibrary.keywords.Robot; import org.openqa.selenium.WebDriver; @@ -16,7 +17,8 @@ public class CustomRobotDriverElement { private static SeleniumLibrary s; private static BrowserManagement b; - private Robot robot = new Robot(); + protected Robot robot = new Robot(); + protected Logging logging = new Logging(); public CustomRobotDriverElement() throws NoSuchFieldException, IllegalAccessException { try { @@ -41,9 +43,4 @@ private static SeleniumLibrary getLibraryInstance() throws ScriptException { protected WebDriver getCurrentBrowser() { return b.getCurrentWebDriver(); } - - protected Robot getRobot() { - return robot; - } - } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/DataUtils.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/DataUtils.java new file mode 100644 index 0000000..e47f2fc --- /dev/null +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/DataUtils.java @@ -0,0 +1,54 @@ +package com.github.markusbernhardt.seleniumlibrary.keywords; + +import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter; +import org.robotframework.javalib.annotation.ArgumentNames; +import org.robotframework.javalib.annotation.Autowired; +import org.robotframework.javalib.annotation.RobotKeyword; +import org.robotframework.javalib.annotation.RobotKeywords; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +@RobotKeywords +public class DataUtils extends RunOnFailureKeywordsAdapter { + + private static final String ASCENDING = "ascending"; + private static final String DESCENDING = "descending"; + + @Autowired + protected Robot robot; + + /** + * Instantiated Logging keyword bean + */ + @Autowired + protected Logging logging; + + // ############################## + // Keywords + // ############################## + + /** + * Sort list of strings. + * + * @param jsonStringOfList json string of list strings + * @param params sorting order + * @return sorting list of strings + */ + @RobotKeyword("Returns sorting list of strings by ``order``.") + @ArgumentNames({"list", "order=ascending"}) + public List sortStrings(String jsonStringOfList, String... params) { + List listOfStrings = robot.parseRobotList(jsonStringOfList); + String order = robot.getParamsValue(params, 0, ASCENDING); + List sortedList = new ArrayList<>(listOfStrings); + if (order.equalsIgnoreCase(DESCENDING)) { + listOfStrings.sort(Collections.reverseOrder()); + } else { + Collections.sort(listOfStrings); + } + logging.info(String.format("Sorted list '%s' by %s", sortedList, order.toUpperCase(Locale.ENGLISH))); + return sortedList; + } +} diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java index a8c3ac4..ff74415 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java @@ -934,8 +934,8 @@ public void xpathShouldMatchXTimes(String xpath, int expectedXpathCount, String. @RobotKeyword("Click to element from list elements by locator ``xpath``.") @ArgumentNames({"xpath", "index=0", "message=NONE"}) public void clickElementByIndex(String xpath, String... params) { - String message = robot.getParamsValue(params, 0, ""); - int index = robot.getParamsValue(params, 1, 0); + int index = robot.getParamsValue(params, 0, 0); + String message = robot.getParamsValue(params, 1, ""); List elements = elementFind(xpath, false, false); if (elements.isEmpty()) { if (message.isEmpty()) {