This:
*** Variable ***
${USER}
${PSW}
means that two variables are creates, variable with name USER
and variable with name PSW
. But they are empty.
This:
*** Test Case ***
ENTER_ID ${USER} ${PSW}
Input Text //input[@name="j_name"] ${USER}
Input Text //input[@name="j_password"] ${PSW}
seems like incorrectly formatted test case. But even if you gave it a name and formatted it properly, you still aren't assigning to those variables USER
and PSW
by the time Input Text
keywords are executed. That's because you're using them as arguments and in keyword:
ENTER_ID
[arguments] ${myUSer} ${myPSW}
${myUSER}= Get Value From User Please enter Name
${myPSW}= Get Value From User Please enter password
there's no assignment into these two variables you're later using with Input Text
keywords.
A working code would be:
*** Variables ***
${USER}
${PWD}
*** Test Cases ***
Input User And Pwd
Ask For Credentials
Input Text //input[@name="j_name"] ${USER}
Input Text //input[@name="j_password"] ${PWD}
*** Keywords ***
Ask For Credentials
${user}= Get Value From User Please enter Name
${pwd}= Get Value From User Please enter password
Set Suite Variable ${USER} ${user}
Set Suite Variable ${PWD} ${pwd}
Set Suite Variable
or Set Global Variable
is necessary here, because simple Set Variable
will create only local variables, but you want to assign to USER
and PWD
in a keyword but use them in a test case elsewhere.
Personally, I'd rather go for an option with a return value, that seems a bit more secure than working with suite or global variables:
*** Test Cases ***
Input User And Pwd
${credentials}= Ask For Credentials
Input Text //input[@name="j_name"] ${credentials.user}
Input Text //input[@name="j_password"] ${credentials.pwd}
*** Keywords ***
Ask For Credentials
${user}= Get Value From User Please enter Name
${pwd}= Get Value From User Please enter password
${credentials} = Create Dictionary user=${user} pwd=${pwd}
[Return] ${credentials}
By this time, you realise, you don't really need those USER
and PWD
variables at all (unless you wan't to use them for something more like setting default values).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…