July 4, 2022

Get Azure VM Chrome version using PowerShell script and use the output value in Azure Pipeline tasks

  July 4, 2022
We might have seen the following error while using chrome driver in selenium 

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"


Then we can use this output variable in VsTest task to download the correct chrome driver version.

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.





logoblog

Thanks for reading Get Azure VM Chrome version using PowerShell script and use the output value in Azure Pipeline tasks

Previous
« Prev Post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...