2015-07-20 89 views
1

我正面臨着與機器人硒庫添加自定義關鍵字的問題。我已經看到了一些用於添加自定義關鍵字的解決方案,但是這種方法似乎不適合我。在測試的情況下實現的是由CustomSeleniumLibrary.Get好Button.I指定的自定義關鍵字已張貼下面我用的代碼和我的測試用例: 自定義關鍵字實現Selenium2Library:Robot Framework,將自定義關鍵字與Selenium2Library集成

from Selenium2Library import Selenium2Library 


# create new class that inherits from Selenium2Library 
class CustomSeleniumLibrary(Selenium2Library): 
    # create a new keyword called "get webdriver instance" 
    def get_ok_button(self, locator): 
       element = self._get_checkbox(locator) 
       element.click() 

測試調用自定義關鍵字:

*** Settings *** 

Documentation A test suite containing tests related to invalid login. These 
...    tests are data-driven by they nature. They use a single 
...    keyword, specified with Test Template setting, that is called 
...    with different arguments to cover different scenarios. 

Resource  resource_one.txt 
Library   CustomSeleniumLibrary.py 
*** Variables *** 
${button_xpath} //button[@type='button']/span[text()=""'"Ok"'""]")) 
${message}  Please select one or more entries to unlock! 
${table_TO} //table[@id='userdetailTable']/tbody/tr/td 
${unlock_checkbox} //*[@id='userdetailTable']/tbody/tr/td[6]/input 
*** Test Cases *** 
Happy_Path_Unlock 
    Given a Intellix user is on the login page 
    When they enter their credentials 
    Attempt to Unlock an Valid TO User Id 
    Then they will see the TO User Id in the results list 

*** Keywords *** 
a Intellix user is on the login page 
    Selenium2Library.Open Browser ${url} ${BROWSER_CHROME} 

they enter their credentials 
    Selenium2Library.Input Text ${username_xpath} ${username_txt} 
    Selenium2Library.Input Password ${password_xpath} ${password_txt} 
    Selenium2Library.Click Button ${btn_submit} 

Attempt to Unlock an Valid TO User Id 
    Selenium2Library.Page Should Contain Link ${view_tab} ${view_tab_text} 
    Selenium2Library.Page Should Contain Link ${admin_tab} ${admin_tab_text} 
    Selenium2Library.Page Should Contain Link ${unlock_tab} ${unlock_tab_text} 
    Selenium2Library.Click Link ${unlock_tab} 
    Selenium2Library.Wait Until Element Is Visible ${TO_User_Id} 
    Selenium2Library.Click Element ${TO_User_Id} 
    Selenium2Library.Input Text ${TO_User_Id} teksmith 
    Selenium2Library.Click Button ${go_btn} 

they will see the TO User Id in the results list 
    Selenium2Library.Wait Until Page Contains Element ${unlock_checkbox} 
    CustomSeleniumLibrary.Get Ok Button     ${unlock_checkbox} 
    Selenium2Library.Close Window 

運行文件後,我收到以下錯誤:CaptureScreenshot失敗。它沒有給我一個特定的運行錯誤實現的python自定義關鍵字。反饋意見,如果我的實施將不勝感激!

回答

3

您的代碼示例沒有導入Selenium2Library的行,但您經常從那裏調用關鍵字。也許你忘了將它包含在你的示例中。

由於CustomSeleniumLibrary繼承自Selenium2Library,因此不需要指定Selenium2Library。嘗試刪除Selenium2Library導入和所有Selenium2Library和CustomSeleniumLibrary前綴。我認爲他們參考不同的瀏覽器實例。

我測試了你的自定義關鍵字,它工作正常:它失敗了,它應該會產生一個漂亮的截圖。

*** Settings *** 
Library   CustomSeleniumLibrary.py 
Suite Teardown Close All Browsers 

*** Test Cases *** 
Stackoverflow 
    Open Browser http://www.google.com/ Chrome 
    Page Should Contain Element btnK 
    Get Ok Button foo 
+0

非常感謝你佩卡!有效!!! –

相關問題