如何在机器人框架中处理基于网络的警报或弹出窗口? [英] how to handle web based alert or pop ups in robot framework?

查看:48
本文介绍了如何在机器人框架中处理基于网络的警报或弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Robot IDE 创建机器人自动化测试脚本.对于我的测试,当我开始音频通话时,浏览器会通过允许"和阻止"按钮请求许可.因此,由于它是基于 Web 的警报/弹出对话框,因此我无法在我的机器人脚本中访问它.如果我手动单击允许"按钮,则它会继续测试并成功通过,但我需要手动单击它.

解决方案

可以使用 chrome://settings/.这些设置存储在 Chrome 配置文件中.可以使用 chrome://version/ 找到此配置文件的路径.在 preferences 文件中可以找到设置的 JSON 结构.

在下面的机器人框架示例中,脚本打开谷歌,然后点击麦克风图标开始语音搜索.在正常情况下,这会导致弹出麦克风访问权限.

分配被分成两个变量的原因是因为 url 包含被视为分隔符的字符 (. ://).然后通过手动创建结构的那部分来克服这个问题:Create Dictionary https://www.google.nl:443,*=${SiteOptions}.

这会导致理想的偏好结构:

<代码>...轮廓":{...内容设置": {...例外":{...media_stream_mic":{"https://www.google.nl:443,*":{"last_used":1492245954.955647,设置":1}},

机器人脚本:

*** 设置 ***图书馆 Selenium2Library*** 测试用例 ***带首选项的 Chrome${chrome_options} = 评估 sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver&{SiteOptions} 创建字典 last_used=${1470931206} setting=${1}&{media_stream_mic} 创建字典 https://www.google.nl:443,*=${SiteOptions}${prefs} 创建字典 profile.content_settings.exceptions.media_stream_mic=${media_stream_mic}调用方法 ${chrome_options} add_experimental_option prefs ${prefs}创建 WebDriver Chrome chrome_options=${chrome_options}转到 https://google.com单击链接 css=#gs_st0 >a # 单击搜索麦克风图标.睡眠 5s[拆解] 关闭浏览器

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

解决方案

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

这篇关于如何在机器人框架中处理基于网络的警报或弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