BrowserStack and RobotFramework Integration

In this post, we will integrate RobotFramework with BrowserStack and we will run our test in BrowserStack’s cloud grid system. Last week, I described how to install and use RobotFramework in this post. If you don’t have any experience or if you don’t know how to use RobotFramework, please check that post first.

Please, see the latest update for RobotFramework and Selenium 3.0 Integration in this article

I want to go with the same Linkedin Login test example. Our test scenario is shown below:

  • Open LinkedIn page
  • Check Title
  • Enter User Name
  • Enter the Wrong Password
  • Click Login
  • Wait 5 seconds
  • Assert Warning Message
  • Close Browser

This time, I want to use two files for a better test structure. These are setup.robot and BrowserStackLoginTest.robot

We will have two folders one of them is Resource and the other is Tests folder. Resource folder comprises of setup.robot and Tests folder contains BrowserStackLoginTest.robot file.

robot_browserstack3

setup.robot file holds Settings, Variables, Keywords information, and BrowserStackLoginTest.robot contains test codes.

setup.robot

In order to connect BrowserStack, we should register it and have an account. By using our account’s AccessKey and username information, we can connect BrowserStack. Also, we should use desired capabilities to declare which operating system, browser, browser version, OS version, etc. we will use. In below code, I did all these settings.

*** Settings ***
Library           Selenium2Library
 
*** Variables ***
${Username}       [email protected]
${Password}       wrongpass
${SiteUrl}        http://www.linkedin.com
${DashboardTitle}    World's Largest Professional Network | LinkedIn
${ExpectedWarningMessage}    Hmm, we don't recognize that email. Please try again.
${WarningMessage}    Login Failed!
${Delay}          5s
${BSUser}   YOUR-USER
${AccessKey}   YOUR-ACCESS-KEY
${RemoteUrl}   http://${BSUser}:${AccessKey}@hub.browserstack.com/wd/hub
 
 
*** Keywords ***
Open LinkedinPage
    [Arguments]   ${BROWSER}  ${BROWSER_VERSION}  ${OS}  ${OS_VERSION}
    Open Browser   url=${SiteUrl}   browser=${BROWSER}   remote_url=${RemoteURL}   desired_capabilities=browser:${BROWSER},browser_version:${BROWSER_VERSION},os:${OS},os_version:${OS_VERSION}
 
Maximize Browser
    Maximize Browser Window
 
Enter User Name
    Input Text   id=login-email    ${Username}
 
Enter Wrong Password
    Input Text   id=login-password    ${Password}
 
Click Login
    Click Button   css=[name=submit]
 
#Check Title
#Title Should Be   ${DashboardTitle}  #There is an encoding problem in this function.
 
Assert Warning Message
    Element Text Should Be   id=session_key-login-error   ${ExpectedWarningMessage}   ${WarningMessage}

When I tried to run the same test on BrowserStack I got an encoding error on the “Title Should Be” method. I tried to fix that encoding problem but I was not successful. I also asked about this issue on StackOverflow (Link: http://stackoverflow.com/questions/36936352/how-to-match-browserstack-and-robotframework-encoding). If you know the solution, please write a comment.

Error Screen is shown below. :(

TitleShouldBe_EncodingError

Now, let’s write our test robot file.

BrowserStackLoginTest.robot

*** Settings ***
Resource  ../Resource/setup.robot
Suite Teardown    Close Browser
Force Tags  	  BrowserStack

*** Test Cases ***
Login Should Failed With Unregistered Mail Adress
    Open LinkedinPage  BROWSER=Chrome  BROWSER_VERSION=47.0  OS=Windows  OS_VERSION=7  
    #Check Title
    Enter User Name
    Enter Wrong Password
    Click Login
    sleep    ${Delay}
    Assert Warning Message
    [Teardown]    Close Browser

Execution & Results

Open a command prompt and go to your test folder and then type the below command.

robot BrowserStackLoginTest.robot

Then, you will see below execution at the command prompt.

browserstack

and you will see test execution on BrowserStack’s Dashboard.

robotframework

browserstack_ressults

Thanks.
-Onur

22 thoughts on “BrowserStack and RobotFramework Integration”

  1. Hey. How do you get the http://[email protected]:pass@address working? For me it cuts already the address from the first @ -mark and tries to remote connect to pass@address as the remote url. I have tried escaping it with \ or putting %40 in place of @ for the email username. It does no have affect if I have the username and password in variables or write it straight to the the address.

    Reply
  2. It works fine for the public server, I need ti run the same think for a local server in the remote browser. I have this issue : Could not get IP address for host: hub.browserstack.com

    Please Help !

    Reply
  3. Hi This was very helpful.. I’m trying to run the script through my local. The elements are not getting recognized. And it fails.
    Second question i have enough parallel run but im getting the error “WebDriverException: Message: All parallel tests are currently in use, including the queued tests. Please wait to finish or upgrade your plan to add more sessions.”

    Reply
    • Hi Josey, It was a very basic test scenario to help us to go further. Probably elements’ ids changed. I will try to update the article in the future. But I guess that the concept will be the same. For parallel runs, I did not try parallel execution with RF. It is better to check StackOverflow for these kinds of problems.

      Reply
  4. Hi,
    I’ve tried to use some robot command in browser stack, to upload a file. Below commands were used. They are working fine in my local machine i.e. without using browser stack, but in browser stack the below mentioned commands are not working. Not getting any error as well.
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.setAutoDelay(2000);
    robot.keyPress(KeyEvent.VK_V);

    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_V);

    Any suggestion why these are not working.?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.