Flip‐flop - daniel-qa/RobotFramework GitHub Wiki

Flip-flop

  • FlipFlopLibrary.py,实现状态机的逻辑:
class FlipFlopLibrary:
    def __init__(self):
        self.state = False

    def flip_state(self):
        self.state = not self.state

    def get_current_state(self):
        return str(self.state).lower()  # 返回状态,并转换为小写字符串以匹配 Robot Framework 的格式

my.robot

*** Settings ***
Library    FlipFlopLibrary.py

*** Test Cases ***
Test Flip-Flop State Transition
    Flip State And Verify
    Flip State And Verify Again

*** Keywords ***
Flip State And Verify
    Flip State
    ${current_state} =    Get Current State
    Should Be Equal As Strings    ${current_state}    "true"    # 验证当前状态是True

Flip State And Verify Again
    Flip State
    ${current_state} =    Get Current State
    Should Be Equal As Strings    ${current_state}    "false"   # 验证当前状态是False