无法在RobotFram存储变量值

2024-09-30 05:22:16 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,我们有:

Get ticket value
        Wait Until Element is Visible    ${ticketDescription}
        ${ticketDescValue}=    Execute Javascript    return window.document.querySelector('p[class*="ticket-description"]').innerHTML.toString()


Verify if ticket value matches
       Element Text Should Be    ${some_locator}    ${ticketDescValue}

其中,${ticketDescValue}将是预期的文本

测试用例示例:

^{pr2}$

有没有办法在现有关键字之间共享变量? 在Java中,我可以使用getter和setter来处理这个问题。 或者发送参数到方法等。。。在

如何使用Robot框架实现它?在


Tags: executegetreturnisvalueelementjavascriptwindow
2条回答

更好的方法是修改您的Get ticket value关键字以返回参数,并修改您的Verify if ticket value matches关键字以票据值作为参数。这样就不需要使用全局变量。在

Get ticket value
    Wait Until Element is Visible    ${ticketDescription}
    ${ticketDescValue}=    Execute Javascript    return window.document.querySelector('p[class*="ticket-description"]').innerHTML.toString()
    [Return]    ${ticketDescValue}

Verify if ticket value matches
   [Arguments]    ${value}
   Element Text Should Be    ${some_locator}    ${value}

那么你的测试应该是这样的:

^{pr2}$

我把所有的参数名都改为不同的,以强调它们不一定都是相同的——但是如果你愿意,你可以让它们都一样。在

您需要在赋值行后使用类似于下面的内容将变量值设置为全局变量或套件变量:

 Set Suite Variable    ${ticketDescValue}

或者,可以从第一个关键字返回变量,并将其作为参数传递到第二个关键字

相关问题 更多 >

    热门问题