How to get browser version using Robot Framework libraries

2,490 views
Skip to first unread message

Mike Nar

unread,
Dec 31, 2013, 12:56:42 PM12/31/13
to robotframe...@googlegroups.com
I have to run my test suite in different browser versions. The locators used to find elements do not work the same way for all the browser versions. Hence have decided to bifurcate the locators used to find any element based on the browser version at run time. Is there any way to get the browser version in Robot? So that i can store that in a variable and condition the locators accordingly.

Mukesh T

unread,
Jan 1, 2014, 6:10:31 AM1/1/14
to robotframe...@googlegroups.com
hello,

i'm not sure if there is any built-in keyword to get the browser details.

however, we can extract the required info from user-agent header string. In case of Firefox, the user-agent header will be something like:
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0

here, in above string, the browser name/version are contained as "Firefox/25.0". so, we can do something like the below to achieve the goal:

*** Testcases ***
Check Browser
${version}= Get Browser Version Firefox

*** Keywords ***
Get Browser Version
[Arguments] ${bname}
${agentHeader}=    Execute Javascript    return navigator.userAgent;
LOG USER AGENT HEADER=${agentHeader}
${browserVer}= Fetch From Right ${agentHeader} ${bname}/
LOG BROWSER VERSION=${browserVer}
[Return] ${browserVer}

hope this is helpful.

best,
Mukesh

Kevin O.

unread,
Jan 2, 2014, 12:19:47 PM1/2/14
to robotframe...@googlegroups.com
If you are using the Java version of Selenium2Library, there is a keyword you can use.
${caps}=    Get Remote Capabilities
${version}=    Set Variable    ${caps['version']}

To do this with the Python Selenium2Library, you have to call a private method since there is no Get Remote Capabilities keyword:
    ${s2l}=    Get Library Instance    Selenium2Library
    ${caps}=    Set Variable    ${s2l._current_browser().capabilities}
    ${version}=    Set Variable    ${caps['version']}

The browser name is stored in an entry in the capabilities dict with this key: browserName
Use Collections.Log Dictionary to have a nice view of the capabilities dict in your log.

Mukesh T

unread,
Jan 2, 2014, 12:48:07 PM1/2/14
to robotframe...@googlegroups.com
hello Kevin:

that's really a much cleaner approach !

how could I explore/learn more about such private methods of selenium2library (py version) ?

pl let me know some references.

best,
Mukesh

Kevin O.

unread,
Jan 2, 2014, 7:32:16 PM1/2/14
to robotframe...@googlegroups.com
It is open source, so you can look at the code.
There is not anything I could recommend other than _current_browser, since the methods could change in a future version.
_element_find is useful.
For what to do with the _current_browser() (webdriver instance), look at http://selenium.googlecode.com/git/docs/api/py/api.html, particularly selenium.webdriver.remote.webdriver
I would not do anything like my example unless you have to.
If important features are missing from Selenium2Library, then raise an issue on the tracker.
Reply all
Reply to author
Forward
0 new messages