2016-11-03 2 views
3

リモートデータから読み込まれたselect2ドロップダウンからプログラムで選択しようとしています。ここでRobot Frameworkを使用してリモートデータでselect2からアイテムを選択する

はSELECT2のデモページに基づいて、テストケースのカップルです:

*** Settings *** 
Library   Selenium2Library 

*** Variables *** 
${URL}  https://select2.github.io/examples.html 
${BROWSER}  Chrome 


*** Test Cases *** 

Test select2 input with click 
    Open browser ${URL} ${BROWSER} 
    Wait Until Page Contains Loading remote data 
    Click Element xpath=/html/body/div/div/div[1]/section[3]/p[4]/span 
    Input Text  xpath=/html/body/span/span/span[1]/input  robotframework 
    Wait Until Page Contains Generic test automation 
    Click Element xpath=//*[@id="select2-aiw0-results"]/li 


Test select2 input with select from 
    Open browser ${URL} ${BROWSER} 
    Wait Until Page Contains Loading remote data 
    Click Element xpath=/html/body/div/div/div[1]/section[3]/p[4]/span 
    Input Text  xpath=/html/body/span/span/span[1]/input  robotframework 
    Wait Until Page Contains Generic test automation 
    Select From List By Index xpath=/html/body/span   0 

意図は、「リモートデータのロード」からSELECT2入力を開く「robotframework」を入力し、最後にrobotframeworkを選択することです項目。それは私が正しく行う方法を理解することができない最新のアクションです。ここで私はロボットのフレームワークから取得出力は、次のとおりです。

$ robot select2.robot 
============================================================================== 
Select2                  
============================================================================== 
Test select2 input with click           | FAIL | 
ValueError: Element locator 'xpath=//*[@id="select2-aiw0-results"]/li' did not match any elements. 
------------------------------------------------------------------------------ 
Test select2 input with select from         | FAIL | 
ValueError: Element locator 'xpath=/html/body/span' did not match any elements. 
------------------------------------------------------------------------------ 
Select2                | FAIL | 
2 critical tests, 0 passed, 2 failed 
2 tests total, 0 passed, 2 failed 
============================================================================== 
Output: /home/al/essai/robotframework/output.xml 
Log:  /home/al/essai/robotframework/log.html 
Report: /home/al/essai/robotframework/report.html 

私はChromeとFirefoxで同じ結果を得ます。

答えて

1

Maybe with Javascript ?

そして、ちょうどSELECT2関数を使用します。

+0

私はむしろCSSセレクタでロボットFrameworkのキーワードを使用すると思います。 JavaScriptを使用してselect2をトリガーすると、この種のテストではレベルが低すぎます。とにかくこれに言及してくれてありがとう、私はそれを認識していなかったし、別の状況で便利になる可能性があります。 –

0

ここに行く方法は、Click Elementキーワードを使用することです。私の最初のテストケースは、select2によって動的に生成されたid(select2-aiw0-results)に依存していたため、各実行中に異なるものでした。ここで

SELECT2のデモページに不利に働くテストケース

*** Settings *** 
Library   Selenium2Library 

*** Variables *** 
${URL}  https://select2.github.io/examples.html 
${BROWSER}  Chrome 


*** Test Cases *** 

Test select2 input with click 
    Open browser ${URL} ${BROWSER} 
    Wait Until Page Contains Loading remote data 
    # Click on the input 
    Click Element xpath=/html/body/div/div/div[1]/section[3]/p[4]/span 
    # Enter text to trigger autocompletion 
    Input Text  xpath=/html/body/span/span/span[1]/input  robotframework 
    Wait Until Page Contains Generic test automation 
    # Select the first suggestion from the autocompletion list 
    Click Element css=.select2-results li:nth-child(1) 
    # Check that the input contains text corresponding to the selected item 
    Element Text Should Be css=body > .container section:nth-child(3) .js-example-data-ajax + .select2-container .select2-selection__rendered robotframework/robotframework 
    Close Browser 
関連する問題