2016-11-03 1 views
3

원격 데이터에서 채워지는 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 

의도가 robotframework을 선택 마지막으로, "원격 데이터를로드"섹션의 선택 2 입력을 열고 "robotframework"를 입력하는 것입니다 : 여기

는 선택 2의 데모 페이지를 기반으로 테스트 케이스의 커플 목. 내가 그 일을 올바르게하는 방법을 알 수없는 것은 바로 그 최신 행동입니다. Robot Framework에서 얻은 결과는 다음과 같습니다.

$ 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 ?

그리고 단지 선택 2 기능을 사용하십시오.

+0

나는 오히려 CSS 셀렉터와 로봇 프레임 워크 키워드를 사용하십시오. JavaScript를 통해 select2를 트리거하는 것은 이런 종류의 테스트를하기에는 너무 낮은 수준입니다. 어쨌든 이것을 언급 해 주셔서 감사합니다. 나는 그것을 인식하지 못했으며 다른 상황에서 유용 할 수 있습니다. –

0

여기에가는 방법은 Click Element 키워드를 사용하는 것입니다. 첫 번째 테스트 케이스는 select2에 의해 동적으로 생성 된 id (select2-aiw0-results)에 의존하고 있었고 각 실행 중에는 다른 점 때문에 작동하지 않았습니다. 여기

선택 2 데모 페이지에 대해 작동하는 테스트 케이스

:

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