Robot Framework - How to get a value inside a list of Rows
up vote
0
down vote
favorite
I am running a query from robot framework to get an id from the database, The query works but my returned value is 'locationId': ['[('somekindofIdhere', )] I need to just the somekindofIdhere value,
I have tried to get the first index of the list
Verify Location Details
@{Get_LocationId}= Query Select locationId From Location WHERE LocationName = '${Name}'
${Response_Location}= Rest.get http://sampleurl/sample/locations/@{Get_LocationId}[0]
but that Gives me back this ('somekindofIdhere', ) how can i get rid of the () characters and just get the value?
arrays list robotframework
add a comment |
up vote
0
down vote
favorite
I am running a query from robot framework to get an id from the database, The query works but my returned value is 'locationId': ['[('somekindofIdhere', )] I need to just the somekindofIdhere value,
I have tried to get the first index of the list
Verify Location Details
@{Get_LocationId}= Query Select locationId From Location WHERE LocationName = '${Name}'
${Response_Location}= Rest.get http://sampleurl/sample/locations/@{Get_LocationId}[0]
but that Gives me back this ('somekindofIdhere', ) how can i get rid of the () characters and just get the value?
arrays list robotframework
The used keywordQueryis a custom keyword or one from an existing library?
– A. Kootstra
Nov 7 at 12:46
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am running a query from robot framework to get an id from the database, The query works but my returned value is 'locationId': ['[('somekindofIdhere', )] I need to just the somekindofIdhere value,
I have tried to get the first index of the list
Verify Location Details
@{Get_LocationId}= Query Select locationId From Location WHERE LocationName = '${Name}'
${Response_Location}= Rest.get http://sampleurl/sample/locations/@{Get_LocationId}[0]
but that Gives me back this ('somekindofIdhere', ) how can i get rid of the () characters and just get the value?
arrays list robotframework
I am running a query from robot framework to get an id from the database, The query works but my returned value is 'locationId': ['[('somekindofIdhere', )] I need to just the somekindofIdhere value,
I have tried to get the first index of the list
Verify Location Details
@{Get_LocationId}= Query Select locationId From Location WHERE LocationName = '${Name}'
${Response_Location}= Rest.get http://sampleurl/sample/locations/@{Get_LocationId}[0]
but that Gives me back this ('somekindofIdhere', ) how can i get rid of the () characters and just get the value?
arrays list robotframework
arrays list robotframework
edited Nov 7 at 16:21
asked Nov 7 at 11:42
Wojtek T
968422
968422
The used keywordQueryis a custom keyword or one from an existing library?
– A. Kootstra
Nov 7 at 12:46
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40
add a comment |
The used keywordQueryis a custom keyword or one from an existing library?
– A. Kootstra
Nov 7 at 12:46
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40
The used keyword
Query is a custom keyword or one from an existing library?– A. Kootstra
Nov 7 at 12:46
The used keyword
Query is a custom keyword or one from an existing library?– A. Kootstra
Nov 7 at 12:46
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The query returns a list of lists - the outer list is a list of rows returned by the query, and the inner lists are lists of columns. This will be true even if the query returns a single column in a single row. You can use robot's embedded variable syntax to reference the value you want:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
Here is a complete that that illustrates the difference. I'm simulating the data in @{Get_LocationId} so that the test doesn't require an actual database connection.
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The[0][0]needs to be inside the curly braces.
– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :Value of variable '@{Get_LocationId[0][0]}' is not list or list-like.I just relized I was using@instead of$Thanks for the answer, That works
– Wojtek T
Nov 7 at 16:17
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The query returns a list of lists - the outer list is a list of rows returned by the query, and the inner lists are lists of columns. This will be true even if the query returns a single column in a single row. You can use robot's embedded variable syntax to reference the value you want:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
Here is a complete that that illustrates the difference. I'm simulating the data in @{Get_LocationId} so that the test doesn't require an actual database connection.
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The[0][0]needs to be inside the curly braces.
– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :Value of variable '@{Get_LocationId[0][0]}' is not list or list-like.I just relized I was using@instead of$Thanks for the answer, That works
– Wojtek T
Nov 7 at 16:17
add a comment |
up vote
2
down vote
accepted
The query returns a list of lists - the outer list is a list of rows returned by the query, and the inner lists are lists of columns. This will be true even if the query returns a single column in a single row. You can use robot's embedded variable syntax to reference the value you want:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
Here is a complete that that illustrates the difference. I'm simulating the data in @{Get_LocationId} so that the test doesn't require an actual database connection.
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The[0][0]needs to be inside the curly braces.
– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :Value of variable '@{Get_LocationId[0][0]}' is not list or list-like.I just relized I was using@instead of$Thanks for the answer, That works
– Wojtek T
Nov 7 at 16:17
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The query returns a list of lists - the outer list is a list of rows returned by the query, and the inner lists are lists of columns. This will be true even if the query returns a single column in a single row. You can use robot's embedded variable syntax to reference the value you want:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
Here is a complete that that illustrates the difference. I'm simulating the data in @{Get_LocationId} so that the test doesn't require an actual database connection.
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere
The query returns a list of lists - the outer list is a list of rows returned by the query, and the inner lists are lists of columns. This will be true even if the query returns a single column in a single row. You can use robot's embedded variable syntax to reference the value you want:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
Here is a complete that that illustrates the difference. I'm simulating the data in @{Get_LocationId} so that the test doesn't require an actual database connection.
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere
edited Nov 7 at 16:04
answered Nov 7 at 13:01
Bryan Oakley
208k21241402
208k21241402
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The[0][0]needs to be inside the curly braces.
– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :Value of variable '@{Get_LocationId[0][0]}' is not list or list-like.I just relized I was using@instead of$Thanks for the answer, That works
– Wojtek T
Nov 7 at 16:17
add a comment |
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The[0][0]needs to be inside the curly braces.
– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :Value of variable '@{Get_LocationId[0][0]}' is not list or list-like.I just relized I was using@instead of$Thanks for the answer, That works
– Wojtek T
Nov 7 at 16:17
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
I am getting this error now- 'locationId': ["The value '['somekindofIdhere'][0]' is not valid."]}
– Wojtek T
Nov 7 at 13:41
@WojtekT: my apologies. I messed up the variable reference. The
[0][0] needs to be inside the curly braces.– Bryan Oakley
Nov 7 at 15:57
@WojtekT: my apologies. I messed up the variable reference. The
[0][0] needs to be inside the curly braces.– Bryan Oakley
Nov 7 at 15:57
I have tried that previously and the error i was getting was :
Value of variable '@{Get_LocationId[0][0]}' is not list or list-like. I just relized I was using @ instead of $ Thanks for the answer, That works– Wojtek T
Nov 7 at 16:17
I have tried that previously and the error i was getting was :
Value of variable '@{Get_LocationId[0][0]}' is not list or list-like. I just relized I was using @ instead of $ Thanks for the answer, That works– Wojtek T
Nov 7 at 16:17
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188791%2frobot-framework-how-to-get-a-value-inside-a-list-of-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The used keyword
Queryis a custom keyword or one from an existing library?– A. Kootstra
Nov 7 at 12:46
I am using the DatabaseLibrary
– Wojtek T
Nov 7 at 13:40