【问题标题】:How to launch Chrome Extension using Automation (Robot Framework, etc.)如何使用自动化(机器人框架等)启动 Chrome 扩展程序
【发布时间】:2019-10-03 19:31:06
【问题描述】:

我需要在我的自动化中启动一个特定的 chrome 扩展。我目前正在将 Selenium 与 Java 一起使用。但我无法启动我的 chrome 扩展程序。

【问题讨论】:

标签: selenium google-chrome-extension automation robotframework


【解决方案1】:

基本上有两种方法。

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

2. 手动安装所需的扩展做现有的浏览器配置文件并使用 selenium 中的现有配置文件。像这样:

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();
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-09-26
  • 1970-01-01
  • 2019-03-06
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多