Abhilasha
Abhilasha

Reputation: 1

Robot Framework - Cross browser testing

I am new to automation and i want to do cross browser testing in robot framework. What method i can add in browser management file so that my test case runs in multiple browser https://github.com/MarkusBernhardt/robotframework-selenium2library-java/blob/master/src/main/java/com/github/markusbernhardt/selenium2library/keywords/BrowserManagement.java

Thanks, your help is really appreciated!

Upvotes: 0

Views: 5430

Answers (2)

Bohdan Pylypenko
Bohdan Pylypenko

Reputation: 1234

There is pabot. A parallel executor for Robot Framework tests.

And it has the option:

--argumentfile[INTEGER] [FILEPATH] Run same suites with multiple argumentfile options. For example:

--argumentfile1 arg1.txt --argumentfile2 arg2.txt

For example, the content of the argument file (firefox.txt) for Mozilla Firefox tests:

--name      Mozilla Firefox Suites
--variable  BROWSER:firefox

And Shell command:

   pabot --argumentfile1 ${ROBOT_CONFIG}/chrome.txt \
         --argumentfile2 ${ROBOT_CONFIG}/firefox.txt \
         --verbose

The answers of others for the related question:

How can we run test cases on different browser at once in robotframework using Ride

Upvotes: 1

Todor Minakov
Todor Minakov

Reputation: 20057

The SeleniumLibrary doesn't have the capability to run the same command against multiple browsers. The feature does sound quite cool, but will require quite some modifications in it (all revolving around relaying the same command to all browsers), and taking care of any unforeseen circumstances in its current architecture (what should happen if one of the selenium drivers loses connectivity, but the others are working ok? etc).

The usual approach for multi-browser testing is to run the collection of cases, one by one, against each browser. Thus a full coverage matrix will be produced - the run on one browser doesn't affect the run on another.

A very basic sample how to do it - code with inline comments:

*** Settings ***
Documentation     A suite of cases.

Library             SeleniumLibrary

# the browser will be opened in the start-up of the suite
Suite Setup         Open Browser    url=https://www.google.com      browser=${browser}    # which browser? the one that's the value of the variable
Suite Teardown      Close Browser   # and closed when the suite finishes

*** Variables ***
# the variable will hold the name of the target browser
${browser}      Chrome          # a default value, if not overriden

*** Test Cases ***
Test this
    [Documentation]     Do this then that and verify the thing.
    Go To      https://www.yahoo.com
    My Keyword 1
    My Keyword 2

Verify That
    [Documentation]     Another case
    My Keyword Doing Thing       with argument
    Log     log message

So - the actual browser to use is the value of the ${browser} variable. If it's not overridden, it has a default value (Chrome in that case).

And now, to run with a different browser you just set it its name, on the CLI for starting a run; sample:

robot --variable browser:Firefox suites\sample.robot

The argument --variable is used to set the value of one; it is given in the format var_name:value. This btw is described in details in the user guide, the Variables section.

Thus you can start one run with Chrome, another with Firefox, and so on.

A small tip - by default, the run logs are in files with the names "output.xml", "log.html" and "report.html". If you start 3 runs with 3 different browsers, and don't bother copying the files, they will be overwritten. It's better to define a custom name for each, for easier processing. This is done with these 3 arguments - --output, --log and --report; for example:

robot --variable browser:Edge --output output-edge.xml --log log-edge.html --report report-edge.html suites\sample.robot

P.S. I do realize you're using RF in jython, but I don't have this environment, thus vanilla standalone RF - you can adjust the CLI examples and the library import with the help of the user guide.

Upvotes: 2

Related Questions