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

Feature/data utils keywords #82

Merged
merged 3 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand All @@ -41,9 +43,4 @@ private static SeleniumLibrary getLibraryInstance() throws ScriptException {
protected WebDriver getCurrentBrowser() {
return b.getCurrentWebDriver();
}

protected Robot getRobot() {
return robot;
}

}
Original file line number Diff line number Diff line change
@@ -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<String> sortStrings(String jsonStringOfList, String... params) {
List<String> listOfStrings = robot.parseRobotList(jsonStringOfList);
String order = robot.getParamsValue(params, 0, ASCENDING);
List<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you fix a bug here? Or... what has been changed here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, fixed

List<WebElement> elements = elementFind(xpath, false, false);
if (elements.isEmpty()) {
if (message.isEmpty()) {
Expand Down