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?










share|improve this question
























  • 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















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?










share|improve this question
























  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 16:21

























asked Nov 7 at 11:42









Wojtek T

968422




968422












  • 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


















  • 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
















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












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





share|improve this answer























  • 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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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





share|improve this answer























  • 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

















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





share|improve this answer























  • 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















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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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




















  • 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




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings