如何使用自动化(机器人框架等)启动Chrome扩展程序 [英] How to launch Chrome Extension using Automation (Robot Framework, etc.)

查看:116
本文介绍了如何使用自动化(机器人框架等)启动Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在自动化中启动特定的chrome扩展程序.我目前在Java中使用Selenium.但是我无法启动chrome扩展程序.

I need to launch a particular chrome extension in my automation. I am currently using Selenium with Java. But I am unable to launch my chrome extension.

推荐答案

基本有两种方法.

1.在运行时安装所需的扩展程序- https://dev.到/razgandeanu/testing-chrome-extensions-with-selenium-491b

2..手动安装所需的扩展程序以执行现有的浏览器配置文件,并使用硒中的现有配置文件.像这样:

2. manualy install desired extension do existing browser profile and use the existing profile in selenium. Like this:

package packageName;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebdriverSetup {   
    public static String chromedriverPath = "C:\\Users\\pburgr\\Desktop\\selenium-tests\\GCH_driver\\chromedriver.exe";

    // my default profile folder
    public static String chromeProfilePath = "C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data";    

    public static WebDriver driver; 
    public static WebDriver startChromeWithCustomProfile() {
        System.setProperty("webdriver.chrome.driver", chromedriverPath);
        ChromeOptions options = new ChromeOptions();

        // loading Chrome with my existing profile instead of a temporary profile
        options.addArguments("user-data-dir=" + chromeProfilePath);

        driver = new ChromeDriver(options);
        driver.manage().window().maximize();
        return driver;
    }
    public static void shutdownChrome() {
        driver.close();
        driver.quit();
    }
}

这篇关于如何使用自动化(机器人框架等)启动Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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