-1

I have found many cases where described how can be executed some test case with data range inside, but I need create separated test cases based on some array.

For example I have a boxes range on which I need check some scenarios:

  • Login on box
  • Execute command some command (ex. echo 'Hello world')

In all cases login, password, test command would be the same. One difference - IP\Computername.

Now it is look like this, and for me it's look strange when VM count > 10:

*** Settings ***
Library     SSHLibrary
Library     OperatingSystem
Library     String

*** Variable ***
${HOST}
${USERNAME}
${PASSWORD}

*** Test Case ***
Logging-into-VM1
    Open Connection And Log In     ${VM1}
Executing-Commands-on-VM1
    Executing commands

Logging-into-VM2
    Open Connection And Log In     ${VM2}
Executing-Commands-on-VM2
    Executing commands

.....

Logging-into-VMn
    Open Connection And Log In     ${VMn}
Executing-Commands-on-VMn
    Executing commands


*** Keywords ***
Open Connection And Log In
    [Arguments]     ${BOX}
    Open Connection     ${BOX}
    Login               ${USERNAME}     ${PASSWORD}
Executing commands
    ${testcmd}=     Execute Command     echo 'Hello world'

In this case I receive correct output, but it's strange for me use Copy\Paste method for tests if their more than 10 (example if I need test 100 VM's i need write 400 strings with 1 difference for every 4 strings)

If i tries execute something like that (which looks much better for me):

*** Settings ***
Library     SSHLibrary
Library     OperatingSystem
Library     String

*** Variable ***
${USERNAME}
${PASSWORD}

*** Test Case ***

Logging and commands executes
    [Template]    Conectivity tests {BOX}
    ${VM1}
    ${VM2}
    ${VM3}
    ....    
    ${VMn}


*** Keywords ***

Conectivity tests
    [Arguments]     ${BOX}
    Open Connection     ${BOX}
    Login               ${USERNAME}     ${PASSWORD}
    ${hostname}=     Execute Command    hostname

I get only one test case with non informal result:

=================================================================
ttestcase12
=================================================================
Logging and commands executes                            | FAIL |
Several failures occurred:

1) timeout: timed out

2) timeout: timed out

3) timeout: timed out

4) timeout: timed out

5) timeout: timed out

6) timeout: timed out

7) timeout: timed out
------------------------------------------------------------------
ttestcase12                                               | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed

I receive this "great" result, looking on which I do not understand what was passed, and what not

This sample looks much better:

*** Settings ***
Library          SSHLibrary
Library          OperatingSystem
Library          String
Test Template    Conectivity tests

*** Variable ***
${USERNAME}
${PASSWORD}

*** Test Cases ***          BOX

Conectivity tests VM1       ${VM1}
Conectivity tests VM2       ${VM2}
Conectivity tests VM3       ${VM3}

....

Conectivity tests VMn       ${VMn}

*** Keywords ***

Conectivity tests
    [Arguments]       ${BOX}
    Open Connection   ${BOX}
    Login             ${USERNAME}     ${PASSWORD}
    ${hostname}=      Execute Command     hostname





====================================================================
ttestcase12
====================================================================
Conectivity tests VM1                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Conectivity tests VM2                                       | PASS |
--------------------------------------------------------------------
Conectivity tests VM3                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Conectivity tests VM4                                       | FAIL |
timeout: timed out

.....

--------------------------------------------------------------------
Conectivity tests VMn                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Sanityv8                                                    | FAIL |
99 critical tests, 12 passed, 87 failed
99 tests total, 12 passed, 87 failed

Also all of this scenarios require different test suites for example if in some case I need test 99 VMs and sometimes 100 (which include previous 99)...

I want once more time akcent that I need separate tests (with separate results PASS\FAIL) instead loop in one test case

Link on similar question but without answer: In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?

Links with scenarios stored in one test case (not the same that I need): http://www.thinkpalm.com/blogs/data-driven-testing-robot-framework/

Victor Dronov
  • 139
  • 1
  • 12
  • Did you try the Data-driven style? http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#data-driven-style – Eddy Pronk Jul 18 '18 at 06:10
  • Hi Eddy, could you please describe how it should look like based on my sample? – Victor Dronov Jul 18 '18 at 07:39
  • I`m trying play with it 3 days, and maybe not understanding correct what I should do... – Victor Dronov Jul 18 '18 at 07:53
  • 1
    Hey, I think I got something that you might want to try... though it will get away from how robot reads: [Programatic Test Generation](https://robot-framework.readthedocs.io/en/3.0.1/autodoc/robot.running.html#examples). You can write a script to build your robot tests and run them. – bison Aug 03 '18 at 20:09
  • Thanks @GrantMcCloskey, I will try to test your solution :) – Victor Dronov Aug 06 '18 at 09:48

3 Answers3

2
Simple solution:

*** Settings ***
Library           SSHLibrary

*** Test Cases ***
loop
    [Template]    loopcall
    VM1    root    pwd1
    VM1    root    pwd2

*** Keywords ***
loopcall
    [Arguments]    ${machine}    ${user}    ${pwd}
    Open Connection    ${machine}    prompt=$
    Login    ${user}    ${pwd}
    ${hostname}=    Execute Command    hostname
    log    ${hostname}
    Close Connection
Basavaraj
  • 93
  • 1
  • 2
  • 6
  • actually, this variant described as non-informative one in my question because console output does not contain something that can trigger something which exactly case failed – Victor Dronov Jul 31 '18 at 10:40
0

So for now solution was found in python:

  • I have external script which create configuration file for data driven testcase
  • The same script create on-the-go tescase with required tests, based on tescase template
  • And at the end the same python script execute robot framework:

    call(['python.exe', '-m', 'robot', '-V', "params.py", testfile])

Victor Dronov
  • 139
  • 1
  • 12
0

You could look at RobotFramework-Examples library (disclaimer: I am the author). This allows the data to be read in from external source during Suite setup - the data can then be used as example data for a given test sequence.

  • this was interested for me 3 years ago :) for now I do not have access to that tests and even don`t know is those tests still exists in case if you could provide detailed info, I can try find someone who can check in my previous team – Victor Dronov Dec 15 '21 at 22:36