How to assign SQL query results to a variable(Robot Framework) to input in application edit text?

六月ゝ 毕业季﹏ 提交于 2020-01-30 06:41:27

问题


Using MySQL and Robot Framework combination along with robot database library and pymysql library.

Connecting Database
Connect to database                         pymysql  ${DB_NAME}  ${DB_USER_NAME}  ${DB_USER_PASSWORD}  ${DB_HOST}  ${DB_PORT}
Sleep                                       ${wait_time}
Log to console                              Database Connection is established successfully!

And able to fetch the DB table data and printed on IDE console. Problem is that not able to assign query results to a robot variable to input for an edit-text inside the application.

${queryResult1}                             QUERY  SELECT COLUMN1 FROM  ${TABLE_NAME};
${query_results}                            Selenium2Library.Get Text  ${queryResult1}
Log to Console                              ${query_results}

Application Script

Sleep                               5s
Selenium2Library.Input Text                          ${username}     ${query_results}}
Sleep                               5s
Selenium2Library.Input Text                          ${password}     ${query_results}}
Sleep                               5s
Selenium2Library.Click element                       ${login_button}

回答1:


The return value of a query in the database library is a list of tuples - each list member is a response row, and the tuple is the column values in it.
When you used queryResult1 in the keywords you were actually using this two-dimensional object - not the text in the database, as you might have expected.

To get the value you're after you have to "unpack" the object; presuming you want to get the first column from the first row, that is the simplest approach:

${DB value}=    Set Variable    ${queryResult1[0][0]}

The first index is the row number, the second - the column; the indices are zero-based.

Then you can use ${DB value} in the follow-up keywords.



来源:https://stackoverflow.com/questions/54705917/how-to-assign-sql-query-results-to-a-variablerobot-framework-to-input-in-appli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!