1

I have a robot test table and am running pybot. The robot/pybot calls a python function. Can I pass the test number to my python function ?

I realize I can do this by appending a number to my robot test table, but its painful to do this because its a huge table with formatting. Is there another way?

The tests are like (shorter form of the actual test table, its too big to paste)

=================================================
Test Case           Action          Arguments
=================================================
Test connection   mytest.setup      ${Bucket}
Verify files      mytest.verify     ${filename}
Search logs       mytest.searchlog  ${string_to_search}
==================================================

So when I call mytest.searchlog() in python (mytest is my python file), how do I tell it that this is the 3rd test case?

I am running it with pybot

pybot --variable Bucket:mybucket .....  testfile.rst

1 Answer 1

1

It seems to me that you can implement this using a counter that is reset every test case and stores it's value in the Test Case variable scope.

Using the data driven example found here I created the below example where the test case has the [setup] section added and the keyword that is called each time for every data record has a [teardown] section. Although it could handled inside the keyword as well.

*** Test Cases ***
Calculation error     [Template]    Calculation should fail
                      [setup]    Set Test Variable     ${counter}    0
                      kekkonen      Invalid button 'k'.
                      ${EMPTY}      Invalid expression.
                      1 / 0         Division by zero.
*** Keywords ***
Calculation should fail
    [Arguments]    ${expression}    ${expected}
    ${error} =    Should cause error    C${expression}=
    Should be equal    ${expected}    ${error}    # Using `BuiltIn` keyword
    [teardown]    Counter

Counter
    ${countr}=       Get Variable Value   ${counter}
    ${countr}=     evaluate    ${countr}+1
    Set Test Variable    ${counter}    ${countr}

The variable can be called within the scope of the Test Case, this also includes the keywords that are called within that given test case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.