Skip to content

Andrei-Straut/robotframework-selenium2library-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java port of the Selenium 2 (WebDriver) Python library for Robot Framework

Introduction

This Java port of the existing Selenium2Library was created to enable the usage of a Selenium 2 library with Jython.

  • Python Selenium2Library needs Python 2.6 upwards
  • The latests stable release of Jython is 2.5.3
  • Jython 2.7b2 is a beta version
  • There seems to be only slow development of a stable Jython 2.7

Usage

This library is a direct replacement to the Python Selenium2Library. There are almost no changes necesssary to the existing code. You can execute the same testcases and keywords with Python and Jython.

If you are using the robotframework-maven-plugin you can use this library by adding the following dependency to your pom.xml:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.2.0.12</version>
    <scope>test</scope>
</dependency>

If you cannot use the robotframework-maven-plugin you can use the jar-with-dependencies, which contains all required libraries.

If you want more control and feel adventurous you could you use this jar and provide all required libraries from this list on your own.

Differences

  • Robotframework does not support providing arguments to Java libraries

    With Python it is possible to provide arguments to libraries

      *** Settings ***
      Library    Selenium2Library    15    30    run_on_failure=Log Source
    

    This is not possible with a Java Library. But it can be done in a way that works with Java and Python

      *** Settings ***
      Library    Selenium2Library
      
      *** Keywords ***
      Open
          Open Browser    <url>    <browser>
          Set Selenium Timeout    15
          Set Selenium Implicit Wait    30
          Register Keyword To Run On Failure    Log Source
    
  • Robotframework does not support named arguments with Java libraries

    It is not possible to use named arguments. See User Guide 2.2.2

  • Selenium Speed not implemented

    Setting the Selenium Speed is deprecated several years and not implemented in WebDriver. The Python Selenium2Library tries to emulate the old behavior. I have not implemented this emulation for the following reasons.

    • As far as I understand the emulation is broken and only works with RemoteWebDriver
    • I do not know how to implement that in a correct way with Java
    • There is a reason, why this is not implemented in WebDriver. It's a bad idea.

Enhancements

More browser supported
  • ipad
  • safari
Custom JavaScript Locators
We added the keyword Add Location Strategy. This keyword is somewhat analogous to the SeleniumLibrary (RC) keyword. It can be used to register a JavaScript function as locator with the specified strategy name. The registered function has to return a WebElement, a List of WebElements or null. This feature was requested in issue #1.

Since 1.2.0.1 an optional delimiter can be specified. See #3 for more info.

KeywordArguments
Add Location Strategystrategy_name, function_definition, delimiter=NONE

A small example:

    Selenium2Library.Add Location Strategy    elementById    return window.document.getElementById(arguments[0]);
    Input Text    elementById=firstName    Max

A small example with delimiter:

    Selenium2Library.Add Location Strategy    elementByClassname    return window.document.getElementsByClassName(arguments[0])[arguments[1]];    ,
    Input Text    elementByClassname=inputField,0    Max
    Input Text    elementByClassname=inputField,1    Mustermann
Proxy Handling
We added proper proxy handling for RemoteWebDriver instances. This is needed, if you want to connect to an external Selenium grid through a local HTTP proxy. Our implementation handles BASIC, DIGEST and NTLM based authentication schemes correctly. We added the following keyword.
KeywordArguments
Set Remote Web Driver Proxyhost,port,user=NONE,password=NONE,domain=NONE,workstation=NONE
Some additional info:
  • If you set a proxy, it will be used for all subsequent calls of Open Browser
  • You can remove the proxy by calling: Set Remote Web Driver Proxy ${EMPTY} ${EMPTY}
  • If you provide no username, we are looking for a username at the Java property http.proxyUser and the environment variables HTTP_PROXY and http_proxy. If we find a username, it is only used, if the host and port also match.
  • If you provide no password, we are looking for a password at the Java property http.proxyUser and the environment variables HTTP_PROXY and http_proxy. If we find a password, it is only used, if the host, port and username also match.
  • If you provide a domain, we use NTLM based authentication
  • If you provide no workstation and we use NTLM based authentication, we use the hostname as workstation name
Waiting
Our application is heavily using AJAX. So much more waiting keywords are needed. The list of new keywords:
KeywordArguments
Element Should Be Clickablelocator,message=NONE
Element Should Not Be Clickablelocator,message=NONE
Element Should Be Selectedlocator,message=NONE
Element Should Not Be Selectedlocator,message=NONE
Element Should Not Containlocator,expected,message=NONE
Element Should Text Should Not Belocator,expected,message=NONE
Wait Until Element Is Clickablelocator,timeout=NONE,message=NONE
Wait Until Element Is Successfully Clickedlocator,timeout=NONE,message=NONE
Wait Until Element Is Not Clickablelocator,timeout=NONE,message=NONE
Wait Until Element Is Selectedlocator,timeout=NONE,message=NONE
Wait Until Element Is Not Selectedlocator,timeout=NONE,message=NONE
Wait Until Element Is Not Visiblelocator,timeout=NONE,message=NONE
Wait Until Page Not Containscondition,timeout=NONE,message=NONE
Wait Until Page Not Contains Elementlocator,timeout=NONE,message=NONE
Wait Until Title Istitle,timeout=NONE,message=NONE
Wait Until Title Is Nottitle,timeout=NONE,message=NONE
Wait Until Title Containstitle,timeout=NONE,message=NONE
Wait Until Title Not Containstitle,timeout=NONE,message=NONE
XPath Count
We extended the following keywords to be called with a xpath statement that optionally can start with "xpath=".
KeywordArguments
Get Matching Xpath Countxpath
Xpath Should Match X Timesxpath, expected_xpath_count, message=NONE, loglevel=INFO
Remote Session Id
We introduced two keywords to get the session id from the RemoteWebDriver. This is mainly needed to identify the test session at external grids like SauceLabs.
KeywordArguments
Get Remote Session Id
Log Remote Session Id
Remote Capabilities
According to the Javadoc no error is thrown, if a session cannot support a capability that is requested in the desired capabilities. Therefore it can happen that you are silently running your tests on the wrong environment. With the following two keywords you can control what capabilities the actual session supports.
KeywordArguments
Get Remote Capabilities
Log Remote Capabilities
System Info
The following two keywords are outputting the current system info as in the WebDriverException.
KeywordArguments
Get System Info
Log System Info

Demo

This is a maven project. If you have firefox installed, you can execute the unit tests with:

mvn integration-test

About

Java port of the Selenium 2 (WebDriver) Python library for Robot Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%