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

Commit eef989b

Browse files
authored
Merge pull request #74 from YauheniPo/feature/custom_robot_driver_element
added RobotString class for working with system properties and string…
2 parents cbe8ecb + 5cc545d commit eef989b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.github.markusbernhardt.seleniumlibrary;
2+
3+
import com.github.markusbernhardt.seleniumlibrary.keywords.BrowserManagement;
4+
import com.github.markusbernhardt.seleniumlibrary.keywords.Robot;
5+
import org.openqa.selenium.WebDriver;
6+
7+
import javax.script.ScriptEngine;
8+
import javax.script.ScriptEngineManager;
9+
import javax.script.ScriptException;
10+
import java.lang.reflect.Field;
11+
12+
/**
13+
* For extends of custom keywords of WebDriver actions
14+
*/
15+
public class CustomRobotDriverElement {
16+
17+
private static SeleniumLibrary s;
18+
private static BrowserManagement b;
19+
private Robot robot = new Robot();
20+
21+
public CustomRobotDriverElement() throws NoSuchFieldException, IllegalAccessException {
22+
try {
23+
CustomRobotDriverElement.s = getLibraryInstance();
24+
} catch (ScriptException e) {
25+
throw new SeleniumLibraryNonFatalException("Cannot create SeleniumLibrary instance.", e);
26+
}
27+
Field bmField = SeleniumLibrary.class.getDeclaredField("bm");
28+
bmField.setAccessible(true);
29+
b = (BrowserManagement) bmField.get(s);
30+
bmField.setAccessible(false);
31+
}
32+
33+
private static SeleniumLibrary getLibraryInstance() throws ScriptException {
34+
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
35+
engine.put("library", "SeleniumLibrary");
36+
engine.eval("from robot.libraries.BuiltIn import BuiltIn");
37+
engine.eval("instance = BuiltIn().get_library_instance(library)");
38+
return (SeleniumLibrary) engine.get("instance");
39+
}
40+
41+
protected WebDriver getCurrentBrowser() {
42+
return b.getCurrentWebDriver();
43+
}
44+
45+
protected Robot getRobot() {
46+
return robot;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)