如何在Robot Framework Automation中(通过命令行)将值(任何变量)传递到搜索框(Google)



下面给出了我的代码。。。注意:这是一个简单的谷歌搜索程序。

*** settings ***  
Library   SeleniumLibrary
*** Variables ***  
${browser}    Chrome  
${url}    https://google.com
*** Test Cases ***  
Google Index    
Go To google
*** Keywords ***  
Go To google  

open browser   ${url}    ${browser}
Wait Until Element Is Visible    //input[@title='Search']        60
Capture Page Screenshot
Wait Until Element Is Visible    //input[@title='Search']    50
Capture Page Screenshot
Press Keys   //input[@title='Search']    ***Hello_World***
Capture Page Screenshot
Press Keys   None   RETURN
Capture Page Screenshot
Sleep  2s
Wait Until Element Is Visible    //a[@id='logo']    25
Close browser

上述代码运行良好。但是我需要更改值(Hello_World(,我需要用一个可以在运行robot文件时传递的值来替换这个值。

我浏览了一些网站,但什么都找不到。

您可以通过--variable选项在命令行上传递变量的定义。

首先,将测试用例修改为如下所示:

Go To google    
...
Press Keys   //input[@title='Search']    ${search_string}
...

接下来,在命令行上将搜索字符串作为参数传递:

$ robot --variable search_string:Hello_World

相关内容

最新更新