Message:
Initialization method Project_BeforeTest threw exception. System.InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 104
Current browser version is 103.0.5060.66 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe (SessionNotCreated).
TestCleanup method Project_AfterTest threw exception.
System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
If we are running the test script on the local machine, we can easily change the appropriate browser driver by downloading it and replacing it in the local repo.
But what happens, if this issue happens while executing in Azure VM ? Where we don't have control over the version of Chrome driver used.
Below given is a workaround for such a scenario.
Here we are using PowerShell script to get the current chrome version and this version number will be used along with WebDriver manager to download the corresponding Browser driver.
Below PowerShell script can be executed in the Azure Pipeline task and we can store the version number in an output variable that can be used in another task.
$VersionOutput=(Get-Package -Name "Google Chrome").Version Write-Output $VersionOutput Write-Host "##vso[task.setvariable variable=ChromeVersion] $VersionOutput"
One way to implement this is by passing the version number through the runsetting file.
The default value of the version in WebDriver Manager is "Latest", We need to Override this by using the value we got from the PowerShell script.
ChromeOptions chroptions = new ChromeOptions(); new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig(), "<Version RunSetting Key>");
We can override the default value by runsetting value in the VsTest Pipeline task as below.
No comments:
Post a Comment