【问题标题】:How do I combine two SeleniumLibrary keywords that use the same variable into a custom keyword and call it in other keywords?如何将使用相同变量的两个 SeleniumLibrary 关键字组合成一个自定义关键字并在其他关键字中调用它?
【发布时间】:2019-12-16 23:51:17
【问题描述】:

我正在编写一些基本的自动化测试,我发现自己一遍又一遍地重复相同的两个关键字,我想知道是否有更简单的方法。

由于它们都使用相同的变量,我想创建另一个关键字,这样当我调用它以用于其他关键字时,我可以只写一行。

我有什么:

 Click Home Button
     Wait Until Element Is Visible     ${HOME_BUTTON}
     Click Button                      ${HOME_BUTTON}

我想要什么:

 Click Home Button
      Wait Until Visible And Click      ${HOME_BUTTON}

我想知道新关键字怎么写

 Wait Until Visible And Click

【问题讨论】:

    标签: python selenium robotframework ui-automation web-testing


    【解决方案1】:

    你可以这样做:

    ***Variables***
    ${HOME_BUTTON}  myVar
    
    ***Keywords***
    
      Wait Until Visible And Click
         [Arguments]  ${myvar}
         Wait Until Element Is Visible     ${myvar}
         Click Button                      ${myvar}
    
    ***Test cases***
    My Testcase1
      Wait Until Visible And Click  ${myvar1}
    
    
    My Testcase2
      Wait Until Visible And Click  ${myvar1}
    

    【讨论】:

    • 您好,感谢您的回复。但是,我希望能够将不同的参数传递给关键字 Wait Until Visible And Click,而不仅仅是 ${HOME_BUTTON} 变量,因此我可以在整个测试套件中使用它。如果不清楚,请道歉!
    • 我编辑了我之前的答案。我希望我确实理解正确 =)
    • 我认为很多人将这些自定义关键字放入他们自己的资源文件中。像 common.robot 这样的东西。 “等到可见并单击”、“等到元素可见并输入文本”等...
    猜你喜欢
    • 2019-10-31
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 2016-12-12
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多