2121using System . Collections . Generic ;
2222using System . Globalization ;
2323
24+ #nullable enable
25+
2426namespace OpenQA . Selenium
2527{
2628 /// <summary>
@@ -33,19 +35,19 @@ internal class Timeouts : ITimeouts
3335 private const string PageLoadTimeoutName = "pageLoad" ;
3436 private const string LegacyPageLoadTimeoutName = "page load" ;
3537
36- private readonly TimeSpan DefaultImplicitWaitTimeout = TimeSpan . FromSeconds ( 0 ) ;
37- private readonly TimeSpan DefaultAsyncScriptTimeout = TimeSpan . FromSeconds ( 30 ) ;
38- private readonly TimeSpan DefaultPageLoadTimeout = TimeSpan . FromSeconds ( 300 ) ;
38+ private static readonly TimeSpan DefaultImplicitWaitTimeout = TimeSpan . FromSeconds ( 0 ) ;
39+ private static readonly TimeSpan DefaultAsyncScriptTimeout = TimeSpan . FromSeconds ( 30 ) ;
40+ private static readonly TimeSpan DefaultPageLoadTimeout = TimeSpan . FromSeconds ( 300 ) ;
3941
40- private WebDriver driver ;
42+ private readonly WebDriver driver ;
4143
4244 /// <summary>
4345 /// Initializes a new instance of the <see cref="Timeouts"/> class
4446 /// </summary>
4547 /// <param name="driver">The driver that is currently in use</param>
4648 public Timeouts ( WebDriver driver )
4749 {
48- this . driver = driver ;
50+ this . driver = driver ?? throw new ArgumentNullException ( nameof ( driver ) ) ;
4951 }
5052
5153 /// <summary>
@@ -70,8 +72,8 @@ public Timeouts(WebDriver driver)
7072 /// </remarks>
7173 public TimeSpan ImplicitWait
7274 {
73- get { return this . ExecuteGetTimeout ( ImplicitTimeoutName ) ; }
74- set { this . ExecuteSetTimeout ( ImplicitTimeoutName , value ) ; }
75+ get => this . ExecuteGetTimeout ( ImplicitTimeoutName ) ;
76+ set => this . ExecuteSetTimeout ( ImplicitTimeoutName , value ) ;
7577 }
7678
7779 /// <summary>
@@ -87,8 +89,8 @@ public TimeSpan ImplicitWait
8789 /// </remarks>
8890 public TimeSpan AsynchronousJavaScript
8991 {
90- get { return this . ExecuteGetTimeout ( AsyncScriptTimeoutName ) ; }
91- set { this . ExecuteSetTimeout ( AsyncScriptTimeoutName , value ) ; }
92+ get => this . ExecuteGetTimeout ( AsyncScriptTimeoutName ) ;
93+ set => this . ExecuteSetTimeout ( AsyncScriptTimeoutName , value ) ;
9294 }
9395
9496 /// <summary>
@@ -103,29 +105,21 @@ public TimeSpan AsynchronousJavaScript
103105 /// </remarks>
104106 public TimeSpan PageLoad
105107 {
106- get
107- {
108- string timeoutName = PageLoadTimeoutName ;
109- return this . ExecuteGetTimeout ( timeoutName ) ;
110- }
111-
112- set
113- {
114- string timeoutName = PageLoadTimeoutName ;
115- this . ExecuteSetTimeout ( timeoutName , value ) ;
116- }
108+ get => this . ExecuteGetTimeout ( PageLoadTimeoutName ) ;
109+ set => this . ExecuteSetTimeout ( PageLoadTimeoutName , value ) ;
117110 }
118111
119112 private TimeSpan ExecuteGetTimeout ( string timeoutType )
120113 {
121114 Response commandResponse = this . driver . InternalExecute ( DriverCommand . GetTimeouts , null ) ;
122- Dictionary < string , object > responseValue = ( Dictionary < string , object > ) commandResponse . Value ;
123- if ( ! responseValue . ContainsKey ( timeoutType ) )
115+
116+ Dictionary < string , object ? > responseValue = ( Dictionary < string , object ? > ) commandResponse . Value ! ;
117+ if ( ! responseValue . TryGetValue ( timeoutType , out object ? timeout ) )
124118 {
125119 throw new WebDriverException ( "Specified timeout type not defined" ) ;
126120 }
127121
128- return TimeSpan . FromMilliseconds ( Convert . ToDouble ( responseValue [ timeoutType ] , CultureInfo . InvariantCulture ) ) ;
122+ return TimeSpan . FromMilliseconds ( Convert . ToDouble ( timeout , CultureInfo . InvariantCulture ) ) ;
129123 }
130124
131125 private void ExecuteSetTimeout ( string timeoutType , TimeSpan timeToWait )
@@ -149,6 +143,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
149143
150144 Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
151145 parameters . Add ( timeoutType , Convert . ToInt64 ( milliseconds ) ) ;
146+
152147 this . driver . InternalExecute ( DriverCommand . SetTimeouts , parameters ) ;
153148 }
154149 }
0 commit comments