使用 Robot Framework 时如何访问类中的方法? [英] How do I gain access to the methods in a class when using Robot Framework?

查看:61
本文介绍了使用 Robot Framework 时如何访问类中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Robot Framework 并构建测试.我在访问 python 文件中的类方法时遇到问题.我收到此错误消息

I am using Robot Framework and building tests. I am having issues accessing the class methods inside my python file. I receive this error message

==============================================================================
Test temperature setpoint change response                             | FAIL |
No keyword with name 'setpoint_change' found.
------------------------------------------------------------------------------

据我从文档中了解到,这应该可行

From what I understand from the documentation this should work

机器人文件

*** Settings ***
Library    Integration


*** Keywords ***
Confirm Temperature Setpoint Can Be Changed
    setpoint_change



*** Test Cases ***
Test temperature setpoint change response
    Confirm Temperature Setpoint Can Be Changed

Python 文件 Integration.py

Python File Integration.py

class Integration(object):
    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

    def setpoint_change(self):
        print('stuff is happening..')

如果我在静态函数的上下文中使用它,它将起作用,以便告诉我我的路径是正确的并且逻辑在那里,但是从类内部访问时出现问题.

if I use this in the context of a static function it will work so that tells me my paths are correct and the logic is there, but something is going wrong with accessing from within a class.

从我看来这应该可行,文档中提到如果文件名与类名相同,那么在我的情况下,一个简单的集成就足够了 - 我已经尝试了两种方式(Integration.Integration 文件和类名) 以及 ( Integration ) 并且无法成功访问类方法.

From what I see this should work, it's mentioned in the documentation that if the filename is the same as the class name a simple Integration in my case would suffice - I have tried it both ways as in (Integration.Integration file and class name) along with just ( Integration ) and was not able to successfully access the class methods.

从其他示例中我看到哪些更老,使用了可以使用 robots.api import 关键字访问的关键字装饰器,我还没有在现代帖子中看到它的实现,请告诉我我要去哪里错在这里,谢谢.

From other examples I see which are much older, there is the use of a keyword decorator that's accessible using robot.api import keyword which I have yet to see implemented in a modern post, kindly let me know where I'm going wrong here, thanks.

推荐答案

好的,找到了.好傻..

Alright, found it. So silly..

*** Settings ***

Library  Integration.py

*** Keywords ***
Confirm Temperature Setpoint Can Be Changed
    setpoint_change

*** Test Cases ***

 Test temperature setpoint change response
    Confirm Temperature Setpoint Can Be Changed

对于下一个人..请确保并特别注意间距方案另外我必须包含我真的认为我没有的文件扩展名类型(.py),它现在可以导入我的类并执行它可以访问方法以及定义的python 类中没有的内容

For the next person.. please be sure and pay extra attention to the spacing scheme Also I had to include the file extension type (.py) which I really thought I did not, it now can import my class and do it's thing and have access to the methods and what not within the python class that's defined

这篇关于使用 Robot Framework 时如何访问类中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