Is there a way to get the list of test suites which robotframework executes

1,526 views
Skip to first unread message

Rohit Misra

unread,
Jan 28, 2016, 8:22:21 PM1/28/16
to robotframework-devel
Is it possible to get the list of all Suites files or cout of suite files which Robot framework is supposed to run at the start of execution.
Considering the scenario where multiple Suite file name are provided as command line argument to Pybot or Directory Name ( consisting of multiple suite files )  is provided as command line argument to Pybot utility.

I want to make a decision in Suite setup based on the number of suite files which Robotframework will run when multiple suite file or directory name is provided as a command line argument to Pybot.

Krishna Chowdary

unread,
Jan 29, 2016, 10:47:52 AM1/29/16
to robotframework-devel
Hi Rohit,

you can get it using in windows

${file count} = | Execute Command | dir *.txt /b /a-d | find /c /v ""

If it is in Linux you can use this
${file count} = | Execute Command | ls -1 *.txt \| wc -l

and be sure that there are no other files in the directory and you can change the extension accordingly.

Taylor, Martin

unread,
Jan 29, 2016, 11:26:08 AM1/29/16
to pemmasa...@gmail.com, robotframework-devel

I don’t think this suggested solution really addresses the question. The commands below would simply give a listing of what RF suite files exist. The question said “suite files which Robot framework is supposed to run” (emphasis mine). In other words, when pybot starts it is given a list of suite files and/or folders, plus other selection criteria by tags. The end result is some set of tests from some set of suites that is unknowable except by asking pybot. I’ve always wanted to know the total number of tests to be executed by pybot in a given run, but haven’t been able to figure out how to know this. It would be really nice if there was a variable you could reference, or a listener call to subscribe to, to get the number of suites and tests to be executed in a pybot run.

 

Thanks,

Martin

--
You received this message because you are subscribed to the Google Groups "robotframework-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-d...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-devel.
For more options, visit https://groups.google.com/d/optout.

Krishna Chowdary

unread,
Jan 29, 2016, 11:31:38 AM1/29/16
to Taylor, Martin, robotframework-devel
ya, and in the bottom of the command I have mentioned that make sure that no other files exist in the directory.

Bryan Oakley

unread,
Jan 29, 2016, 12:26:23 PM1/29/16
to Martin Taylor, pemmasa...@gmail.com, robotframework-devel
Yes, it would be nice if robot built up some sort of execution plan and exposed that to a running test or to a listener. This toopic came up last week over slack when Pekka hosted a conversation about skipping test cases. 

This seemed like an interesting challenge, so I did some experimentation. With a little out-of-the-box thinking, I think I have a solution. 

You can build up a list of the suites using the new --prerunmodifier option (which is called after all of the --include and --exclude options have been processed).  The problem is, there's no obvious way to get that information to a running test case. The solution is to use a single module that serves double duty, both as the target of --prerunmodifier, and as a keyword library. 

As a prerunmodifier, the module will be imported, and the class instantiated, after robot parses the command line arguments but before the first test is executed. It can build up a global variable that contains the path to each test suite. When used as a library, it can provide a keyword which returns the contents of this global variable.

For example, you could write a test like this:

    **** Settings ***
    | Library | getsuites.py

    *** Test cases ***
    | Example
    | | @{suites}= | get list of suites

To run it, you have to use the -prerunmodifier:

    pybot --prerunmodifier getsuites.py ...

I've done very, very limited testing, but it seems to work on a very shallow test suite.  Here's the implementation:

    # getsuites.py
    from robot.api import SuiteVisitor

    suites = []

    class getsuites(SuiteVisitor):

        ROBOT_LIBRARY_SCOPE = "GLOBAL"

        # this is for when this class is used as a keyword library
        # We only expose a single keyword.
        def get_keyword_names(self):
            return ["get_list_of_suites"]

        def get_list_of_suites(self):
            """Return a list of all suites to be run"""
            return suites

        # this is used when this class is used as the target of
        # the --prerunmodifier class
        def start_suite(self, suite):
            global suites
            suites.append(suite.source)


Reply all
Reply to author
Forward
0 new messages