Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with Robot Framework 2.9 -series with updated dependencies #74

Merged
merged 15 commits into from Oct 27, 2015
15 changes: 10 additions & 5 deletions pom.xml
Expand Up @@ -23,7 +23,7 @@
<aspectj.version>1.7.3</aspectj.version>
<java.version>1.6</java.version>
<xml.doclet.version>1.0.4</xml.doclet.version>
<robotframework.version>2.8.3</robotframework.version>
<robotframework.version>2.9.2</robotframework.version>
<keywords.class>Selenium2Library</keywords.class>
</properties>

Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>org.robotframework</groupId>
<artifactId>javalib-core</artifactId>
<version>1.2</version>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.github.markusbernhardt</groupId>
Expand All @@ -62,7 +62,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.43.1</version>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>com.opera</groupId>
Expand Down Expand Up @@ -92,7 +92,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.43.1</version>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>io.selendroid</groupId>
Expand All @@ -104,6 +104,11 @@
<artifactId>java-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -157,7 +162,7 @@
<!-- Integration-Test, build documentation -->
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.2</version>
<version>1.4.5</version>
<executions>
<execution>
<id>test</id>
Expand Down
Expand Up @@ -360,13 +360,13 @@ public Selenium2Library(String timeout, String implicitWait) {
* Default=Capture Page Screenshot. Optional custom keyword to
* run on failure.
*/
public Selenium2Library(String timeout, String implicitWait, String runOnFailure) {
public Selenium2Library(String timeout, String implicitWait, String keywordToRunOnFailure) {
super();
addKeywordPattern(KEYWORD_PATTERN);
createKeywordFactory(); // => init annotations
browserManagement.setSeleniumTimeout(timeout);
browserManagement.setSeleniumImplicitWait(implicitWait);
this.runOnFailure.registerKeywordToRunOnFailure(runOnFailure);
runOnFailure.registerKeywordToRunOnFailure(keywordToRunOnFailure);
}

// ##############################
Expand Down
Expand Up @@ -365,12 +365,13 @@ protected void log0(String msg, String methodName, String methodArguments) {
}

protected File getLogDir() {
if (logDir == null) {
PyString logDirName = (PyString) loggingPythonInterpreter.get().eval("GLOBAL_VARIABLES['${LOG FILE}']");

if (logDir == null && !loggingPythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) {
PyString logDirName = (PyString) loggingPythonInterpreter.get().eval("BuiltIn().get_variables()['${LOG FILE}']");
if (logDirName != null && !(logDirName.asString().toUpperCase().equals("NONE"))) {
return new File(logDirName.asString()).getParentFile();
}
logDirName = (PyString) loggingPythonInterpreter.get().eval("GLOBAL_VARIABLES['${OUTPUTDIR}']");
logDirName = (PyString) loggingPythonInterpreter.get().eval("BuiltIn().get_variables()['${OUTPUTDIR}']");
return new File(logDirName.asString()).getParentFile();
} else {
return new File(logDir);
Expand All @@ -386,7 +387,7 @@ public static void setLogDir(String logDirectory) {
@Override
protected PythonInterpreter initialValue() {
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec("from robot.variables import GLOBAL_VARIABLES; from robot.api import logger;");
pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; from robot.api import logger;");
return pythonInterpreter;
}
};
Expand Down
Expand Up @@ -99,7 +99,7 @@ public String registerKeywordToRunOnFailure(String keyword) {
@Override
protected PythonInterpreter initialValue() {
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec("from robot.libraries import BuiltIn; BUILTIN = BuiltIn.BuiltIn();");
pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; BIN = BuiltIn();");
return pythonInterpreter;
}
};
Expand All @@ -111,10 +111,13 @@ public void runOnFailure() {
if (runningOnFailureRoutine) {
return;
}
runningOnFailureRoutine = true;
if(runOnFailurePythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) {
return;
}

try {
runOnFailurePythonInterpreter.get().exec(
String.format("BUILTIN.run_keyword('%s')",
String.format("BIN.run_keyword('%s')",
runOnFailureKeyword.replace("'", "\\'").replace("\n", "\\n")));
} catch (RuntimeException r) {
logging.warn(String.format("Keyword '%s' could not be run on failure%s", runOnFailureKeyword,
Expand Down
Expand Up @@ -261,7 +261,7 @@ public static List<WebElement> find(WebDriver webDriver, String locator, String
@Override
protected PythonInterpreter initialValue() {
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec("from robot.variables import GLOBAL_VARIABLES; from robot.api import logger;");
pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.api import logger;");
return pythonInterpreter;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/robotframework/objects/Google.Search.txt
Expand Up @@ -4,7 +4,7 @@ Documentation Defines all required resources and keywords
Resource ../adapters/Selenium2Library.txt

*** Variables ***
${Google.Search.Locator.SearchField} id=gbqfq
${Google.Search.Locator.SearchField} id=lst-ib
${Google.Search.Locator.SearchResult.Rtomac} xpath=//a[contains(.,'MarkusBernhardt')]

*** Keywords ***
Expand Down
23 changes: 9 additions & 14 deletions src/test/robotframework/testsuites/UnitTests/Google.txt
Expand Up @@ -10,34 +10,29 @@ Open And Close Google Site
Capture Page Screenshot

Store Web Element In JavaScript
Execute Javascript window.document.my_element = window.document.getElementsByClassName('gbqfba')[0];
Execute Javascript window.document.my_element = window.document.getElementsByClassName('gsfi')[0];
${className}= Execute Javascript return window.document.my_element.className;
Should Be Equal ${className} gbqfba
Should Contain ${className} gsfi

Search Robotframework Selenium2Library
Google.Search.Search String Robotframework Selenium2Library Java

Search With JavaScript Locator
Selenium2Library.Add Location Strategy elementById return window.document.getElementById(arguments[0]);
Input Text elementById=gbqfq Robotframework Selenium2Library Java
Press Key elementById=gbqfq \\13
Input Text elementById=lst-ib Robotframework Selenium2Library Java
Press Key elementById=lst-ib \\13
Wait Until Element Is Visible xpath=//a[contains(.,'MarkusBernhardt')]
Capture Page Screenshot

Search With JavaScript Locator And Delimiter
Selenium2Library.Add Location Strategy elementByClassname return window.document.getElementsByClassName(arguments[0])[arguments[1]]; ,
Element Text Should Be elementByClassname=gbqfba,0 Google-Suche
Element Text Should Be elementByClassname=gbqfba,1 Auf gut Glück!


Search With JavaScript Locator Text
Selenium2Library.Add Location Strategy text return window.document.evaluate("//*[contains(text(),'" + arguments[0] + "')]", window.document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
Selenium2Library.Add Location Strategy text return window.document.evaluate("//*[contains(@value,'" + arguments[0] + "')]", window.document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
Wait Until Element Is Visible text=Google-Suche

Search Without Locator Type
Input Text gbqfq Robotframework Selenium2Library Java
Press Key gbqfq \\13
Input Text lst-ib Robotframework Selenium2Library Java
Press Key lst-ib \\13
Wait Until Element Is Visible //a[contains(.,'MarkusBernhardt')]

Get Id Of Active Element With JavaScript
Input Text gbqfq Robotframework Selenium2Library
Input Text lst-ib Robotframework Selenium2Library
${activeElementId}= Execute JavaScript return window.document.activeElement.id;