簡體   English   中英

如何使用自動化(機器人框架等)啟動Chrome擴展程序

[英]How to launch Chrome Extension using Automation (Robot Framework, etc.)

我需要在自動化中啟動特定的chrome擴展。 我目前正在使用Selenium和Java。 但是我無法啟動Chrome擴展程序。

基本上有兩種方法。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM