Reputation: 127
I have written some ATPs using Selenium Web Driver in C#. Currently I am using ChromeDriver to execute my scripts. But I want to take the driver information(like chrome, firefox...) dynamically from some source(like config file) and create driver object accordingly.
One way to do that is getting the driver information from config file and instantiating driver object accordingly using switch case...
Is there any other way to do that??
Thanks in advance.
Upvotes: 1
Views: 1728
Reputation: 2301
I have created the function for choosing the driver dynamically based on browser value from config file, using the Switch case that you suggested. I believe this is the only way to dynamically initialize driver locally.
In case, you want to create driver remotely, say on Saucelabs or Selenium Grid, there is a better approach than using the switch case. It can be initialized using the DesiredCapability object.
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(browserName); //browser value is dynamically taken
capability.setPlatform(platform);
capability.setVersion(version);
driver = new RemoteWebDriver(new URL(remoteURL),capability);
return driver;
Upvotes: 1