Overview

Robot Framework Tutorial 2016 – Selenium2Library as a drop-in replacement for SeleniumLibrary

No Comments

Robot Framework Tutorial 2016

Part 1: Installation
Part 2: Keywords
Part 3: Implementing Keywords in Java
Part 4: Selenium2Library as a drop-in replacement for SeleniumLibrary
Part 5: Integration with TeamCity CI-Server
Part 6: Integration with Jenkins
Part 7: File Processing

The “old” Robot Framework Tutorial.


A brief history of Selenium

Selenium is still one of the first tools to name when testing Web Applications. It is sticking around since 2004 and has gone through quite some improvements during that time. The biggest improvement for sure was the step from Selenium 1 (Selenium-RC) to Selenium 2 (Selenium Web-Driver). Now this is not really hot news as Selenium 2 is out for years already. But still lots of projects – and we are looking at those projects utilizing the Robot Framework – are for sure using Selenium-RC. This blog post is intended to help in switching to Selenium 2 and showing that this is probably often less effort than expected in return for a big gain in test stability. Not talking about the fact that support for the Selenium-RC library of the Robot Framework has stopped already some time ago.

Selenium-RC vs. Selenium 2 – Comparison

So of course new projects will always start using the Selenium2Library. But what about upgrading existing projects? The following table shows a comparison of the available keywords for both Selenium libraries. And believe me it was really some effort to create that table.

