This repository was archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
added RobotString class for working with system properties and string… #74
Merged
Hi-Fi
merged 6 commits into
MarketSquare:develop
from
YauheniPo:feature/custom_robot_driver_element
Jul 9, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7c69cc
added RobotString class for working with system properties and string…
YauheniPo 562d59f
Added SeleniumLibraryNonFatalException to catch block in the CustomRo…
YauheniPo 47c60db
Corrected by review comments - updated constructor issues of CustomRo…
YauheniPo 6b3b3ec
Corrected by review comments - updated constructor issues of CustomRo…
YauheniPo 68e00e1
remover 'static' of getCurrentBrowser method
YauheniPo 5cc545d
Removed RobotString class
YauheniPo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/github/markusbernhardt/seleniumlibrary/CustomRobotDriverElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.markusbernhardt.seleniumlibrary; | ||
|
||
import com.github.markusbernhardt.seleniumlibrary.keywords.BrowserManagement; | ||
import com.github.markusbernhardt.seleniumlibrary.keywords.Robot; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptEngineManager; | ||
import javax.script.ScriptException; | ||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* For extends of custom keywords of WebDriver actions | ||
*/ | ||
public class CustomRobotDriverElement { | ||
|
||
private static SeleniumLibrary s; | ||
private static BrowserManagement b; | ||
private Robot robot = new Robot(); | ||
|
||
public CustomRobotDriverElement() throws NoSuchFieldException, IllegalAccessException { | ||
try { | ||
CustomRobotDriverElement.s = getLibraryInstance(); | ||
} catch (ScriptException e) { | ||
throw new SeleniumLibraryNonFatalException("Cannot create SeleniumLibrary instance.", e); | ||
} | ||
Field bmField = SeleniumLibrary.class.getDeclaredField("bm"); | ||
bmField.setAccessible(true); | ||
b = (BrowserManagement) bmField.get(s); | ||
bmField.setAccessible(false); | ||
} | ||
|
||
private static SeleniumLibrary getLibraryInstance() throws ScriptException { | ||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python"); | ||
engine.put("library", "SeleniumLibrary"); | ||
engine.eval("from robot.libraries.BuiltIn import BuiltIn"); | ||
engine.eval("instance = BuiltIn().get_library_instance(library)"); | ||
return (SeleniumLibrary) engine.get("instance"); | ||
} | ||
|
||
protected WebDriver getCurrentBrowser() { | ||
return b.getCurrentWebDriver(); | ||
} | ||
|
||
protected Robot getRobot() { | ||
return robot; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the visibility back to the previous state after getting what we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done