简体   繁体   中英

How can I instantiate a Robotframework library class with a factory method?

I have a Java class which I want to import as a library in my robot file.

The problem is that this class is a singleton with a static method newInstance instead of ordinary public constructor.

Is there any way to tell RobotFramework to use newInstance instead of constructor to instantiate a library object?

Of course, I can use Call Method to get the desired "library" object and then again call its method, but this will disable all the magic and simplicity of direct using of library class methods as keywords. Making the class a non-singleton is not a solution in my case.

No, according to the user guide , it is not possible. But you can define the library's scope bysetting ROBOT_LIBRARY_SCOPE accordingly.

Maybe this helps:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM