Robotframework 如何在使用Robot框架运行自动测试时使浏览器允许通知消失

Robotframework 如何在使用Robot框架运行自动测试时使浏览器允许通知消失,robotframework,Robotframework,我不希望在运行自动脚本时出现“允许通知”弹出窗口,我尝试手动阻止它(在浏览器设置中阻止它)。浏览器是Firefox Test [Tags] Regression Open Excel ${Data.${ENV_DATA}} @{getCustInfor}= Get Sheet Values CardNo @{getMsg}= Get Sheet Values Messages Login.Login by username and password ${

我不希望在运行自动脚本时出现“允许通知”弹出窗口,我尝试手动阻止它(在浏览器设置中阻止它)。浏览器是Firefox

Test
[Tags]    Regression
Open Excel    ${Data.${ENV_DATA}}
@{getCustInfor}=    Get Sheet Values    CardNo
@{getMsg}=    Get Sheet Values    Messages
Login.Login by username and password    ${USER.${ENV}}    ${PASS.${ENV}}

该弹出窗口总是在完成登录页面后显示,它包含一些元素。

将firefox
dom.webnotifications.enabled的首选项设置为False。这将在通知中消失

在robot中,您可以通过创建一个函数来实现这一点

def create_profile(self):
    from selenium import webdriver
    fp=webdriver.FirefoxProfile()
    fp.set_preference("dom.webnotifications.enabled",False)
    fp.update_preferences()
    return fp.path
在.robot文件中添加以下代码:

${profile}=    create profile   
Open Browser    ${URL}    ${BROWSER}    ff_profile_dir=${profile}

将firefox
dom.webnotifications.enabled
的首选项设置为False。这将在通知中消失

在robot中,您可以通过创建一个函数来实现这一点

def create_profile(self):
    from selenium import webdriver
    fp=webdriver.FirefoxProfile()
    fp.set_preference("dom.webnotifications.enabled",False)
    fp.update_preferences()
    return fp.path
在.robot文件中添加以下代码:

${profile}=    create profile   
Open Browser    ${URL}    ${BROWSER}    ff_profile_dir=${profile}

我已经创建了一个函数.py,然后我将这些脚本输入到robot文件中,但是如何在create_profile关键字之后输入参数。您可以通过给参数标记ex->Login[arguments]${URL}${BROWSER}${profile}=create profile Open BROWSER${URL}${BROWSER}来传递参数ff_profile_dir=${profile}此处登录是一个以URL和浏览器作为参数的关键字。我得到错误关键字“NotificationsBlock.Create profile”应为1个参数,得到0。在您的函数中,必须在创建配置文件后添加一些内容。在创建配置文件函数中,尝试从itI中删除self。我已经创建了一个函数.py,然后我将这些脚本输入robot文件,但如何在创建配置文件关键字后输入参数。您可以通过提供参数标记ex->Login来传递参数[参数]${URL}${BROWSER}${profile}=创建配置文件打开浏览器${URL}${BROWSER}ff\u profile\u dir=${profile}此处登录是一个以URL和浏览器作为参数的关键字。我得到了错误关键字“NotificationsBlock.Create Profile”应为1个参数,但得到了0。在函数中,必须在创建配置文件后放置一些内容。在Create_Profile函数中,尝试从中删除self