I've been trying to use the faker library to generate data without having it in my test cases as static data.
I have tried calling fake.md5(raw_output=False) directly from my keyword and also by creating a variable and assigning it this value, but neither has the intended effect. It seems that no matter what I do, the only output I'm getting during my test is fake.md5(raw_output=False).
What am I doing wrong?
Edit: My keyword (it writes to a specific field, this is just a test keyword to make sure I can use faker) -
Write username
${md5}= MD 5
${my data}= log md5: ${md5}
Input Text a11y-username ${my data}
Edit #2 - I realized I had missed out the log keyword, I have updated my code
The problem is in this statement:
${my data}= md5: ${md5}
Robot expects the first cell (or the first cell after a variable name) to be a keyword. So, in this case it thinks md5: ${md5} is a keyword, which it obviously is not. That is why you get the error No keyword with name 'md5: ${md5}' found.
I don't know what you're expecting to do with that line of code. Your value is already in a variable, are you trying to copy it to another variable, or simply print it out?
If your intention was to log the value, use the Log keyword:
Write username
${md5}= MD 5
log md5: ${md5}
If you instead want to copy the value to another variable, you can use the Set Variable keyword:
write username
${md5}= MD 5
${my data}= set variable ${md5}
Input Text a11y-username ${my data}
Related
Create user //Is my test case name
${random_string}= Generate Random String 8 [LOWER]
Set Global Variable ${random_string}
${body}= create dictionary email=${random_string}#mail.com firstName=${random_string} lastName=${random_string} role=ADMIN
${response}= Post On Session mysession /user json=${body} headers=${headers} //This is One Response for POST Method
${getuserresponse}= GET On Session mysession /user headers=${headers} //This is 2nd response for GET method which return all the users
FOR ${i} IN #{getuserresponse.json()}
#Validation
IF ${i['firstName']} == ${random_string} // I want to check weather GET Response contains email that I send from POST request
Log User Created Successfully
ELSE
Log User Not Created Successfully
END
Instead it gives me Error as
Evaluating IF condition failed: Evaluating expression 'ptrmipuy'(this is random_string) failed: NameError: name 'ptrmipuy' is not defined nor importable as module
Your conditions cannot have sequences with two or more spaces, since that's what robot uses to parse a statement. Everywhere you have == it needs to be ==
Also, your expressions either need to quote the string values or you can use the special syntax that converts the robot variables into python variables.
IF "${i['firstName']}" == "${random_string}"
-or-
IF $i['firstName'] == $random_string
This is covered in the documentation for the BuiltIn library, in a section titled Evaluating Expressions
Try below snippet of if else, if it works then copy paste this syntax and replace your variable. Also print your variable before comparing, if it has extra quotes, then you might get that error.
Also you should have only space before and after this symbol "=="
*** Test Cases ***
Testifelse
${Variation}= Set Variable NA
IF "${Variation}" == "NA"
Log if
ELSE
Log else
END
I am trying to move over some API calls I had working over to python from postman, I am having some issues making a variable callable by my next get request. I've found a few things while searching but never found a 100% answer on how to call the environment variable in the get request...is it correct to use the {{TEST}} to call that var. Example below.
Test = Myaccoount
Json_Response_Test = requests.get('https://thisisjustatesttoaccessmyaccount/{{Test}}')
How can I carry over Test into the request?
Your code will almost work as you have it if you use the feature of newer version of Python called "format strings". These are denoted by a f at the beginning of the string. This works like this in such versions of Python:
Test = Myaccoount
Json_Response_Test = requests.get(f'https://thisisjustatesttoaccessmyaccount/{Test}')
as long as Myaccoount is a valid value that can be expanded by Python into the format string.
If you're using an older version of Python, you could do something like this:
Test = Myaccoount
Json_Response_Test = requests.get('https://thisisjustatesttoaccessmyaccount/{}'.format(Test))
BTW, it's not good form to use uppercase first character names for variables. The convention is to use uppercase only for class and type names, and use lowercase for variable and field names.
I store in database a string with concatenated variables but when I fetch it, it behaves like string, and the variable values are not reflected.
Stored in database field I have:
"""\
Please visit the following link to grant or revoke your consent:
"""+os.environ.get("PROTOCOL")+"""://"""+os.environ.get("DOMAIN")+"""/consent?id="""+consentHash+""""""
I need to be able to fetch it in python and store it in a variable but have the concatenated variable values reflected:
someVariable = database['field']
But like this the concatenated variable values are not processed and the whole thing behaves like one string.
When I print(someVariable) I am expecting
Please visit the following link to grant or revoke your consent:
https://somedomain/consent?id=123
But instead I get the original stored string as in database field:
"""\
Please visit the following link to grant or revoke your consent:
"""+os.environ.get("PROTOCOL")+"""://"""+os.environ.get("DOMAIN")+"""/consent?id="""+consentHash+""""""
You can call eval on your string to have it, uh, evaluate the string as an expression.
Using eval is considered dangerous, because it can be used to do pretty much anything you could write code for, without knowing just what that code will be ahead of time. This is more of an issue when using it on strings provided from an outside source.
If I pass the string ${varName} to the built in keyword Log to Console, the console outputs the literal string ${varName}. If there is a variable named varName with a value of test123, how do I get the keyword Log to Console to output the variable value of test123 when I pass in ${varName}?
I'm making a data-driven script from an Excel spreadsheet. In the string values I'm passing in, there are variables names within it that I want replaced with the variable's value.
I've tried to run the string through the Evaluate keyword, but it just changes all of the variable names like ${varName} to RF_VAR_varName, so it's recognizing something here?
Open Excel ${ExcelFile}
${varName} Read Cell Data By Coordinates ${Sheet_Name} 0 ${RowNum}
set global variable ${varName}
log varName: ${varName} console=yes
Would output to the console:
'38773461|${TMS_ConfNo}|substr:RDSJUMHV FIRSTNAME|${globalLastName} FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|${globalLastName1}, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|${globalLastName}, FIRSTNAME|fullline'
I would like this string:
'38773461|${TMS_ConfNo}|substr:RDSJUMHV FIRSTNAME|${globalLastName} FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|${globalLastName1}, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|${globalLastName}, FIRSTNAME|fullline'
To evaluate into this:
'38773461|12345678|substr:RDSJUMHV FIRSTNAME|LASTNAME FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|LASTNAME1, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|LASTNAME, FIRSTNAME|fullline'
I would like all variables in the string to translate to their respective value.
Robot has a built-in keyword named Replace variables which will replace variables with their values in a string.
I hope you can help me, I am quite stuck with this issue :(
I am trying to create all the tests using the robot api with python, I followed the example in the documentation, but I need to capture the output from a keyword and I dont find how can I do it
I tried as usual in rf-ride syntax:
test.keywords.create('${greps}= grep file', args=['log.txt', 'url:', 'encoding_errors=ignore'])
It says: No keyword with name '${grep}= grep file' found.
I tried:
output = test.keywords.create('grep file', args=['log.txt', 'url:', 'encoding_errors=ignore'])
but the variable output is having just the keyword name, not the output from kw
I dont know where to look for more info, all the examples are creating kw which dont return any value...
The call to test.keywords.create(...) doesn't call the keyword, it merely creates one to be called later. If you want the results to be assigned to a variable, use the assign attribute when calling create. This argument takes a list of variable names.
For example, given this line in plain text format:
${greps}= grep file log.txt url: encoding_errors=ignore
... you would create it like this using the API:
test.keywords.create('grep file',
args=['log.txt', 'url:', 'encoding_errors=ignore'],
assign=['${greps}'])