Robot Framework is returning u' in front of the string when doing a query statemet

4,451 views
Skip to first unread message

Mike Lin

unread,
Mar 24, 2014, 11:56:38 AM3/24/14
to robotframe...@googlegroups.com

Hi Everyone,

I am using the following environment. They are all windows 32 bit version.

Python 2.7.6

RobotFramework 2.8.4

Selenium2Library

WxPython 2.8

 

Robot Framework is returning an incorrect query when the column is a varchar.

This is the code that I have:

    ${importpath}    Query    ${query_statement}

The query statement is only returning one row.

It is returning “u’” at the front. Here is what I get when I query in robot framework.

[(u'\\\\server_name\\primary\\database_name\\ImportFolders\\51',)]

I have tried putting the variable ${importpath} as a list by using the “Create List” keyword. The result is still the same.

The u’ at the beginning of the query should not be there. Can anyone provide a feedback at why robotframework is returning a u’ in front of the query?

Thanks for the assistance,

Mike

Laurent Bristiel

unread,
Mar 25, 2014, 4:04:47 AM3/25/14
to robotframe...@googlegroups.com
Hello,

the little u means that your string is Unicode.
See http://stackoverflow.com/a/11279428/1826804

You can ignore it and should be able to use your string in the next step.
Or does it really cause a problem for you?

Laurent Bristiel

Kevin O.

unread,
Mar 25, 2014, 10:50:12 AM3/25/14
to robotframe...@googlegroups.com
I agree with Laurent's assessment. If you want just the path, extract the contents of the string out of the query results like this:

${importpath}
    Query    ${query_statement}
${importpath}    Set Variable    ${importpath[0][0]}

Mike Lin

unread,
Mar 25, 2014, 7:17:32 PM3/25/14
to robotframe...@googlegroups.com
Hi Kevin,

Thanks for the reply. I have few more questions with the [0][0].

I was able to extract the contents without the little u and among other stuff that robot framework returns when doing a query with the following statements:

${importpath}    Query    ${query_statement}

${importpath}    Set Variable    ${importpath[0][0]}

 

The statement above worked perfectly. I try using the same code on a “list” since some queries returned multiple rows and it doesn’t work so well

@{importID }     Create list           

@{ImportID}      Query   ${query_statement}

${importID}        Set Variable        ${importID[0][0]}

 

I play around with it and I had to use the FOR loop to make it work

 

@{ importID }    Create list                           

@{ importID }    Query   ${query_statement}

:FOR      ${value}               IN           @{ importID }

                ${value}               Set Variable        ${value[0]}

                Should not contain          ${value}               ${empty}

 

Any reason why I have to use only one [0] instead of [0][0] in order to make it work?



Florian Heine

unread,
Mar 26, 2014, 4:37:01 AM3/26/14
to robotframe...@googlegroups.com
Mike,

The Query keyword returns an Array of Arrays. Every row returned from the database is an array with every column represented as an entry in the array. What you get back looks something like this:

((row 0 col 0, row 0 col 1, row 0 col 2),
 (row 1 col 0, row 1 col 1, row 1 col 2),
 (row 2 col 0, row 2 col 1, row 2 col 2))

data[0][0] returns the FIRST column of the FIRST row: row 0 col 0
data[0] returns an ALL the columns for the FIRST row as an array: (row 0 col 0, row 0 col 1, row 0 col 2)

Because the query keyword doesn't know how much data is being returned, it does this even if only one column in one row is returned.

Hope that this makes it clearer.

     Florian

Kevin O.

unread,
Mar 26, 2014, 9:36:06 AM3/26/14
to robotframe...@googlegroups.com
Thanks for explaining that Florian. I should have not been so terse. One small correction - Query returns a list of tuples, which is array-like (and two-dimensional).

Unfortunately there is no standard keyword or keyword in database library for extracting columnar data. For larger data sets, I have transformed the query results from Query in a library keyword (Python, etc.).
This enhancement request seems to have fallen to the side:

Kevin

Mike Lin

unread,
Mar 26, 2014, 11:59:56 AM3/26/14
to robotframe...@googlegroups.com
Florian and Kevin,

Thank you for assisting me in this manner. Your replies truly help all of us (the QA team).

Regards,
Mike

Shailaja(Riya)

unread,
Jul 10, 2017, 7:31:49 AM7/10/17
to robotframework-users
Hi Mark,

I am also facing same issue,

For me requirement is ,

I have python method which accepts the list and in method definition I am creating string out of list items,

string1=repr(','.join(list)
some more statements to operate on string1

and return the value.


I am seeing when i pass the list it pass u' also with the list because of this u' character my scripts are getting failed.

Could you please redirect me to correct one?

I tried with ${list[0][o]} , it fetches first character of first list item.

Tatu Aalto

unread,
Jul 11, 2017, 11:41:32 AM7/11/17
to shailaj...@gmail.com, robotframework-users
Ugh

In the original post there was a list which did contain a tuple (tuple is immutable list). And when taking the first item from the list and from the tuple, the correct string can be accessed for verification.

But your problem seems like a different problem, although it involves unicode characters. Could you describe your problem more deeply, perhaps even with simple and runnable examples? After this we might be able to help you better.

-Tatu
Send from my mobile

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Riya

unread,
Jul 12, 2017, 6:40:39 AM7/12/17
to robotframework-users

Hello,

Attached test file (python and robot)

After running the output i get is :


Starting test: Robot With Backend.Test.Test Suite.test
20170712 16:03:35.401 :  INFO : hello
20170712 16:03:35.402 :  INFO : @{rcpt_list} = [ a...@b.com | c...@d.com ]
20170712 16:03:35.403 :  INFO : [u'a...@b.com', u'c...@d.com']
Ending test:   Robot With Backend.Test.Test Suite.test

****

One solution to get rid from u' is by converting list elements into string at python code ( which i have done and its working)

There are a lot of python scripts i am going use in my project , i dont want to go each file and convert the input into string, I am looking for solution from robot script, can i make any changes/ use any keyword to get rid from above problem.
To post to this group, send email to robotframe...@googlegroups.com.
test_suite.robot
test.py

Tatu Aalto

unread,
Aug 6, 2017, 5:18:45 AM8/6/17
to Shailaja Patil, robotframework-users
Ugh

Sorry for long delay, but here is the answer.

If your need was to create a string which looks like this ${SPACE}--to a...@b.com,c...@d.com${SPACE} in Robot Framework data, then the attachments will explain how that can be done. As was said earlier, the "u" in front of the string can be ignored because in Python 2 it means unicode[1]. The log did confuse you because you did print the rcpt_list argument in  you keyword and when printed out, did does contains the indication of the unicode (by addinf u in front of the starting quote). But you had returned the string, then you would have noticed that string was correctly created in your keyword. 

I did refactor you code little bit and removed the not required methods and logging. Most likely the readability did suffer a little bit, but in any case happy testing. 

-Tatu 

To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsubscrib...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
test.py
test_suite.robot
Reply all
Reply to author
Forward
0 new messages