public static IWebDriver GetDriverServer(StartSeWebDriverCommand cmdlet) { IWebDriver driver = null; var driverDirectoryPath = string.Empty; ChromeOptions chromeOptions = null; InternetExplorerOptions ieOptions = null; var commandTimeout = TimeSpan.FromSeconds(60.0); DriverService service = null; var listOfParameters = new System.Collections.Generic.List <Autofac.Core.Parameter>(); // determine the type of dirver server var driverServerType = DriverServers.None; var ieArchitecture = InternetExplorer.X86; // Drivers driverType = Drivers.HTML; // if (true == cmdlet.CH) { // cmdlet.WriteVerbose(cmdlet, "required ChromeDriver"); // driverServerType = DriverServers.chrome; // driverType = Drivers.Chrome; // } // if (true == cmdlet.IE) { // cmdlet.WriteVerbose(cmdlet, "required InternetExplorerDriver"); // driverServerType = DriverServers.ie; // ieArchitecture = cmdlet.Architecture; // driverType = Drivers.InternetExplorer; // } switch (cmdlet.DriverType) { case Drivers.Chrome: cmdlet.WriteVerbose(cmdlet, "required ChromeDriver"); driverServerType = DriverServers.Chrome; //driverType = Drivers.Chrome; break; case Drivers.Firefox: break; case Drivers.InternetExplorer: cmdlet.WriteVerbose(cmdlet, "required InternetExplorerDriver"); driverServerType = DriverServers.Ie; ieArchitecture = cmdlet.Architecture; //driverType = Drivers.InternetExplorer; break; case Drivers.Safari: break; case Drivers.Html: break; default: throw new Exception("Invalid value for Drivers"); } // collect processes before running the server cmdlet.WriteVerbose(cmdlet, "collect processes"); SeHelper.CollectDriverProcesses(cmdlet.DriverType); // driverDirectoryPath if (string.IsNullOrEmpty(cmdlet.DriverDirectoryPath)) { cmdlet.WriteVerbose(cmdlet, "using the default driver directory path"); driverDirectoryPath = System.IO.Path.GetDirectoryName(cmdlet.GetType().Assembly.Location); if (DriverServers.Ie == driverServerType && InternetExplorer.X86 == ieArchitecture) { driverDirectoryPath += "\\32\\"; } if (DriverServers.Ie == driverServerType && InternetExplorer.X64 == ieArchitecture) { driverDirectoryPath += "\\64\\"; } } else { cmdlet.WriteVerbose(cmdlet, "using the path from the cmdlet parameter"); driverDirectoryPath = cmdlet.DriverDirectoryPath; } cmdlet.WriteVerbose(cmdlet, driverDirectoryPath); // ChromeOptions, InternetExplorerOptions // try { if (DriverServers.Chrome == driverServerType) { if (null == cmdlet.ChromeOptions) { cmdlet.WriteVerbose(cmdlet, "using the default ChromeOptions"); chromeOptions = new ChromeOptions(); } else { cmdlet.WriteVerbose(cmdlet, "using the supplied ChromeOptions"); chromeOptions = cmdlet.ChromeOptions; } } if (DriverServers.Ie == driverServerType) { if (null == cmdlet.IeOptions) { cmdlet.WriteVerbose(cmdlet, "using the default InternetExplorerOptions"); ieOptions = new InternetExplorerOptions(); ieOptions.IgnoreZoomLevel = true; } else { cmdlet.WriteVerbose(cmdlet, "using the supplied InternetExplorerOptions"); ieOptions = cmdlet.IeOptions; } } // commandTimeout if (null != cmdlet.Timeout && 0 != cmdlet.Timeout && Preferences.Timeout != cmdlet.Timeout) // ?? { cmdlet.WriteVerbose(cmdlet, "setting the commandTimeout"); commandTimeout = TimeSpan.FromMilliseconds(cmdlet.Timeout); cmdlet.WriteVerbose(cmdlet, "commandTimeout = " + commandTimeout.ToString()); } // creating the driver server service cmdlet.WriteVerbose(cmdlet, "creating a DriverService"); // try { //Autofac.NamedParameter driverDirectoryParameter = // new NamedParameter("driverPath", driverDirectoryPath); switch (driverServerType) { // case DriverServers.none: // // break; case DriverServers.Chrome: //Console.WriteLine("driver server 00012c"); cmdlet.WriteVerbose(cmdlet, "creating a ChromeDriverService"); //Console.WriteLine("creating chrome driver service"); service = ChromeDriverService.CreateDefaultService(driverDirectoryPath); //Console.WriteLine("the chrome driver service has been created"); break; case DriverServers.Ie: cmdlet.WriteVerbose(cmdlet, "creating a InternetExplorerDriverService"); service = InternetExplorerDriverService.CreateDefaultService(driverDirectoryPath); break; default: throw new Exception("Invalid value for DriverServers"); } switch (driverServerType) { // case DriverServers.none: // // break; case DriverServers.Chrome: listOfParameters.Add(new NamedParameter("service", service)); listOfParameters.Add(new NamedParameter("options", chromeOptions)); listOfParameters.Add(new NamedParameter("commandTimeout", commandTimeout)); cmdlet.WriteVerbose(cmdlet, "creating the ChromeDriver"); try { //ChromeDriverService service1 = ChromeDriverService.CreateDefaultService(); //DriverService service2 = ChromeDriverService.CreateDefaultService(); //Console.WriteLine("driverServerType.ToString() = " + driverServerType.ToString()); //Console.WriteLine(listOfParameters.Count.ToString()); //Console.WriteLine("creating driver"); driver = Container.ResolveNamed <IWebDriver>( driverServerType.ToString(), listOfParameters); //Console.WriteLine("driver has been created"); } catch (Exception eChDrv) { Console.WriteLine(eChDrv.Message); Console.WriteLine(eChDrv.StackTrace); } // // ChromeDriver drv = new ChromeDriver(); // ChromeDriver drv = new ChromeDriver("opt"); // ChromeDriver drv = new ChromeDriver("dir"); // ChromeDriver drv = new ChromeDriver("dir", "opt"); // ChromeDriver drv = new ChromeDriver("dir", "opt", "timeout"); // ChromeDriver drv = new ChromeDriver("svc", "opt"); // ChromeDriver drv = new ChromeDriver("svc", "opt", "timeout"); // break; case DriverServers.Ie: listOfParameters.Add(new NamedParameter("service", service)); listOfParameters.Add(new NamedParameter("options", ieOptions)); listOfParameters.Add(new NamedParameter("commandTimeout", commandTimeout)); cmdlet.WriteVerbose(cmdlet, "creating the InternetExplorerDriver"); driver = Container.ResolveNamed <IWebDriver>( driverServerType.ToString(), listOfParameters.ToArray()); break; default: throw new Exception("Invalid value for DriverServers"); } // getting the process of the driver server running cmdlet.WriteVerbose(cmdlet, "findng out the process of the driver created"); //switch (driverType) { switch (cmdlet.DriverType) { case Drivers.Chrome: //SeHelper.GetDriverProcess(Drivers.Chrome, driver.Title + SeHelper.DriverTitleComplementChrome); //SeHelper.GetDriverProcess(driverType, driver.Title + SeHelper.DriverTitleComplementChrome); SeHelper.GetDriverProcess(cmdlet.DriverType, driver.Title + SeHelper.DriverTitleComplementChrome); break; // case Drivers.Firefox: // // break; case Drivers.InternetExplorer: //SeHelper.GetDriverProcess(Drivers.InternetExplorer, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); //SeHelper.GetDriverProcess(driverType, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); SeHelper.GetDriverProcess(cmdlet.DriverType, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); break; // case Drivers.Safari: // // break; // case Drivers.HTML: // // break; // default: // throw new Exception("Invalid value for Drivers"); } // return driver return(driver); }
public static IWebDriver GetDriverServer(StartSeWebDriverCommand cmdlet) { IWebDriver driver = null; var driverDirectoryPath = string.Empty; ChromeOptions chromeOptions = null; InternetExplorerOptions ieOptions = null; var commandTimeout = TimeSpan.FromSeconds(60.0); DriverService service = null; var listOfParameters = new System.Collections.Generic.List<Autofac.Core.Parameter>(); // determine the type of dirver server var driverServerType = DriverServers.None; var ieArchitecture = InternetExplorer.X86; // Drivers driverType = Drivers.HTML; // if (true == cmdlet.CH) { // cmdlet.WriteVerbose(cmdlet, "required ChromeDriver"); // driverServerType = DriverServers.chrome; // driverType = Drivers.Chrome; // } // if (true == cmdlet.IE) { // cmdlet.WriteVerbose(cmdlet, "required InternetExplorerDriver"); // driverServerType = DriverServers.ie; // ieArchitecture = cmdlet.Architecture; // driverType = Drivers.InternetExplorer; // } switch (cmdlet.DriverType) { case Drivers.Chrome: cmdlet.WriteVerbose(cmdlet, "required ChromeDriver"); driverServerType = DriverServers.Chrome; //driverType = Drivers.Chrome; break; case Drivers.Firefox: break; case Drivers.InternetExplorer: cmdlet.WriteVerbose(cmdlet, "required InternetExplorerDriver"); driverServerType = DriverServers.Ie; ieArchitecture = cmdlet.Architecture; //driverType = Drivers.InternetExplorer; break; case Drivers.Safari: break; case Drivers.Html: break; default: throw new Exception("Invalid value for Drivers"); } // collect processes before running the server cmdlet.WriteVerbose(cmdlet, "collect processes"); SeHelper.CollectDriverProcesses(cmdlet.DriverType); // driverDirectoryPath if (string.IsNullOrEmpty(cmdlet.DriverDirectoryPath)) { cmdlet.WriteVerbose(cmdlet, "using the default driver directory path"); driverDirectoryPath = System.IO.Path.GetDirectoryName(cmdlet.GetType().Assembly.Location); if (DriverServers.Ie == driverServerType && InternetExplorer.X86 == ieArchitecture) { driverDirectoryPath += "\\32\\"; } if (DriverServers.Ie == driverServerType && InternetExplorer.X64 == ieArchitecture) { driverDirectoryPath += "\\64\\"; } } else { cmdlet.WriteVerbose(cmdlet, "using the path from the cmdlet parameter"); driverDirectoryPath = cmdlet.DriverDirectoryPath; } cmdlet.WriteVerbose(cmdlet, driverDirectoryPath); // ChromeOptions, InternetExplorerOptions // try { if (DriverServers.Chrome == driverServerType) { if (null == cmdlet.ChromeOptions) { cmdlet.WriteVerbose(cmdlet, "using the default ChromeOptions"); chromeOptions = new ChromeOptions(); } else { cmdlet.WriteVerbose(cmdlet, "using the supplied ChromeOptions"); chromeOptions = cmdlet.ChromeOptions; } } if (DriverServers.Ie == driverServerType) { if (null == cmdlet.IeOptions) { cmdlet.WriteVerbose(cmdlet, "using the default InternetExplorerOptions"); ieOptions = new InternetExplorerOptions(); ieOptions.IgnoreZoomLevel = true; } else { cmdlet.WriteVerbose(cmdlet, "using the supplied InternetExplorerOptions"); ieOptions = cmdlet.IeOptions; } } // commandTimeout if (null != cmdlet.Timeout && 0 != cmdlet.Timeout && Preferences.Timeout != cmdlet.Timeout) { // ?? cmdlet.WriteVerbose(cmdlet, "setting the commandTimeout"); commandTimeout = TimeSpan.FromMilliseconds(cmdlet.Timeout); cmdlet.WriteVerbose(cmdlet, "commandTimeout = " + commandTimeout.ToString()); } // creating the driver server service cmdlet.WriteVerbose(cmdlet, "creating a DriverService"); // try { //Autofac.NamedParameter driverDirectoryParameter = // new NamedParameter("driverPath", driverDirectoryPath); switch (driverServerType) { // case DriverServers.none: // // break; case DriverServers.Chrome: //Console.WriteLine("driver server 00012c"); cmdlet.WriteVerbose(cmdlet, "creating a ChromeDriverService"); //Console.WriteLine("creating chrome driver service"); service = ChromeDriverService.CreateDefaultService(driverDirectoryPath); //Console.WriteLine("the chrome driver service has been created"); break; case DriverServers.Ie: cmdlet.WriteVerbose(cmdlet, "creating a InternetExplorerDriverService"); service = InternetExplorerDriverService.CreateDefaultService(driverDirectoryPath); break; default: throw new Exception("Invalid value for DriverServers"); } switch (driverServerType) { // case DriverServers.none: // // break; case DriverServers.Chrome: listOfParameters.Add(new NamedParameter("service", service)); listOfParameters.Add(new NamedParameter("options", chromeOptions)); listOfParameters.Add(new NamedParameter("commandTimeout", commandTimeout)); cmdlet.WriteVerbose(cmdlet, "creating the ChromeDriver"); try { //ChromeDriverService service1 = ChromeDriverService.CreateDefaultService(); //DriverService service2 = ChromeDriverService.CreateDefaultService(); //Console.WriteLine("driverServerType.ToString() = " + driverServerType.ToString()); //Console.WriteLine(listOfParameters.Count.ToString()); //Console.WriteLine("creating driver"); driver = Container.ResolveNamed<IWebDriver>( driverServerType.ToString(), listOfParameters); //Console.WriteLine("driver has been created"); } catch (Exception eChDrv) { Console.WriteLine(eChDrv.Message); Console.WriteLine(eChDrv.StackTrace); } // // ChromeDriver drv = new ChromeDriver(); // ChromeDriver drv = new ChromeDriver("opt"); // ChromeDriver drv = new ChromeDriver("dir"); // ChromeDriver drv = new ChromeDriver("dir", "opt"); // ChromeDriver drv = new ChromeDriver("dir", "opt", "timeout"); // ChromeDriver drv = new ChromeDriver("svc", "opt"); // ChromeDriver drv = new ChromeDriver("svc", "opt", "timeout"); // break; case DriverServers.Ie: listOfParameters.Add(new NamedParameter("service", service)); listOfParameters.Add(new NamedParameter("options", ieOptions)); listOfParameters.Add(new NamedParameter("commandTimeout", commandTimeout)); cmdlet.WriteVerbose(cmdlet, "creating the InternetExplorerDriver"); driver = Container.ResolveNamed<IWebDriver>( driverServerType.ToString(), listOfParameters.ToArray()); break; default: throw new Exception("Invalid value for DriverServers"); } // getting the process of the driver server running cmdlet.WriteVerbose(cmdlet, "findng out the process of the driver created"); //switch (driverType) { switch (cmdlet.DriverType) { case Drivers.Chrome: //SeHelper.GetDriverProcess(Drivers.Chrome, driver.Title + SeHelper.DriverTitleComplementChrome); //SeHelper.GetDriverProcess(driverType, driver.Title + SeHelper.DriverTitleComplementChrome); SeHelper.GetDriverProcess(cmdlet.DriverType, driver.Title + SeHelper.DriverTitleComplementChrome); break; // case Drivers.Firefox: // // break; case Drivers.InternetExplorer: //SeHelper.GetDriverProcess(Drivers.InternetExplorer, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); //SeHelper.GetDriverProcess(driverType, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); SeHelper.GetDriverProcess(cmdlet.DriverType, driver.Title + SeHelper.DriverTitleComplementInternetExplorer); break; // case Drivers.Safari: // // break; // case Drivers.HTML: // // break; // default: // throw new Exception("Invalid value for Drivers"); } // return driver return driver; }