简体   繁体   中英

How to trigger multiple chrome instances in parallel using different chrome profiles C#, selenium webdriver

I have the next requirement:

Execute multiple instances(parallel) with using different chrome profile. I have 3 profiles: profile1, profile2 and profile3

When I create the driver i add the path of the profile1

For running in parallel, how can I tell to the second instance that use the profile 2

I found this, i can't figure out how to execute in parallel.(I'm using Nunit for parallel execution)

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

Good Q. Working on same myself. To point Selenium to correct profile, so far I have the following (not complete - but part way; think there is better way; I can't open to drivers with same executable path, but can define multiple chrome drivers that pt. to same executable and then add arguments with separate profiles to each of those...(I'm using Python, you'll need to find out equivalent for Java).

from selenium import webdriver from selenium.webdriver.chrome.webdriver import WebDriver

Options = webdriver.ChromeOptions() Profile_Path = "C:/Users//AppData/Local/Google/Chrome/User Data/Profile/" '''ie relevant path to profile in question''' Options.add_argument('--user-data-dir=' + Profile_Path)

'''I'm experimenting with the map function to pass list of chromedrivers to a function with a loop that does something like this:'''

def SetUp(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], options=v_options[i])

That's as far as I am - good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM