Robot Framework - How to if statement if keyword fails - robotframework

${Var_Name}= page should contain element ${ID}
run keyword if "some keyword" ${Var_Name} false
If the page doesn't contain the element the test fails, is it possible to ignore the fail and run "some keyword" as it returns false?

The keyword 'page should contain element' does not return anything, so ${Var_Name} will not contain a value apart from 'None' when the 'page should contain element' test succeeds.
You could use the keyword "Get Matching Xpath Count" from the selenium2Library and perform the required action in an if/else statement based on the value of the xpath count.
like so:
${value}= | Get Matching Xpath Count | [xpath]
Run Keyword If | ${value} > 0 | [keyword]
... | ELSE | [keyword]

Related

Robot Framework ellipsis concatenate adding commas

In Robot Framework when I try and use the ellipsis to put a long statement on multiple lines it is adding a comma at the break.
${Built_query} = Set Variable select oid, activityCode, activity_description from tblActivity
... where ACTIVITY_ENDDATE is null order by oid
And that's 4 spaces ellipsis and two spaces.
the result is:
'select oid, activityCode, activity_description from tblActivity', 'where ACTIVITY_ENDDATE is null order by oid'
Any help will be appreciated.
Sam.
When you use ..., each line represents one or more arguments to the keyword. In your case, Set Variable is seeing two separate arguments. When Set Variable gets more than one argument, it creates a list.
If you want to create a string that is spread out on different lines, you need to use Catenate. With Catenate you can define what is used to join each line. By default it uses a single space.
${Built_query}= Catenate
... select oid, activityCode, activity_description from tblActivity
... where ACTIVITY_ENDDATE is null order by oid
Here is a complete test, which passes when run:
*** Test Cases ***
Example
${Built_query}= Catenate
... select oid, activityCode, activity_description from tblActivity
... where ACTIVITY_ENDDATE is null order by oid
Should be equal
... ${Built_query}
... select oid, activityCode, activity_description from tblActivity where ACTIVITY_ENDDATE is null order by oid

Kusto sub query selection using toscalar - returns only last matching record

I am referring sqlcheatsheet - Nested queries
Query 1:
traces
| where customDimensions.Domain == "someDomain"
| where message contains "some-text"
| project itemId=substring(itemId,indexof(itemId,"-"),strlen(itemId))
Result :
itemId
-c580-11e9-888a-8776d3f65945
-c580-11e9-888a-8776d3f65945
-c580-11e9-9b01-c3be0f4a2bf2
Query 2:
traces
| where customDimensions.Domain == "someDomain"
| where itemId has toscalar(
traces
| where customDimensions.Domain == "someDomain"
| where message contains "some-text"
| project itemId=substring(itemId,indexof(itemId,"-"),strlen(itemId)))
Result for the second query returns records matching only last record of sub query
ie:) > -c580-11e9-9b01-c3be0f4a2bf2
Question :
How get entire result set that has matching with all the three items.
My requirement is to take entire sequence of logs for a particular request.
To get that I have below inputs, I could able to take one log, from that I can find ItemId
The itemId looks like "b5066283-c7ea-11e9-9e9b-2ff40863cba4". Rest of all logs related to this request must have "-c7ea-11e9-9e9b-2ff40863cba4" this value. Only first part will get incremented like b5066284 , b5066285, b5066286 like that.
toscalar(), as its name implies, returns a scalar value.
Given a tabular argument with N columns and M rows it'll return the value in the 1st column and the 1st row.
For example: the following will return a single value - 1
let T = datatable(a:int, b:int, c:int)
[
1,2,3,
4,5,6,
7,8,9,
]
;
print toscalar(T)
If I understand the intention in your 2nd query correctly, you should be able to achieve your requirement by using has_any.
For example:
let T = datatable(item_id:string)
[
"c580-11e9-888a-8776d3f65945",
"c580-11e9-888a-8776d3f65945",
"c580-11e9-9b01-c3be0f4a2bf2",
]
;
T
| where item_id has_any (
(
T
| parse item_id with * "-" item_id
)
)

DynamoDB boto3 : How to query if a key has some value