SeleniumRCSelenium2SeleniumRCSelenium2SeleniumRCSelenium2
Add CookieAdd Location StrategyAdd Location StrategyAlert Should Be PresentAlert Should Be Present
Assign Id To ElementAssign Id To ElementCall Selenium ApiAssign Id To Element
Capture Page ScreenshotCapture Page ScreenshotCapture ScreenshotCheckbox Should Be SelectedCheckbox Should Be Selected
Checkbox Should Not Be SelectedCheckbox Should Not Be SelectedChoose Cancel On Next ConfirmationChoose Cancel On Next ConfirmationChoose FileChoose File
Choose Ok On Next ConfirmationClear Element TextClick ButtonClick Button
Click ElementClick ElementClick Flex ElementClick Element At Coordinates
Click ImageClick ImageClick LinkClick LinkClose All BrowsersClose All Browsers
Close BrowserClose BrowserClose WindowClose WindowConfirm ActionConfirm Action
Create WebdriverCurrent Frame ContainsCurrent Frame ContainsCurrent Frame Should Contain
Current Frame Should Not ContainDelete All CookiesDelete All CookiesDelete CookieDelete Cookie
Dismiss AlertDouble Click ElementDouble Click ElementDouble Click Flex Element
Drag And DropDrag And DropDrag And Drop By OffsetElement Should Be DisabledElement Should Be Disabled
Element Should Be EnabledElement Should Be EnabledElement Should Be VisibleElement Should Be VisibleElement Should ContainElement Should Contain
Element Should Not Be VisibleElement Should Not Be VisibleElement Should Not ContainElement Text Should BeElement Text Should Be
Execute Async JavascriptExecute JavascriptExecute JavascriptFlex Element Property Should Be
Flex Element Should ExistFlex Element Should Not ExistFlex Element Text Should Be
FocusFocusFrame Should ContainFrame Should ContainFrame Should Contain Text
Get Alert MessageGet Alert MessageGet All LinksGet All LinksGet Cookie ValueGet Cookie Value
Get CookiesGet CookiesGet Element AttributeGet Element AttributeGet Horizontal PositionGet Horizontal Position
Get Inner HtmlGet List ItemsGet List ItemsGet LocationGet Location
Get Matching Xpath CountGet Matching Xpath CountGet Selected List LabelGet Selected List LabelGet Selected List LabelsGet Selected List Labels
Get Selected List ValueGet Selected List ValueGet Selected List ValuesGet Selected List ValuesGet Selenium Implicit Wait
Get Selenium SpeedGet Selenium SpeedGet Selenium Timeout
Get SourceGet SourceGet Table CellGet Table CellGet TextGet Text
Get TitleGet TitleGet ValueGet ValueGet Vertical PositionGet Vertical Position
Get WebelementGet WebelementsGet Window IdentifiersGet Window Identifiers
Get Window NamesGet Window NamesGet Window PositionGet Window Size
Get Window TitlesGet Window TitlesGo BackGo BackGo ToGo To
Highlight ElementInput PasswordInput PasswordInput TextInput Text
Input Text Into Flex ElementInput Text Into PromptList Selection Should BeList Selection Should Be
List Should Have No SelectionsList Should Have No SelectionsList WindowsLocation Should BeLocation Should Be
Location Should ContainLocation Should ContainLocator Should Match X TimesLog Location
Log SourceLog SourceLog TitleMaximize Browser WindowMaximize Browser Window
Mouse DownMouse DownMouse Down On ImageMouse Down On ImageMouse Down On LinkMouse Down On Link
Mouse OutMouse OutMouse OverMouse OverMouse UpMouse Up
Open BrowserOpen BrowserOpen Context MenuOpen Context MenuPage Should ContainPage Should Contain
Page Should Contain ButtonPage Should Contain ButtonPage Should Contain CheckboxPage Should Contain CheckboxPage Should Contain ElementPage Should Contain Element
Page Should Contain ImagePage Should Contain ImagePage Should Contain LinkPage Should Contain LinkPage Should Contain ListPage Should Contain List
Page Should Contain Radio ButtonPage Should Contain Radio ButtonPage Should Contain TextfieldPage Should Contain TextfieldPage Should Not ContainPage Should Not Contain
Page Should Not Contain ButtonPage Should Not Contain ButtonPage Should Not Contain CheckboxPage Should Not Contain CheckboxPage Should Not Contain ElementPage Should Not Contain Element
Page Should Not Contain ImagePage Should Not Contain ImagePage Should Not Contain LinkPage Should Not Contain LinkPage Should Not Contain ListPage Should Not Contain List
Page Should Not Contain Radio ButtonPage Should Not Contain Radio ButtonPage Should Not Contain TextfieldPage Should Not Contain TextfieldPress KeyPress Key
Press Key NativeRadio Button Should Be Set ToRadio Button Should Be Set ToRadio Button Should Not Be SelectedRadio Button Should Not Be Selected
Register Keyword To Run On FailureRegister Keyword To Run On FailureReload PageReload PageRemove Location Strategy
Select All From ListSelect All From ListSelect CheckboxSelect CheckboxSelect Flex Application
Select FrameSelect FrameSelect From Flex ElementSelect From ListSelect From List
Select From List By IndexSelect From List By LabelSelect From List By Value
Select Radio ButtonSelect Radio ButtonSelect WindowSelect WindowSet Browser Implicit Wait
Set Screenshot DirectorySet Selenium Implicit WaitSet Selenium SpeedSet Selenium Speed
Set Selenium TimeoutSet Selenium TimeoutSet Window PositionSet Window Size
SimulateSimulateStart Selenium ServerStop Selenium Server
Submit FormSubmit FormSwitch BrowserSwitch BrowserTable Cell Should ContainTable Cell Should Contain
Table Column Should ContainTable Column Should ContainTable Footer Should ContainTable Footer Should ContainTable Header Should ContainTable Header Should Contain
Table Row Should ContainTable Row Should ContainTable Should ContainTable Should ContainTextarea Should Contain
Textarea Value Should BeTextfield Should ContainTextfield Should ContainTextfield Value Should BeTextfield Value Should Be
Title Should BeTitle Should BeUnselect CheckboxUnselect CheckboxUnselect FrameUnselect Frame
Unselect From ListUnselect From ListUnselect From List By IndexUnselect From List By Label
Unselect From List By ValueWait For ConditionWait For ConditionWait For Flex Element
Wait Until Element ContainsWait Until Element Does Not ContainWait Until Element Is Enabled
Wait Until Element Is Not VisibleWait Until Element Is VisibleWait Until Page ContainsWait Until Page Contains
Wait Until Page Contains ElementWait Until Page Contains ElementWait Until Page LoadedWait Until Page Does Not Contain
Wait Until Page Does Not Contain ElementXpath Should Match X TimesXpath Should Match X Times

