[英]How can i compare data output from robot framework by using python
here's my robot code这是我的机器人代码
Database-Keywords-Test
connect to database using custom params cx_Oracle ${DB_CONNECT_STRING}
${queryResults}= Query Select * from QA_USER.SealTest_Security_A order by SECURITY_ID
Log ${queryResults}
${queryResults1}= Query Select * from QA_USER.SealTest_Security_B order by SECURITY_ID
Log ${queryResults1}
The Robot Framework is written in Python, which makes for a number of good entry points. Robot Framework 是用 Python 编写的,它提供了许多很好的切入点。
You have to make a design decision (or determine the design decision already made by your team) around which to use.您必须围绕要使用的设计决策(或确定您的团队已经做出的设计决策)。
Robot native solution机器人原生解决方案
If the results from the two tables in your system are meant to be identical, you might be able to just use a built-in Robot framework keyword directly and not call out to Python at all.如果您系统中两个表的结果是相同的,您也许可以直接使用内置的 Robot 框架关键字,而根本不调用 Python。
*** Settings ***
Documentation Exercise database keywords (Robot-only).
Library Collections
Library # <Database library implied above>
*** Test Cases ***
User Settings Test
[Documentation] User details db comparison (Database-Keywords-Test)
${queryResultsA}= Query Select * from QA_USER.SealTest_Security_A order by SECURITY_ID
${queryResultsB}= Query Select * from QA_USER.SealTest_Security_B order by SECURITY_ID
Lists Should Be Equal ${queryResultsA} ${queryResultsB}
Robot invoking Python solution机器人调用Python解决方案
If you want Robot to drive Python, ie you invoke robot as the main entry point, you can import Python modules using the Library keyword.如果想让Robot 驱动Python,即调用robot 作为主要入口点,可以使用Library 关键字导入Python 模块。
Robot test case:机器人测试案例:
*** Settings ***
Documentation Exercise database keywords (call out to Python).
Library userManagement
Library # <Database library implied above>
*** Test Cases ***
User Settings Test
[Documentation] User details db comparison (Database-Keywords-Test)
${queryResultsA}= Query Select * from QA_USER.SealTest_Security_A order by SECURITY_ID
${queryResultsB}= Query Select * from QA_USER.SealTest_Security_B order by SECURITY_ID
${diff} = Compare Users ${userResultsA} ${userResultsB}
Should Be Empty ${diff}
Python library userManagement.py: Python 库 userManagement.py:
class UserManagement:
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
def compareUsers(self,userResultsA,userResultsB):
# diff implementation depends on the structure of user results
# which are not shared in the question, but will be related to the
# database library you are using, perhaps a list of
# rows or dictionaries
...
return diff
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-library-class-or-module http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-library-class-or-module
Python invoking Robot solution Python调用Robot解决方案
If you want python to drive Robot, you can access the API from Python https://robot-framework.readthedocs.io/en/latest/如果你想让python驱动Robot,你可以从Python访问API https://robot-framework.readthedocs.io/en/latest/
The above are some directly related stubs that hopefully let you see the mapping and get off the ground.以上是一些直接相关的存根,希望能让您看到映射并开始工作。 Using that starting point, I suggest working through the documentation links carefully for next steps.
使用该起点,我建议仔细阅读文档链接以进行后续步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.