I'm writing a python code to query a table on dynamo DB. Along with other conditions I'd also like to get rows where there exists some value for the key I'm specifying.
KeyConditionExpression = Key('Status').eq('Done') & Key('Name').begins_with('A') & Key('Error').exists()
In the code above, I'd like to display rows where the column "Error" has some value be it anything.
but the last condition is throwing an error.
AttributeError: 'Key' object has no attribute 'exists'.
How can modify the code to incorporate the third query?
Assuming that your “Error” key is neither your partition key and nor sort key as you must specify the partition key name and value as an equality condition always. Also, for the sort key you can use one of the undermentioned comparison operators.
a = b — true if the attribute a is equal to the value b
a < b — true if a is less than b
a <= b — true if a is less than or equal to b
a > b — true if a is greater than b
a >= b — true if a is greater than or equal to b
a BETWEEN b AND c — true if a is greater than or equal to b, and less than or equal to c.
begins_with (a, substr)— true if the value of attribute a begins with a particular substring.
Now coming back to your issue, if you are using Query operation, then you can definitely use QueryFilter to check if some non-null value exists for key “Error”. The official documentation defines QueryFilter as :
In a Query operation, QueryFilter is a condition that evaluates the query results after the items are read and returns only the desired values.
The following comparison operators are available for QueryFilter:
EQ | NE | LE | LT | GE | GT | NOT_NULL | NULL | CONTAINS | NOT_CONTAINS | BEGINS_WITH | IN | BETWEEN
Please refer to the undermentioned link to get more idea about the QueryFilter and FilterExpression
AWS Official Documentation Link : https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/LegacyConditionalParameters.QueryFilter.html

Replacing empty string column with null in Kusto

How do I replace empty (non null) column of string datatype with null value?
So say the following query returns non zero recordset:-
mytable | where mycol == ""
Now these are the rows with mycol containing empty strings. I want to replace these with nulls. Now, from what I have read in the kusto documentation we have datatype specific null literals such as int(null),datetime(null),guid(null) etc. But there is no string(null). The closest to string is guid, but when I use it in the following manner, I get an error:-
mytable | where mycol == "" | extend test = translate(mycol,guid(null))
The error:-
translate(): argument #0 must be string literal
So what is the way out then?
Update:-
datatable(n:int,s:string)
[
10,"hello",
10,"",
11,"world",
11,"",
12,""
]
| summarize myset=make_set(s) by n
If you execute this, you can see that empty strings are being considered as part of sets. I don't want this, no such empty strings should be part of my array. But at the same time I don't want to lose value of n, and this is exactly what will happen if I if I use isnotempty function. So in the following example, you can see that the row where n=12 is not returned, there is no need to skip n=12, one could always get an empty array:-
datatable(n:int,s:string)
[
10,"hello",
10,"",
11,"world",
11,"",
12,""
]
| where isnotempty(s)
| summarize myset=make_set(s) by n
There's currently no support for null values for the string datatype: https://learn.microsoft.com/en-us/azure/kusto/query/scalar-data-types/null-values
I'm pretty certain that in itself, that shouldn't block you from reaching your end goal, but that goal isn't currently clear.
[update based on your update:]
datatable(n:int,s:string)
[
10,"hello",
10,"",
11,"world",
11,"",
12,""
]
| summarize make_set(todynamic(s)) by n

Remove special characters from array elements and mix it with another array

I apologize if this is repeated, but I'm total noob with Robot framework, and I would need help. I have two arrays, results from database:
#{users}= query Select * from users
#{fieldNames}= query SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'robot_test' AND TABLE_NAME = 'users';
Results that I get from this are:
#{users}= (1, 'user1', 'pass1', 'admin'), (2, 'user2', 'pass2', 'user')
#{fieldNames} = [ ('id',) | ('username',) | ('password',) | ('role',) ]
I would like to filter #(fieldNames) to become
#{fieldNames} = [ 'id','username','password','role']
And then to mix it with #(users) to get
#{mixedArray}= (('id',1) , ('username','user1'), ('password','pass1'), ('role','admin')), (('id',2) , ('username','user2'), ('password','pass2'), ('role','user'))
Is there a way to do this? Thanks everyone for help.
Because database library returns query results as a list of tuples, you can just iterate through them. Only cleaning I did was to use Combine Lists to get rid of tuples inside fieldNames list.
*** Settings ***
# Library Dialogs
Library Collections
Library DatabaseLibrary
library pymysql
*** Variables ***
#{database} pymysql users root df478444 localhost 3306
*** Test Cases ***
Stackoverflow
Connect To Database #{database}
#{users}= query Select * from Users
#{fieldNames}= query SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'users' AND TABLE_NAME = 'Users';
#{fields list}= Combine Lists #{fieldNames}
#{mixedArray}= Create List
:FOR ${user} IN #{users}
\ ${user row}= parse user ${user} ${fields list}
\ Append To List ${mixedArray} ${user row}
Log ${mixedArray}
*** Keywords ***
Parse User
[Arguments] ${user} ${fields}
#{line}= Create List
${list length}= Get Length ${fields}
:FOR ${i} IN RANGE ${list length}
\ #{pair}= Create List
\ ${f}= Get From List ${fields} ${i}
\ ${u}= Get From List ${user} ${i}
\ Append To List ${pair} ${f}
\ Append To List ${pair} ${u}
\ Append To List ${line} ${pair}
Return From Keyword ${line}

Resources