简体   繁体   English

如何强制Robot Framework仅初始化一次我的自定义库

[英]How to force Robot Framework to initialize my custom library only once

I have created a custom library in Python that one of the functions in the __init__ module is self.create_new_folder() . 我已经在Python中创建了一个自定义库, __init__模块中的功能之一是self.create_new_folder()

Robot Framework initializes the library twice: Robot Framework将库初始化两次:

  • Once in the suite setup (I do not initialize the library myself, robot does it automatically). 一旦进入套件设置(我自己没有初始化库,机器人会自动完成)。

  • The second time it initializes the library is when it calls the first custom keyword from the custom library, and the test fails because the folder is already created. 第二次初始化库是从定制库调用第一个定制关键字时,测试已失败,因为已经创建了文件夹。

I can check if the folder already exists but I would like to know if there is a way to force Robot to initialize the library only once. 我可以检查该文件夹是否已经存在,但是我想知道是否有一种方法可以强制Robot只初始化一次库。

If you set ROBOT_LIBRARY_SCOPE to GLOBAL , the library will be instantiated exactly once for a test run. 如果将ROBOT_LIBRARY_SCOPE设置为GLOBAL ,则该库将被完全实例化一次以进行测试运行。

From the documentation: 从文档中:

GLOBAL - Only one instance is created during the whole test execution and it is shared by all test cases and test suites. 全局-在整个测试执行期间仅创建一个实例,并且所有测试用例和测试套件都共享该实例。 Libraries created from modules are always global. 从模块创建的库始终是全局的。

Example: 例:

class ExampleLibrary:

    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

See http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope 参见http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-scope

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Java自定义库添加到Robot Framework RIDE - How to add a Java custom library to Robot Framework RIDE 使用WITH NAME导入Robot Framework自定义库 - Robot Framework Custom Library Imports using WITH NAME 在 Robot Framework 中导入自定义测试库 - Importing custom testing library in Robot Framework Robot Framework自定义关键字仅在测试设置中 - Robot Framework custom keyword only in Test Setup 如何在Robot框架中使用Scapy库? - How to use Scapy library in Robot framework? 如何为“ Doubleclick”和“ find icon and type”为Robot Framework编写Python自定义库 <some text> “? - How to write Python custom library for Robot Framework for “doubleclick” and “find icon and type <some text>”? 如何将图像嵌入到用 python 编写的自定义库中的机器人框架日志文件中? - how to embed a image into robot framework log file from Custom Library written in python? 如何使用 Selenium2Library 在 Robot Framework 中向我的 chromedriver 添加扩展并远程启动 - How can I add an extension to my chromedriver at the Robot Framework with Selenium2Library and launch remotely 如何在Robot Framework中创建自定义测试用例设置 - How to create custom testcase settings in Robot Framework 将现有的Webdriver对象传递给Robot Framework的自定义Python库 - Pass existing Webdriver object to custom Python library for Robot Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM