77using OpenQA . Selenium . IE ;
88using OpenQA . Selenium . Remote ;
99using Structura . GuiTests . Utilities ;
10- using Tests . SeleniumHelpers ;
1110
1211namespace Structura . GuiTests . SeleniumHelpers
1312{
@@ -20,78 +19,47 @@ public enum DriverToUse
2019
2120 public class DriverFactory
2221 {
23- private static readonly FirefoxProfile FirefoxProfile = CreateFirefoxProfile ( ) ;
24-
25- private static FirefoxProfile CreateFirefoxProfile ( )
22+ private static FirefoxOptions FirefoxOptions
2623 {
27- var firefoxProfile = new FirefoxProfile ( ) ;
28- firefoxProfile . SetPreference ( "network.automatic-ntlm-auth.trusted-uris" , "http://localhost" ) ;
29- return firefoxProfile ;
24+ get
25+ {
26+ var firefoxProfile = new FirefoxOptions ( ) ;
27+ firefoxProfile . SetPreference ( "network.automatic-ntlm-auth.trusted-uris" , "http://localhost" ) ;
28+ return firefoxProfile ;
29+ }
3030 }
3131
3232 public IWebDriver Create ( )
3333 {
3434 IWebDriver driver ;
35- var driverToUse = ConfigurationHelper . Get < DriverToUse > ( "DriverToUse" ) ;
36- var useGrid = ConfigurationHelper . Get < bool > ( "UseGrid" ) ;
37- if ( useGrid )
38- {
39- driver = CreateGridDriver ( driverToUse ) ;
40- }
41- else
42- {
43- switch ( driverToUse )
44- {
45- case DriverToUse . InternetExplorer :
46- driver = new InternetExplorerDriver ( AppDomain . CurrentDomain . BaseDirectory , new InternetExplorerOptions ( ) , TimeSpan . FromMinutes ( 5 ) ) ;
47- break ;
48- case DriverToUse . Firefox :
49- var firefoxProfile = FirefoxProfile ;
50- driver = new FirefoxDriver ( firefoxProfile ) ;
51- driver . Manage ( ) . Window . Maximize ( ) ;
52- break ;
53- case DriverToUse . Chrome :
54- driver = new ChromeDriver ( ) ;
55- break ;
56- default :
57- throw new ArgumentOutOfRangeException ( ) ;
58- }
35+ var driverToUse = ConfigurationHelper . Get < DriverToUse > ( "DriverToUse" ) ;
36+
37+ switch ( driverToUse )
38+ {
39+ case DriverToUse . InternetExplorer :
40+ driver = new InternetExplorerDriver ( AppDomain . CurrentDomain . BaseDirectory , new InternetExplorerOptions ( ) , TimeSpan . FromMinutes ( 5 ) ) ;
41+ break ;
42+ case DriverToUse . Firefox :
43+ var firefoxProfile = FirefoxOptions ;
44+ driver = new FirefoxDriver ( firefoxProfile ) ;
45+ driver . Manage ( ) . Window . Maximize ( ) ;
46+ break ;
47+ case DriverToUse . Chrome :
48+ driver = new ChromeDriver ( ) ;
49+ break ;
50+ default :
51+ throw new ArgumentOutOfRangeException ( ) ;
5952 }
6053
6154 driver . Manage ( ) . Window . Maximize ( ) ;
6255 var timeouts = driver . Manage ( ) . Timeouts ( ) ;
6356
64- timeouts . ImplicitlyWait ( TimeSpan . FromSeconds ( ConfigurationHelper . Get < int > ( "ImplicitlyWait" ) ) ) ;
65- timeouts . SetPageLoadTimeout ( TimeSpan . FromSeconds ( ConfigurationHelper . Get < int > ( "PageLoadTimeout" ) ) ) ;
57+ timeouts . ImplicitWait = TimeSpan . FromSeconds ( ConfigurationHelper . Get < int > ( "ImplicitlyWait" ) ) ;
58+ timeouts . PageLoad = TimeSpan . FromSeconds ( ConfigurationHelper . Get < int > ( "PageLoadTimeout" ) ) ;
6659
6760 // Suppress the onbeforeunload event first. This prevents the application hanging on a dialog box that does not close.
6861 ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( "window.onbeforeunload = function(e){};" ) ;
6962 return driver ;
7063 }
71-
72- public static IWebDriver CreateGridDriver ( DriverToUse driverToUse )
73- {
74- var gridUrl = ConfigurationManager . AppSettings [ "GridUrl" ] ;
75- var desiredCapabilities = DesiredCapabilities . InternetExplorer ( ) ;
76- switch ( driverToUse )
77- {
78- case DriverToUse . Firefox :
79- desiredCapabilities = DesiredCapabilities . Firefox ( ) ;
80- desiredCapabilities . SetCapability ( FirefoxDriver . ProfileCapabilityName , FirefoxProfile ) ;
81-
82- break ;
83- case DriverToUse . InternetExplorer :
84- desiredCapabilities = DesiredCapabilities . InternetExplorer ( ) ;
85- break ;
86- case DriverToUse . Chrome :
87- desiredCapabilities = DesiredCapabilities . Chrome ( ) ;
88- break ;
89- }
90- desiredCapabilities . IsJavaScriptEnabled = true ;
91- var remoteDriver = new ExtendedRemoteWebDriver ( new Uri ( gridUrl ) , desiredCapabilities , TimeSpan . FromSeconds ( 180 ) ) ;
92- var nodeHost = remoteDriver . GetNodeHost ( ) ;
93- Debug . WriteLine ( "Running tests on host " + nodeHost ) ;
94- return remoteDriver ;
95- }
9664 }
9765}
0 commit comments