2016-05-10 32 views
1

有人可以告訴我什麼在下面的代碼中是錯誤的。我試圖用隨機生成的字符串輸入文本。當我使用沒有selenium2library時它工作正常。任何幫助,將不勝感激。將隨機生成的字符串存儲爲變量,並將其傳遞給使用selenium2library輸入文本

Keywords.txt 

***Settings*** 
Library Selenium2Library 
Library  String 


*** Variables *** 

${URL}     https://www.google.co.in/ 
${Browser}    Chrome 
${RandomString}   Generate Random String 10 [LETTERS] 

*** Keywords *** 

Google Input Random String 
    Open Browser ${URL}  ${Browser} 
    Input Text  //*[@id='lst-ib'] ${RandomString} 
    Close Browser 

Execute.txt 

*** settings *** 
Library Selenium2Library 
Resource   Google_Test_Keywords.txt 


*** Test Cases *** 


Google Random String Search 
    Google Input Random String 
+0

Madhu,如​​果我的解決方案適合您,請將答案標爲正確。 – jim

回答

3

不能在變量定義塊(*** Variables ***)中使用關鍵字。

相反,填充隨機變量或者您的關鍵字裏面:

*** Keywords *** 
Google Input Random String 
    ${RandomString}=   Generate Random String 10 [LETTERS] 
    Open Browser ${URL}  ${Browser} 
    Input Text  //*[@id='lst-ib'] ${RandomString} 
    Close Browser 

或者作爲測試用例的一部分:

*** Test Cases *** 
Google Random String Search 
    ${RandomString}=   Generate Random String 10 [LETTERS] 
    Google Input ${RandomString} 

您還可以使用setups

+0

謝謝你jim。它的作品 – Madhu

+1

我建議用_「can not」_改變「_should not_」(即:「你不能在變量定義塊中使用關鍵字」 –

+0

謝謝,Bryan。 – jim

相關問題