How to use Webdriver manager in Robot Framework?

Viewed 8936

In selenium I used webdriver manager through a command:

driver = webdriver.Chrome(Chromedrivermanager().install())

Is there a webdriver manager use for the robot framework? I would like the webdriver manager to download automatically when running the test script without additional interference.

4 Answers

My solution for using this with Robot Framework was with a python library that I called chromedriversync.

chromedriversync.py:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

def get_chromedriver_path():
    driver_path = ChromeDriverManager().install()
    print(driver_path)
    return  driver_path

Then, in my robotframework tests, I add

Library  chromedriversync.py

${chromedriver_path}=   chromedriversync.Get Chromedriver Path
Create Webdriver    chrome   executable_path=${chromedriver_path}
Go to  www.google.com

I just use the chromedrivermanager install method's returned path variable, to supply to the Open Browser Robot Framework keyword.

The only thing that i found in internet is that Youn need to install webdrivermanager with command :

pip install webdrivermanager 

and you launch this command before your script:

webdrivermanager chrome 
robot --outputdir ./results/Robot-results ./TestSuits/*

NB: your browser (Chrome) has to be updated too : (Ubuntu)

sudo apt-get update
sudo apt-get install google-chrome-stable

There are two web driver managers as shown below,

  1. If you use this one, you need to do one additional step on the command line, you cannot proceed with the test code unless you execute the below command, as this is part of the webdrivermanager setup. webdrivermanager - webdrivermanager 0.7.4

command-line step -

webdrivermanager chrome:2.38 firefox opera:v.2.35
  1. webdriver-manager 2.3.0

You need to do the following to use webdriver-manager, did you notice something, there is nothing which needs to be done anything specific to webdriver-manager, BEAUTY of making use of robotframework. nice!!!

code

1. pip install webdriver-manager robotframework robotframework-seleniumlibrary
(prjenv) 09:37 PM##~::>pip list
Package                        Version
------------------------------ ----------
certifi                        2018.11.29
chardet                        3.0.4
colorama                       0.4.1
configparser                   4.0.2
crayons                        0.3.0
idna                           2.8
pip                            19.2.3
requests                       2.22.0
robotframework                 3.1.2
robotframework-seleniumlibrary 4.1.0
selenium                       3.141.0
setuptools                     40.8.0
urllib3                        1.25.6
webdriver-manager              2.2.0
wheel                          0.32.3
2. create a file sample.robot
***Settings***
Library         SeleniumLibrary

***Test Cases***
Sample Webdriver
        [Tags]  wd0
        [Documentation] Sample invocation using WD
        Open Browser    http://google.com       ff
        Close All Browsers
3. execute the file as follows
robot *.robot

Output
========

(prjenv) 09:38 PM##~::>robot *.robot
==============================================================================
Sam
==============================================================================
Sample Webdriver :: Sample invocation using WD                        | PASS |
------------------------------------------------------------------------------
Sam                                                                   | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  /Users/apachemain/output.xml
Log:     /Users/apachemain/log.html
Report:  /Users/apachemain/report.html

THAT'S IT!!!

Related