每当我运行自动化测试脚本时,Chrome扩展程序就会消失 [英] Chrome extension disappear every time i run my automation test script

查看:145
本文介绍了每当我运行自动化测试脚本时,Chrome扩展程序就会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Selenium Robot Framework测试Chrome扩展程序吗?

I need to test Chrome extension using Selenium Robot Framework?

扩展程序已安装在浏览器中,但是每次我运行测试脚本时它都会消失.

Extension is installed on the browser, but it disappears every time I run my test script.

任何人都可以告诉我在Selenium Robot Framework

Can anyone tell me the steps I need to follow in Selenium Robot Framework

推荐答案

有两种方法.您可以指示Chrome在启动时安装特定的扩展程序,也可以使用安装了扩展程序的永久配置文件.要获取扩展名的crx文件,请参见给我CRX .请参阅此帮助主题,以创建可在其中安装扩展程序的新配置文件. >

There are two approaches to this. You can instruct Chrome to install a specific extension on startup or you can use a persistent profile where an extension is installed. To get a crx file for an extension, see Give Me CRX. See this help topic on creating a new profile into which you can install an extension.

*** Settings ***
Test Teardown     Close All Browsers
Library           Selenium2Library

*** Test Cases ***
Install Extension On Startup
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_extension    C:\\ws\\extension_2_0_2.crx
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    1 minute    # manually verify the extension is active

Using Saved Profile
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_argument    user-data-dir\=C:\\ws\\User Data
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    1 minute    # manually verify the extension is active

user-data-dir后的'\'用来转义'=',因此Robot Framework不会将user-data-dir解释为关键字参数名称.

The '\' after user-data-dir is to escape the '=' so Robot Framework does not interpret user-data-dir as a keyword argument name.

有关硒的Chrome选项的帮助

有关创建Webdriver的帮助

这篇关于每当我运行自动化测试脚本时,Chrome扩展程序就会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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