Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
836 views
in Technique[技术] by (71.8m points)

robotframework - how to handle web based alert or pop ups in robot framework?

I am using Robot IDE for creating robot automation test scripts. For my test when I start audio call then browser is asking for the permission with "Allow" and "Block" buttons. So as it's a web based alert/popup dialog I can't able to access it in my robot script. If I am clicking on "Allow" button manually then it proceeds the test and passes successfully but I need to click it manually.

For Image, please click here

As you can see from the image I want to click on Allow button which is necessary to go ahead in my test.

So can anyone know how can I click on the "Allow" button of the browser confirmation popup via robot test script.

Thanks in advance!

My project structure is

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Chrome settings that drive this functionality can be viewed using the chrome://settings/. These settings are stored in the Chrome Profile. The path to this profile can be found using chrome://version/. In the preferences file a JSON structure of settings can be found.

In the below Robot Framework example the script opens Google and then clicks on the microphone icon to start the voice search. Under normal circumstances this results in a pop-up for microphone access.

The reason the assignment is split into two variables is because the url contains characters (. : //) that are considered separators. This is then overcome by creating that part of the structure manually: Create Dictionary https://www.google.nl:443,*=${SiteOptions}.

This then results in the desireable preference structure:

...
"profile":{
     ...
     "content_settings": {
         ...
         "exceptions": {
            ...
            "media_stream_mic":{
               "https://www.google.nl:443,*":{
                  "last_used":1492245954.955647,
                  "setting":1
               }
            },

Robot Script:

*** Settings ***
Library    Selenium2Library    

*** Test Cases ***

 Chrome With Preferences
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver

    &{SiteOptions}         Create Dictionary    last_used=${1470931206}     setting=${1}
    &{media_stream_mic}    Create Dictionary    https://www.google.nl:443,*=${SiteOptions}
    ${prefs}               Create Dictionary    profile.content_settings.exceptions.media_stream_mic=${media_stream_mic}

    Call Method    ${chrome_options}    add_experimental_option    prefs    ${prefs}

    Create WebDriver    Chrome    chrome_options=${chrome_options}

    Go To    https://google.com

    Click Link    css=#gs_st0 > a    # Click the search microphone icon.

    sleep     5s
    [Teardown]    Close Browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...