siesta
siesta

Reputation: 1415

Setting up SSH in robot framework with multiple hosts

Within robot framework, I can use a for loop in each test case to Start an SSH connection to each host within a list, and then run commands on that host.

But it seems that the ssh setup happens in every test case which takes a considerable amount of time.

Is there some way in which I can make the connection persistent for every test case in a test suite?

Example Code:

*** Settings ***
Variables       sys_variables.py
Resource        ${RESOURCES}/common.robot

*** Test Cases ***
Ping            :FOR    ${HOST}     IN  @{REACHABLE}
                \   SSH to ${HOST} ${USER} ${PASS}
                \   ${result} = Run and Log ${PING_GOOGLE_DNS}
                \   Should Be Equal As Integers  ${result}  0
                \   log  ${result}

This works, but I'd like to not have to run it in every testcase.

Upvotes: 0

Views: 2190

Answers (1)

OGrandeDiEnne
OGrandeDiEnne

Reputation: 888

Just put the tests in a single suite and make the connections in the suite setup. The suite setup is executed one time, before the actual test executions.

Consider the following example code:

*** Settings ***
Suite Setup       SuiteSetup

*** Test Cases ***
Test1
    Log    This is the test 1

Test2
    Log    This is the Test 2

*** Keywords ***
SuiteSetup
    Log    This is the single setup

Put your connection cycle inside the SuiteSetup keyword and you're done.

Upvotes: 3

Related Questions