0
votes

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!

2
Please elaborate what exactly do you mean by "so thatmy test case runs in multiple browser". Do you want to run the test once with Chrome, and afterwards on Firefox, and so on? Or - and that's really pushing it a lot, and based on the github link in your question :) - you want your test to be simultaneously executed on Chrome, Firefox, Edge and whatnot? The later is a novel idea for sure, but requires fundamental changes in the library :). Or, you are going after a third thing I cannot deduct from your question?Todor Minakov
Thanks for your reply! Ideally, i would like to make 2nd option work. However I am thinking what would be optimal approach for first option - have test case run for multiple browsers in sequence?Abhilasha
The keyword Open Browser has as an argument the browser name; so in one run you will pass "Chrome", then in the following - change it to "Firefox", and so on.Todor Minakov
That's what i am doing and put that in a loop for each browser. I just wanted to make sure if there is any other optimal way of doing this. Like overriding browser management class and passing the list of browsers as a concatenated string via JRE arguments. This was i will not have to write loop of browsers in each of my testcase.Abhilasha
Looks like what you're doing is too complicated; an optimal way would be to have the test cases implementing what you are testing, and then - starting different runs with the different browser. This has the added benefit that all cases will be ran, with all browsers - in what you are describing, if the loop is on 3 browsers, and it fails for the first, the other 2 will not be ran, right? (that is, unless you have taken special precautions against it, e.g. extra overhead) Do you want me to scribe a sample of that "suite-run-per-browser" approach for you?Todor Minakov

2 Answers

2
votes

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.

1
votes

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