如何使用 selenium 工具测试我们的 chrome 扩展? [英] How to test our chrome extention with selenium tool?

查看:41
本文介绍了如何使用 selenium 工具测试我们的 chrome 扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个 Chrome 扩展,我想进行自动 Selenium 测试,以便对其进行测试.

I built a Chrome-extension, and I would like to make an automatic Selenium test, in order to test it.

这是我用java写的代码:

This is the code I wrote in java:

public static void main(String[] args) throws InterruptedException {

    WebDriver Driver = null;
    System.setProperty("webdriver.chrome.driver","chromedriver.exe");
    Driver = new ChromeDriver();
    ChromeOptions options = new ChromeOptions();
    options.addExtensions(new File("EXTENSTION-TRY_v1.crx"));

    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(options.CAPABILITY, options);
    Driver = new ChromeDriver(cap);

    //Driver.get("chrome-
      extension://gnenabaciggjinojhciofkkiphbmcinf/home.html");

但是每次我运行它时,我都会收到这个错误:

But everytime I ran it, I get this error:

对服务器的请求已被扩展程序阻止.尝试禁用您的扩展程序.ERR_BLOCKED_BY_CLIENT

Requests to the server have been blocked by an extension. Try disabling your extensions. ERR_BLOCKED_BY_CLIENT

AdBlock 已禁用.你知道我该如何解决这个问题吗?

AdBlock is disabled. Do you know how can I solve this issue?

谢谢

推荐答案

以下是我用于启动 ChromeDriver 的参数:

Here are the arguments I use for starting ChromeDriver:

Map<String, Object> options = new HashMap<String, Object>();
ArrayList<String> args = new ArrayList<String>();
args.add("enable-automation");
args.add("test-type=browser");
args.add("disable-plugins");
args.add("disable-infobars");
options.put("args", args);

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

这个答案中,我也有不同的加载扩展的方法.

I also have a different method for loading the extension in this answer.

这篇关于如何使用 selenium 工具测试我们的 chrome 扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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