簡體   English   中英

如何在 Robot Framework 中從同一個 python 文件中導入兩個不同類的方法?

[英]How to import the methods of two different classes from the same python file in the Robot Framework?

我的 python 文件 di.py 中有兩個不同的類。 我需要導入它們並在機器人文件中使用它們。 你能指導我解決這個問題嗎? 我的 Python 文件:di.py

import time

class di:
    ROBOT_LIBRARY_SCOPE = 'TEST CASE'
    
    def init(self):
       print("*****Initialization Complete*****")

    def read(self):
        display = "Read Complete"
        return display
        print(display)


class Example:
    ROBOT_LIBRARY_SCOPE = 'TEST CASE'
    counter = time.gmtime()

    def county(self):
        print(self.counter)
        return self.counter

    def clear_counter(self):
        self.counter = 0
        print(self.counter)

如何使用機器人文件中的類的方法。 我的機器人文件就像

    *** Settings ***
    Library     Test.di
    Library     Test.Example

    *** Test Cases ***
    Test Read
        [Documentation]  Reads the DI value
        [Tags]  DI Read
        init
        ${var}  read    
        ${var}  clear counter

調試時出現導入錯誤。 你能幫我一下嗎。 非常感謝。

庫導入不正確。 當您有一個包含多個庫類的 Python 文件時,庫導入模式應如下所示:

Library    <PYTHON_FILE_NAME>.<CLASS_NAME>

您的導入沒有遵循它,看起來您擁有機器人文件名而不是 Python 文件名。

Library     Test.di
Library     Test.Example

如果我們應用該模式,正確的導入應該如下所示:

Library     di.di
Library     di.Example

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM