Starts the driver service if it is not already running. A cancellation token to observe while waiting for the task to complete. A task that represents the asynchronous start operation. If the driver service path is specified but the driver service executable name is not.</exc
(CancellationToken cancellationToken = default)
| 217 | /// <exception cref="WebDriverException">If the service fails to initialize within the timeout period or exits unexpectedly.</exception> |
| 218 | /// <exception cref="OperationCanceledException">If the operation is cancelled via the cancellation token.</exception> |
| 219 | [MemberNotNull(nameof(driverServiceProcess))] |
| 220 | public async ValueTask StartAsync(CancellationToken cancellationToken = default) |
| 221 | { |
| 222 | if (this.driverServiceProcess != null) |
| 223 | { |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | this.driverServiceProcess = new Process(); |
| 228 | |
| 229 | if (this.DriverServicePath != null) |
| 230 | { |
| 231 | if (this.DriverServiceExecutableName is null) |
| 232 | { |
| 233 | throw new InvalidOperationException("If the driver service path is specified, the driver service executable name must be as well"); |
| 234 | } |
| 235 | |
| 236 | this.driverServiceProcess.StartInfo.FileName = Path.Combine(this.DriverServicePath, this.DriverServiceExecutableName); |
| 237 | } |
| 238 | else if (this.DriverPathFromEnvironment is string environmentDriverPath) |
| 239 | { |
| 240 | if (_logger.IsEnabled(LogEventLevel.Debug)) |
| 241 | { |
| 242 | _logger.Debug($"Skipping Selenium Manager; using driver from {this.DriverServiceEnvironmentVariableName}: {environmentDriverPath}"); |
| 243 | } |
| 244 | |
| 245 | this.driverServiceProcess.StartInfo.FileName = environmentDriverPath; |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | var driverFinder = new DriverFinder(this.GetDefaultDriverOptions()); |
| 250 | var driverPath = await driverFinder.GetDriverPathAsync(cancellationToken).ConfigureAwait(false); |
| 251 | this.driverServiceProcess.StartInfo.FileName = driverPath; |
| 252 | } |
| 253 | |
| 254 | this.driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments; |
| 255 | this.driverServiceProcess.StartInfo.UseShellExecute = false; |
| 256 | this.driverServiceProcess.StartInfo.CreateNoWindow = this.HideCommandPromptWindow; |
| 257 | |
| 258 | this.driverServiceProcess.StartInfo.RedirectStandardOutput = true; |
| 259 | this.driverServiceProcess.StartInfo.RedirectStandardError = true; |
| 260 | |
| 261 | if (this.EnableProcessRedirection) |
| 262 | { |
| 263 | this.driverServiceProcess.OutputDataReceived += this.OnDriverProcessDataReceived; |
| 264 | this.driverServiceProcess.ErrorDataReceived += this.OnDriverProcessDataReceived; |
| 265 | } |
| 266 | |
| 267 | DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo); |
| 268 | this.OnDriverProcessStarting(eventArgs); |
| 269 | |
| 270 | this.driverServiceProcess.Start(); |
| 271 | |
| 272 | // Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks. |
| 273 | this.driverServiceProcess.BeginOutputReadLine(); |
| 274 | this.driverServiceProcess.BeginErrorReadLine(); |
| 275 | |
| 276 | await this.WaitForServiceInitializationAsync(cancellationToken).ConfigureAwait(false); |
no test coverage detected