Robot framework, chrome new tab issue

无人久伴 提交于 2020-01-02 09:58:52

问题


I have a simple Robot Framework script

*** Settings ***
Documentation  Simple Amazon.in demo
Library  SeleniumLibrary

*** Variables ***
${MESSAGE}  Hello, World

*** Test Cases ***
User must sign in to check out
    [Documentation]  This is some basic info about the test
    [Tags]  Smoke
    Open Browser  http://www.amazon.in  chrome
    Input text  id=twotabsearchtextbox  Ferrari 458
    Click Button  xpath=//div[@class='nav-search-submit nav-sprite']/input[@class='nav-input' and 1]
    Wait until page Contains  results for "Ferrari 458"
    Click Link  css=#result_0 a.s-access-detail-page
    Wait until Page Contains  Back to search results for "Ferrari 458"
    Click Button  id=add-to-cart-button
    Wait Until Page Contains  1 item added to Cart

But whenever chrome reaches Click Link css=#result_0 a.s-access-detail-page it opens a new tab, and my robot script fails. How can I rectify it. Please help


回答1:


You can use the select window keyword and Get Window Titles keyword to navigate between them Get Window Titles keyword will return a list of titles the last index in that list is the new tab that has been opened, to access it from the list you can do the following ${Tabs[1]} (as in this code there is only 2 values in the list)

*** Settings ***
Documentation  Simple Amazon.in demo
Library  SeleniumLibrary

*** Variables ***
${MESSAGE}  Hello, World

*** Test Cases ***
User must sign in to check out
    [Documentation]  This is some basic info about the test
    [Tags]  Smoke
    Open Browser  http://www.amazon.in  chrome
    Input text  id=twotabsearchtextbox  Ferrari 458
    Click Button  xpath=//div[@class='nav-search-submit nav-sprite']/input[@class='nav-input' and 1]
    Wait until page Contains  results for "Ferrari 458"
    Click Link  css=#result_0 a.s-access-detail-page
    ${Tabs} =   Get Window Titles
    select window  title=${Tabs[1]}
    Wait until Page Contains  Back to search results for "Ferrari 458"
    Click Button  id=add-to-cart-button
    # Wait Until Page Contains  1 item added to Cart
    Wait Until Page Contains  Added to Cart

Results:

==============================================================================
Amazon :: Simple Amazon.in demo
==============================================================================
User must sign in to check out :: This is some basic info about th...
DevTools listening on ws://127.0.0.1:29864/devtools/browser/75b8be3c-6e76-474f-b391-d340fb322895
User must sign in to check out :: This is some basic info about th... | PASS |
------------------------------------------------------------------------------
Amazon :: Simple Amazon.in demo                                       | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  C:\development\robot-scripts\sssss\output.xml
Log:     C:\development\robot-scripts\sssss\log.html
Report:  C:\development\robot-scripts\sssss\report.html

I changed the last line of your code as it wasn't a valid text. See the comment in the code.



来源:https://stackoverflow.com/questions/53682332/robot-framework-chrome-new-tab-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!