如何使用不同的Chrome配置文件C#,硒webdriver并行触发多个chrome实例

问题描述 投票:1回答:1

我有下一个要求:

使用不同的Chrome配置文件执行多个实例(并行)。我有3个个人资料:profile1,profile2和profile3

[创建驱动程序时,我添加了profile1的路径

对于并行运行,如何告诉使用配置文件2的第二个实例

我发现了这个,我不知道如何并行执行。(我正在使用Nunit进行并行执行)

using the same chrome profile (session) for different ChromeDriver instances

public static IWebDriver GetDriver()
     {
        var options = new ChromeOptions();
        options.AddArguments("--noerrdialogs");
        options.AddArguments(@"user-data-dir=C:\Users\" + loggedInUser + @"\AppData\Local\Google\Chrome\profile1");
        return new ChromeDriver(options); 
      }
c# selenium-webdriver nunit
1个回答
0
投票

好问。我自己做同样的事情。为了将Selenium指向正确的配置文件,到目前为止,我有以下内容(不是完整的-只是部分原因;认为有更好的方法;我无法向具有相同可执行路径的驱动程序打开,但可以定义多个指向相同的chrome驱动程序可执行文件,然后向每个参数添加带有单独配置文件的参数...(我使用的是Python,您需要找出与Java等效的配置文件。)

来自selenium import webdriver从selenium.webdriver.chrome.webdriver导入WebDriver

选项= webdriver.ChromeOptions()Profile_Path =“ C:/用户// AppData /本地/ Google / Chrome /用户数据/配置文件/”'''即有关个人资料的相关路径'''Options.add_argument('-user-data-dir ='+ Profile_Path)

'''我正在尝试使用map函数,将chromedrivers列表传递给具有如下功能的带有循环的函数:'''

def设置(Number_Drivers):

v_profiles = []; v_options = []; v_chromedrivers =[]; v_drivers = []
profile_path = "C:/Users/..../User Data/Profile" 
'''put path of profile, noting this will become Profile1, Profile2, etc. below...'''

chromedrv_path = "C:/Users/... '''(i.e. path to chromedriver)'''
for i in range(Number_Drivers):
    v_profiles.append(profile_path + str(i) + "/")
    v_options.append(webdriver.ChromeOptions())
    v_chromedrivers.append(chromedrv_path)
    v_options[i].add_argument('--user-data-dir=' + v_profiles[i]



   ''' v_options[i].add_argument to be included for each other argument you want to 
       add, e.g. '--restore-last-session', '--disable-notifications', '--disable- 
       search-geolocation-disclosure' etc.)'''

v_drivers.append(webdriver.Chrome(executable_path = v_chromedrivers [i],选项= v_options [i])]] >>

就我而言-祝您好运!

© www.soinside.com 2019 - 2024. All rights reserved.