First thought was to do this with a screenshot, but it would have been rather hard to see the differences at a glance then. The keywords are taken from the final release (2.9.2) of the Selenium-RC keyword library and the release 1.7.4 of the Selenium 2 keyword library. Following keywords are “missing” from the Selenium 2 library in the comparison:

  • Call Selenium Api
  • Capture Screenshot
  • Click Flex Element
  • Current Frame Should Contain
  • Double Click Flex Element
  • Flex Element Property Should Be
  • Flex Element Should Exist
  • Flex Element Should Not Exist
  • Flex Element Text Should Be
  • Frame Should Contain Text
  • Get Inner Html
  • Highlight Element
  • Input Text Into Flex Element
  • Press Key Native
  • Select Flex Application
  • Select From Flex Element
  • Start Selenium Server
  • Stop Selenium Server
  • Wait Until Page Loaded

Analysis of the Differences

Back to the title of this blog post that is stating something like “drop-in replacement”. But the list of “missing” keywords seems to be rather long. Let’s have a closer look.

This page explains how to use SeleniumLibrary to run tests against Adobe Flex applications. Although it has not been explicitly tested, it should be possible to test also Flash applications the same way. (https://github.com/robotframework/SeleniumLibrary/wiki/FlexTesting)

The missing “Flex-Keywords” are probably only relevant for a minority of projects (no offense intended :-)). Obviously starting and stopping the Selenium Server is no longer required, because, well, there is no Selenium Server anymore. “Highlight Element” (Highlights element found with locator briefly. This is mainly useful for debugging purposes.) does not have any real purpose unless this kind of debugging is happening on a daily basis ;-). “Get Inner HTML” can be easily worked around and “Capture Screenshot” can be replaced by “Capture Page Screenshot”.

“Current Frame Should Contain” and “Frame Should Contain Text” can be replaced using the “Select Frame” and “Current Frame Contains” keywords. The solution to work around the missing keyword “Wait Until Page Loaded” is probably the fact that many of the keywords that cause a page load take an optional argument “dont_wait” that can be also used to wait/not wait for the page load.

This is leaving us with very few potential hard cases, well, at least harder than the previous ones:

  • Call Selenium Api and
  • Press Key Native.

“Call Selenium Api” might have been used to call Selenium functionality that has not been exposed as a keyword. As there are additional keywords available in the Selenium 2 library there is a chance the needed keywords are available already. Otherwise a change in the implementation of the test will be required. The “Press Key Native” has been called last resort in one of my previous blog posts. Well, today I think if this is required then there is really something wrong in the system under test. Again it should have been only used in very rare cases and thus in a very small amount of projects.

The next Move

Hopefully the list and analysis in this blog post makes it easier to predict the effort needed to switch from Selenium-RC to Selenium 2. Just in case here comes a brief list of the main advantages of Selenium 2:

  • The used Webdriver API is supporting real browsers, no need anymore for running a Selenium Server.
  • Possibility to execute tests in headless mode.
  • Better support to test applications using AJAX.

Now making the move from Selenium-RC to Selenium 2 might be a good candidate to be analysed using time-boxing. Depending on the size and complexity of the project one to two days should be enough for this. In a best case scenario after this time the switch is already finished to a good degree. In worst case one has at least a concrete idea on the effort needed to finally move from Selenium-RC to Selenium 2 and if that makes sense at all.

Of course the change can – and should – be made in a rather noninvasive way. Once it has been verified that the affected tests are still running fine the switch can be made final. This means:

  • In case of a smaller project just duplicate the whole testsuite and make the changes in the copy. Keep both testsuites running in parallel for a certain amount of time.
  • In bigger problems the same approach is possible, but just starting with a rather isolated part, e.g. one testsuite from the overall amount of testsuites.
  • In product development there might be often libraries wrapping the Selenium (and other) libraries already. Again a copy can be created and some testsuites can be changed to use that copy. The testsuites can run in parallel to prove it is working with the changed library.

A similar approach should be possible in most projects/products.

Conclusion

Well, it is worth a try :-).

Comment

Your email address will not be published. Required fields are marked *