python - 如何使用 python 比较机器人框架的数据输出

标签 python robotframework

这是我的机器人代码

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}

最佳答案

机器人框架是用 Python 编写的,这提供了许多很好的入口点。

您必须做出要使用的设计决策(或确定您的团队已经做出的设计决策)。

机器人原生解决方案

如果系统中两个表的结果是相同的,您也许可以直接使用内置的 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}

机器人调用Python解决方案

如果您希望Robot驱动Python,即调用robot作为主要入口点,您可以使用Library关键字导入Python模块。

机器人测试用例:

*** 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 库 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

Python调用Robot解决方案

如果你想让Python驱动Robot,你可以从Python访问API https://robot-framework.readthedocs.io/en/latest/

上面是一些直接相关的 stub ,希望能让您看到映射并开始工作。使用这个起点,我建议仔细阅读文档链接以进行后续步骤。

关于python - 如何使用 python 比较机器人框架的数据输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54068251/

相关文章:

Python并行执行——如何高效调试?

python - 为什么 `is` 对相同的实例方法和类方法返回 False,但对静态方法返回 True

python - 错误: TypeError: argument 1 must be a string or unicode object

python - 如何将变量文件路径传递给位于 PYTHONPATH 上的 Robot Framework?

python - Robot 的 Telnet 库是如何工作的?

testing - 如何按特定顺序在 robotframework 中执行 TEST SUITES?

python - Robotframework - 监听器中的 fatal error 应结束套件运行

python - django - 如何在模板中插入上传文件的内容?

python - 如何确定 numpy 数组 reshape 策略

python - 如何计算元素的值(value)?