I am trying to open multiple browsers in parallel, but I can not navigate to the website in more than one window..
Here is how I do it:
namespace XXX
{
public class CoreDriver
{
public IWebDriver driver;
public int my_port { get; set; }
public void Initialize()
{
string chromeee = "";
if (my_port == 50147) { chromeee = "C:/Users/AA/Downloads/chromedriver1/"; }
else if (my_port == 50148) {chromeee = "C:/Users/AA/Downloads/chromedriver2/"; }
else if (my_port == 50149) { chromeee = "C:/Users/AA/Downloads/chromedriver3/"; }
else if (my_port == 50140) { chromeee = "C:/Users/AA/Downloads/chromedriver4/"; }
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\AA\\AppData\\Local\\Google\\Chrome\\User Data");
var driverService = ChromeDriverService.CreateDefaultService(chromeee);
driverService.HideCommandPromptWindow = true;
driverService.Port = my_port;
driver = new ChromeDriver(driverService, options);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0,0,12));
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(13));
//driver navigate
}
}
}
calling it as this:
CoreDriver A1 = new CoreDriver();
A1.my_port = 50147;
A1.Initialize();
CoreDriver A2 = new CoreDriver();
A2.my_port = 50148;
A2.Initialize(); // timeout error here
// ...
Unfortunately, after the second window is opened - timeout error is shownn:
A first chance exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: The HTTP request to the remote WebDriver server for URL http:/loca1host:50148/session timed out after 60 seconds.
at this line:
driver = new ChromeDriver(driverService, options);
after rerunning the test with different parameters I have found out that the error is shown due to the specified Chrome profile:
options.AddArgument("user-data-dir=C:\\Users\\AA\\AppData\\Local\\Google\\Chrome\\User
Data");
If I remove the line - then all of my cookies will not be used in ChromeDriver instance and that is not something that I can live with :) Is there a way to use the same chrome profile in multiple chromedriver instances?
Okay, so I am using my approach as stated above.
My requirements were:
Here is the logic in few words.
And here is the code. You might want to tweak one thing or another.
Please note that I have also implemented a method to clean up all profiles
CleanUpOldProfiles
Review the code, make changes to directories etc. After done - make a following call:
sorry for a long answer. Hope it helps you guys somehow :)