Is it possible to call keyword along with template in robotframework,
*** Keywords ***
PASSWORD UPDATE
[Arguments] ${apidata} ${expctdRspnce} ${jmxPath}
---------
-------
*** Test Cases ***
CHANGE_PASSWORD
${apidata} = Get Excel value 2 3
${expctdRspnce} = Get Excel value 2 5
[Template] PASSWORD UPDATE
${apidata} ${expctdRspnce} ${jmxPath}
In above code i am calling get excel value before calling the template.So here i am getting below error,
Keyword 'PASSWORD UPDATE' expected 3 arguments, got 4.
If i remove both the variables and call only the template then it is working fine.Is there any way to call kewyrods before calling template?
Related
I wrote this simple minimal script to show how I suffer:
main.robot
Library Collections
Library BuiltIn
Library String
*** Variables ***
&{info} Create Dictionary
*** Test Cases ***
Case_00_Initialization
Log Hello 1 WARN
Set To Dictionary ${info} field1=A sample string
Log Hello 2 WARN
Running this code by
python -m robot -L TRACE --NoStatusRC main.robot
Gives me errors:
[ ERROR ] Error in file 'C:\test\main.robot' on line 7: Setting variable '&{info}' failed: Invalid dictionary variable item 'Create Dictionary'. Items must use 'name=value' syntax or be dictionary variables themselves.
==============================================================================
Main
==============================================================================
[ WARN ] Hello 1
Case_00_Initialization | FAIL |
No keyword with name 'Set To Dictionary' found.
------------------------------------------------------------------------------
Main | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\test\output.xml
Log: C:\test\log.html
Report: C:\test\report.html
The application is supposed to set a variable info in the initialization and it will be used in the next test cases. I do not want to use Set Global Variable however.
Please note that this is a minimal working example, do not suggest to set field1 at Variables section. It is not possible. Even that one will not solve the problem of No keyword with name 'Set To Dictionary' found.
In the Variables section you cannot use keywords - and this is exactly what you did with the Create Dictionary there.
You can add some key:values to it (like "field" , but you don't allow us that ;), or - you can initialize it to be an empty dictionary (e.g. like {} in python). The later is done by passing the special value &{Empty}:
*** Variables ***
&{info} &{Empty}
I eventually found what is wrong. I was missing the line for *** Settings *** I couldn't imagine that it does matter. Shame that RF does not have many full examples online.
This is the working code:
*** Settings ***
Library Collections
*** Variables ***
&{info}
*** Test Cases ***
Case_00_Initialization
Log Hello 1 WARN
Set To Dictionary ${info} field1=A sample string
Log Hello 2 WARN
I'm playing around with command-line arguments and had something working both with / without giving a command-line argument, but suddenly it starts failing if I don't give a command-line argument.
On https://groups.google.com/g/robotframework-users/c/_5Usp-K4Dlw?pli=1 I read that adding a space before the variable and comparing it to a value like this '${ VAR}'==<value> should work to check if a variable is existing or not.
The code-snippet that was working before is:
*** Test Cases ***
My test
[Documentation] test to check if the SUT reacts as expected
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test} Log To Console VAR == test
After changing the code to (Removed '[Documentation]' since it was copied from another test):
*** Test Cases ***
My test
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test}
... Log To Console VAR == test
it suddenly started failing with: Variable '${ VAR}' not found. errors.
And after changing it back to the original it still fails.
I can't figure what I did wrong in the change.
Note: The company I'm working for uses RobotFramework version 3.0.4 (yes I know ancient)
Managed to solve it by adding ${VAR} with some default value to a *** Variables *** list. But still I don't understand why it was originally working without that list.
Here is how your test should look like if you want to check if variable is empty and do something based on that.
*** Variables ***
${VAR}= test
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is empty
... ELSE Log To Console Variable is not empty
If you want variable default value to be empty and execute some keyword only if it comes from command line set variable as empty, for example:
*** Variables ***
${VAR}= ${EMPTY}
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is not set
... ELSE Log To Console Variable is ${VAR}
Run your test from command-line without passing variable
$ robot sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is not set
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Now, run with passing variable
$ robot -v VAR:test sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is test
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
P.S. About space inside variable, I think it's just typo in Google Groups. If it was working then variable might be globally accessible or defined somewhere else.
This test case if working fine in Robot Framework 3.1.2 but in 3.2.1 I'm getting error message:
Setting 'Template' accepts only one value, got 2.
I can't see that there is any updates to the documentation that explains this. Any ideas?
*** Test Cases ***
Test Case
[Template] The result of ${calculation}
... should be ${expected}
1 + 1 2
2 + 2 4
*** Keywords ***
The result of ${calculation} should be ${expected}
${result} = Evaluate ${calculation}
Should Be Equal As Integers ${result} ${expected}
The ... marks an argument boundary. What you did is exactly the same as this:
[Template] The result of ${calculation} should be ${expected}
Like the error says, the [Template] setting only accepts a single argument but you're passing two. You cannot define the keyword on multiple lines.
It appears that the old (pre 3.2) parser may have been a bit lax and allowed you to split the template keyword on multiple lines. The new parser doesn't allow that.
I am curious if it's possible to modify some default argument when I try using following keyword during test case creation. See example below.
*** Keywords ***
Open URL With Custom Parameters
[Arguments] ${fe}=example.lan ${be}=https://example.be.lan ${reminderInterval}=5 ${licence}=default ${flowId}=7349 ${name}=example ${cur}=EUR ${lang}=en
... ${browser}=chrome
Open Browser https://${fe}/${name}/debug_index.html?&appsrv=${be}¤cy=${cur}&lang=${lang}&reminderInterval=${reminderInterval}&fullscreen=yes&license=${licence} ${browser}
I would like to modify only 2 dedicated arguments e.g. Below doesn't work
*** Test Cases ***
Open browser and do sth
Open URL With Custom Parameters ${name}=development ${be}=https://goodday.com`
If is possible to change default argument from keyword in different order where is set it in keyword?
I would like to avoid adding all remains parameter to change only 1 or 2 arguments like below:
*** Test Cases ***
Open browser and do sth
Open URL With Custom Parameters ${fe}=https://development ${be}=https://goodday3421.com
....
Yes, it's possible, just don't use the ${} around the arguments' names when calling the keyword:
Open URL With Custom Parameters fe=https://development be=https://goodday3421.com
I am attempting to create a dictionary based upon data in an xls spreadsheet. Below is my code. However, when performing the "set to dictionary" (last line of the code snippet below), I'm getting the following error: TypeError: 'unicode' object does not support item assignment. Any ideas as to what I'm missing?
*** Settings ***
Library ExcelLibrary
Library Collections
*** Variables ***
${PageSheetName} = Welcome Page
${WelcomeDict} = Create Dictionary
*** Test Cases ***
Excel Sandbox Test
Get Values from Spreadsheet
#Print out the Dictionary
*** Keywords ***
Get Values from Spreadsheet
# Open the file
Open Excel Current Directory ${Excel_File_Path}DataExtract.xls
# Get the number of rows
${iTotalRows} = Get Row Count ${PageSheetName}
# Loop through each row to get the data. Only need data from Columns A & B
: FOR ${iRowNum} IN RANGE 1 ${iTotalRows}+1
\ ${KeyVal} = Read Cell Data By Name ${PageSheetName} A${iRowNum}
\ ${Value} = Read Cell Data By Name ${PageSheetName} B${iRowNum}
\ Create the Welcome Page Dictionary ${KeyVal} ${Value}
Create the Welcome Page Dictionary
[Arguments] ${key} ${val}
Set To Dictionary ${WelcomeDict} ${key} ${val}
Consider this block of code:
*** Variables ***
${WelcomeDict} = Create Dictionary
It is creating a string variable with the value "Create Dictionary". You cannot call keywords in the *** Variables *** section.
From the robot framework user guide:
Variable tables are convenient, because they allow creating variables in the same place as the rest of the test data, and the needed syntax is very simple. Their main disadvantages are that values are always strings and they cannot be created dynamically.
If you want to initialize a dictionary, use &, and just don't provide any values:
*** Variables ***
&{WelcomeDict}=