Skip to content

3.3. Do not hardcode passwords

Goal

  • Instead of hardcoding the username and password in the Variables test data section, the user should provide these variables.

Solution

Hints

You can set variables from command line using --variable option which are available globally.

Click here to learn more about setting variables in command line..

Solution: tests/03-remote/01-connection.robot
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
*** Test Cases ***
Get Date From Remote Host
    Switch Connection    ${HOST}[alias]
    ${date}=    Execute Command    date

    Log To Console    ${date}

Test Package Management
    APK Search    ${HOST}[alias]    ipython

*** Keywords ***
Open Connection And Log In With Password
    Open Connection
    ...    ${HOST}[name]
    ...    port=${HOST}[port]
    ...    alias=${HOST}[alias]

    Login
    ...    ${SSH_USERNAME}
    ...    ${SSH_PASSWORD}

*** Settings ***
Library        SSHLibrary
Resource       ${CURDIR}${/}resources${/}apk-management.resource
Suite Setup    Open Connection And Log In With Password

*** Variables ***
&{HOST}    name=localhost    port=2222    alias=openssh-server-for-robot

Results

Inside the tests folder, execute the following command to execute 03-Remote suite.

1
2
3
4
robot \
  --variable SSH_USERNAME:robotdev \
  --variable SSH_PASSWORD:Hn7c5%lyBpIn8*8Z \
  --suite 03-remote .

You can check the generated log.html file to see how your test cases worked.


Last update: June 22, 2020