Shweta karur
Shweta karur

Reputation: 1

How to get the current Testcase name in Suite Setup in robot framework?

I have .robot file containing Suite setup and few testcases say Test1, Test2 and Test3 . I want to run Test2. But as part of requirement I need to print the current testcase name being executed (i.e. Test2 )in suite setup. As suite setup gets executed before testcase, ${TEST_NAME} cannot be used. Is there any other way to retrieve the current testcase name? . Please help me !

Upvotes: 0

Views: 722

Answers (1)

pavelsaman
pavelsaman

Reputation: 8322

I think your best option is to use visitor interface.

You'd create a new class where you'll iterate over all the tests:

Libraries/Visitor.py

from robot.model.visitor import SuiteVisitor
from robot.api import logger

class Visitor(SuiteVisitor):
    def start_suite(self, suite):
        for test in suite.tests:
            logger.console("{}".format(x))

Then you'd run your tests with --prerunmodifier option where you'll specify your new class like so: --prerunmodifier Libraries/Visitor.py.

It'll list your test cases first and then start executing them.

Upvotes: 1

Related Questions