机械手框架-焦点/选择下拉菜单弹出窗口

时间:2018-07-05 12:10:26

标签: user-interface testing popup robotframework dropdown

我需要使用Robot Framework编写UI测试。我正在模拟用户在此网站https://www.cosmote.gr/hub/中的登录(在页面右上方选择英语)。用户应单击“登录/注册”,然后会出现一个弹出窗口:

popup window

我现在正在尝试在电子邮件文本字段以及密码字段中添加输入文本,然后按下按钮进行登录。由于我是Robot Framework的新手,所以我不知道如何聚焦于弹出窗口,因此我的测试失败了-它无法在弹出窗口中找到文本字段。

login example

我的代码是:

    *** Settings ***
Documentation    Present some information about this test suite
Library  Selenium2Library

*** Variables ***
${Browser} =  ff
${HOME_PAGE} =  https://www.cosmote.gr/hub/
${BUTTON_LOGIN} =  //*[@id="wcs_header"]/div[5]/div[1]/div[2]/div/div
${VALID_USERNAME} =  
${VALID_PASSWORD} =  
${PAGE_CONTAINS} =  My COSMOTE
${USERNAME_FIELD} =  //*[@id="loginIn"]
${PASSWORD_FIELD} =  //*[@id="pwdIn"]
${SUBMIT_BUTTON} =  //*[@id="loginBtnIn"]
${POPUP} =  //*[@id="cosid_md_login"]/div[2]
${FRAME} =  idmframeIn

*** Test Cases ***
User Login With Valid Credentials
    [Tags]  Login
    Open Browser  ${HOME_PAGE}  ${Browser}
    Wait Until Element Is Visible  ${BUTTON_LOGIN}
    Click Element  ${BUTTON_LOGIN}
    Wait Until Page Contains  ${PAGE_CONTAINS}
    Select Frame  id=${FRAME}
    Input text  ${USERNAME_FIELD}  ${VALID_USERNAME}
    Input password  ${PASSWORD_FIELD}  ${VALID_PASSWORD}
    Click Element  ${SUBMIT_BUTTON}
    Wait Until Page Contains  Hello
    Close Browser

如何聚焦/选择弹出窗口以查找文本字段和登录按钮元素?

在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

运行您的示例后,我注意到窗口没有扩展到最大大小。这可能会导致搜索栏和链接重叠。当我添加解决该特定问题的Maximize Browser Window关键字时。

由于Select Frame引起了问题,并且没有必要,请将其从脚本中删除。

以下脚本运行并填写值。由于用户名和密码无效,因此由于登录失败而无法通过最终检查。但是,这是预期的。

*** Settings ***
Documentation    Present some information about this test suite
Library  Selenium2Library

Suite Teardown    Close All Browsers

*** Variables ***
${Browser} =  chrome
${HOME_PAGE} =  https://www.cosmote.gr/hub/
# ${BUTTON_LOGIN} =  //*[@id="wcs_header"]/div[5]/div[1]/div[2]/div/div
${BUTTON_LOGIN} =  id=cosid_md_login
${VALID_USERNAME} =  dummy
${VALID_PASSWORD} =  dummy
${PAGE_CONTAINS} =  My COSMOTE
${USERNAME_FIELD} =  //*[@id="loginIn"]
${PASSWORD_FIELD} =  //*[@id="pwdIn"]
${SUBMIT_BUTTON} =  //*[@id="loginBtnIn"]
#${FRAME} =  idmframeIn

*** Test Cases ***
User Login With Valid Credentials
    [Tags]  Login
    Open Browser  ${HOME_PAGE}  ${Browser}
    Maximize Browser Window
    Wait Until Element Is Visible  ${BUTTON_LOGIN}
    Click Element  ${BUTTON_LOGIN}
    Wait Until Page Contains  ${PAGE_CONTAINS}
    # Select Frame  id=${FRAME}
    Input Text    ${USERNAME_FIELD}  ${VALID_USERNAME}
    Input password  ${PASSWORD_FIELD}  ${VALID_PASSWORD}
    Click Element  ${SUBMIT_BUTTON}
    Wait Until Page Contains  Hello
    Close Browser