如何将使用相同变量的两个 SeleniumLibrary 关键字组合成自定义关键字并在其他关键字中调用它?

How do I combine two SeleniumLibrary keywords that use the same variable into a custom keyword and call it in other keywords?

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

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

我有:

 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

你可以这样做:

***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}