21
21
using System . Collections . Generic ;
22
22
using System . Globalization ;
23
23
24
+ #nullable enable
25
+
24
26
namespace OpenQA . Selenium
25
27
{
26
28
/// <summary>
@@ -33,19 +35,19 @@ internal class Timeouts : ITimeouts
33
35
private const string PageLoadTimeoutName = "pageLoad" ;
34
36
private const string LegacyPageLoadTimeoutName = "page load" ;
35
37
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 ) ;
39
41
40
- private WebDriver driver ;
42
+ private readonly WebDriver driver ;
41
43
42
44
/// <summary>
43
45
/// Initializes a new instance of the <see cref="Timeouts"/> class
44
46
/// </summary>
45
47
/// <param name="driver">The driver that is currently in use</param>
46
48
public Timeouts ( WebDriver driver )
47
49
{
48
- this . driver = driver ;
50
+ this . driver = driver ?? throw new ArgumentNullException ( nameof ( driver ) ) ;
49
51
}
50
52
51
53
/// <summary>
@@ -70,8 +72,8 @@ public Timeouts(WebDriver driver)
70
72
/// </remarks>
71
73
public TimeSpan ImplicitWait
72
74
{
73
- get { return this . ExecuteGetTimeout ( ImplicitTimeoutName ) ; }
74
- set { this . ExecuteSetTimeout ( ImplicitTimeoutName , value ) ; }
75
+ get => this . ExecuteGetTimeout ( ImplicitTimeoutName ) ;
76
+ set => this . ExecuteSetTimeout ( ImplicitTimeoutName , value ) ;
75
77
}
76
78
77
79
/// <summary>
@@ -87,8 +89,8 @@ public TimeSpan ImplicitWait
87
89
/// </remarks>
88
90
public TimeSpan AsynchronousJavaScript
89
91
{
90
- get { return this . ExecuteGetTimeout ( AsyncScriptTimeoutName ) ; }
91
- set { this . ExecuteSetTimeout ( AsyncScriptTimeoutName , value ) ; }
92
+ get => this . ExecuteGetTimeout ( AsyncScriptTimeoutName ) ;
93
+ set => this . ExecuteSetTimeout ( AsyncScriptTimeoutName , value ) ;
92
94
}
93
95
94
96
/// <summary>
@@ -103,29 +105,21 @@ public TimeSpan AsynchronousJavaScript
103
105
/// </remarks>
104
106
public TimeSpan PageLoad
105
107
{
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 ) ;
117
110
}
118
111
119
112
private TimeSpan ExecuteGetTimeout ( string timeoutType )
120
113
{
121
114
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 ) )
124
118
{
125
119
throw new WebDriverException ( "Specified timeout type not defined" ) ;
126
120
}
127
121
128
- return TimeSpan . FromMilliseconds ( Convert . ToDouble ( responseValue [ timeoutType ] , CultureInfo . InvariantCulture ) ) ;
122
+ return TimeSpan . FromMilliseconds ( Convert . ToDouble ( timeout , CultureInfo . InvariantCulture ) ) ;
129
123
}
130
124
131
125
private void ExecuteSetTimeout ( string timeoutType , TimeSpan timeToWait )
@@ -149,6 +143,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
149
143
150
144
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
151
145
parameters . Add ( timeoutType , Convert . ToInt64 ( milliseconds ) ) ;
146
+
152
147
this . driver . InternalExecute ( DriverCommand . SetTimeouts , parameters ) ;
153
148
}
154
149
}
0 commit comments