Chromedriver.exe UI Testing Error with AzureDevOps - selenium

EasyRepo Selenium Tests running on Visual Studio 2019, but i get an error stating that the "Chrome Driver" does not exist, however the chromedriver.exe does indeed exist.
I want to conduct UI Tests via ADO Pipelines for Selenium EasyRepo whilst using Chrome on the Hosted Agent running on Windows 2019, but it keeps failing.
# YAML Azure DevOps Pipeline for Visual Studio UI Testing with NuGet and Chrome
trigger:
- master
pool:
vmImage: 'windows-2019'
variables:
solution: 'Automation.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: VisualStudioTestPlatformInstaller#1
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'latestPreRelease'
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: 'Automation.dll'
searchFolder: '$(System.DefaultWorkingDirectory)'
vsTestVersion: '16.0'
runSettingsFile: 'TestSettings.runsettings'
In the app settings i have also hardcoded the web driver for chrome to see if it would make a difference.
<add key="DriversPath" value="C:\SeleniumWebDrivers\ChromeDriver" />
The error;
##[error] [ERROR] The file D:\a\_temp\\Automation\bin\Debug\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html

Related

Azure Devops Pipeline Azure Repos Git .Net Error in Tests Failed to run as a self-contained app

I have a .Net solution with multiple projects, including a test project.
When I create a pipeline for my solution using Azure Devops templates, with the connect Azure Repos Git and configure ASP.Net Core (.Net Framework), I get the following yml file:
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
When I run the pipline and reaches the VSTest Task, after running the tests, it gives me the following error:
##[error]Testhost process for source(s) 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\Microsoft.TestPlatform.PlatformAbstractions.dll' exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
##[error]Failed to run as a self-contained app.
##[error] - The application was run as a self-contained app because 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' was not found.
##[error] - If this should be a framework-dependent app, add the 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
##[error]. Please check the diagnostic logs for more information.
How can I fix this?
After a while searching for the solution, I found out that all I had to do was to change the line **\*test*.dll to **\*Tests.dll for the key testAssemblyVer2 in the task VSTest#2.
Before:
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
--> **\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
After:
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
--> **\*Tests.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Then the pipeline runned sucesssfully!

NETSDK1045: The current .NET SDK does not support 'newer version' as a target

I've created a simple ASP.NET CORE 6 Web API. I then pushed it to Github. When I try to create a pipeline in Azure Devops, I'm getting the error.
C:\Program Files\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET
.TargetFrameworkInference.targets(141,5): error NETSDK1045: The current .NET SDK does not support
targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports
.NET 6.0.
I've just downloaded VS 2022 community edition. I've installed .Net SDK 6.
Here's my csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
I chose what Azure devops suggested, so this is my yml file
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
I've followed what's said in this documentation, but it's not working. The build is still failing like this
[![enter image description here][2]][2]
Thanks for helping
After reading this 2 links, it there were 2 issues with the template from Azure devops.
the restore packages kept on looking for SDK 5. So this task fixed the issue. I've to include a step that mentions SDK 6. https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops
also it kept on targeting Visual Studio 2019, which doesn't support .NET 6.0.x. Therefore, instead of vmImage: 'windows-latest', using vmImage: 'windows-2022' allow the build to succeed https://github.com/dotnet/core/issues/6907.
I ended up using the classic template so that I can understand better how the pipeline works. 1) Either using ubuntu-latest or windows-2022. 2) add a step for the version of SDK.
I chose what Azure devops suggested, so this is my yml file
Unfortunately it's easy to confuse things, since Microsoft's naming is anything but consistent.
You need to use .NET Core guide for this: Build, test, and deploy .NET Core apps
To save you time, here is a simple YAML pipeline to build ASP.NET Core applications:
trigger:
branches:
include:
- master
# Setup pipeline-level variables to keep things DRY
variables:
configuration: Release
projects: '**/*.csproj'
publish_dir: $(Build.ArtifactStagingDirectory)
vm_image: ubuntu-latest
stages:
- stage: Build
jobs:
- job: dotnet
displayName: .NET
pool:
vmImage: $(vm_image)
# Run builds in latest .NET 6 SDK container (Debian 11)
# This simplifies things and allows to easily target different SDKs:
# https://hub.docker.com/_/microsoft-dotnet-sdk
container: mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim
workspace:
clean: all
# Build tasks a separated (restore/build/test/publish)
# to make it easier to catch/debug issues
steps:
- task: DotNetCoreCLI#2
displayName: .NET | Restore [$(configuration)]
inputs:
command: restore
projects: $(projects)
- task: DotNetCoreCLI#2
displayName: .NET | Build [$(configuration)]
inputs:
command: build
projects: $(projects)
arguments: --configuration $(configuration) --no-restore
- task: DotNetCoreCLI#2
displayName: .NET | Test [$(configuration)]
inputs:
command: test
projects: $(projects)
publishTestResults: true
arguments: --configuration $(configuration) --no-restore --no-build
- task: DotNetCoreCLI#2
displayName: .NET | Publish [$(configuration)]
inputs:
command: publish
publishWebProjects: true
zipAfterPublish: true
modifyOutputPath: true
arguments: --configuration $(configuration) --output $(publish_dir) --no-restore --no-build
# Publish zipped build results so they can be downloaded from the pipeline UI
- publish: $(publish_dir)
displayName: Artifact | Publish
artifact: $(Build.DefinitionName)

DevOps IIS Release Pipeline Not Extracting Files To Correct Location

I am trying to setup a Release Pipeline for an ASPNET Core application to an on-premises IIS Virtual Machine (VM).
Everything is working as expected except when it deploys the files to the IIS server, but it's not extracting the files and it's dropping the zip file in the wrong folder location. For example, the application files are supposed to be deployed to %SystemDrive%\sites\{mysite} - This is setup in the Release Pipeline under the IIS Web App Manage section (shown below).
On the server, this is deploying to the correct location, but instead of all the app files being deployed to the \sites\{mysite} it's creating two additional folders and then dropping a zip file called "WebApp.zip" like this, (%SystemDrive%\sites\{mysite}\{artifactName}\{artifactName}\WebApp.zip)
How do I get this to actually only deploy the website app files to the \sites\{mysite} directory?
I do have a yaml file, shown below. Any help would be greatly appreciated.
trigger:
- development
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: '{artifactName}' #removed the name for this post
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: '{removed}' #removed the name for this post
Package: '$(System.DefaultWorkingDirectory)'
RemoveAdditionalFilesFlag: true
XmlVariableSubstitution: True
EDIT:
I've updated my yaml to look like what's shown below. If I do not include the PublishPipelineArtifact#1 task then no files ever get copied to the IIS server. This is also deploying now to a folder structure like this: {artifact}\{artifact}\(all of the files) which is an improvement, but still I don't need the two {artifact} folders, I just want the files deployed in the website's root directory.
Any help is greatly appreciated as I've spent a pretty ridiculous amount of time on this thus far.
Updated Yaml:
trigger:
- development
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: $(System.DefaultWorkingDirectory)/bin/Release/net5.0
artifact: {artifactName}
Specify the path to the *.zip package file for your IISWebAppDeploymentOnMachineGroup#0 task's Package input instead of just the default working directory.
Edit:
You have a lot going on that's confusing me and I believe it's probably because you're not sure what you're doing - forgive me if incorrect. First, you look like you're building and packaging the build results twice - with VSBuild#1 the first time, then using dotnet build and dotnet publish the second time via two DotNetCoreCLI#2 tasks. You then have a PublishPipelineArtifact#1 referencing the target of both packaging/publishing tasks.
You then attempt to deploy these packages but reference a completely different path/file. Typically a build and deployment would be split into two separate jobs and the deployment job would download the published pipeline artifact. That downloaded artifact is the path/file you want to reference in your deployment task's Package input.

Using Azure Pipelines with multi targeting projects I get error NETSDK1061

The complete error is here:
Error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 1.0.0, but with current settings, version 2.2.0 would be used instead.
To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish.
Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.
For more information, see https://aka.ms/dotnet-runtime-patch-selection.
Locally everything looks just fine, but on Azure it does not want to compile.
All the proposed solutions that I have found online did not help, including:
- script: dotnet restore
- setting the <RuntimeFrameworkVersion>2.2.104</RuntimeFrameworkVersion> to the version I use.
- setting the <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Below is a part of the yaml file:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: 'src/MySolution.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
inputs:
versionSpec: '4.3.0'
- task: DotNetCoreInstaller#0
inputs:
packageType: 'sdk'
version: '2.2.104'
- script: dotnet restore $(solution)
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArchitecture: 'x64'
The project file contains the following:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net45</TargetFrameworks>
<LangVersion>latest</LangVersion>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
I had the same problem not so long ago and one thing that I noticed was that the nuget version used to restore the packages was fixed to 4.3.0 (I think it was a default suggestion). I tried to use a newer version like this:
- task: NuGetToolInstaller#0
inputs:
versionSpec: '>=4.3.0'
checkLatest: true
After the change, the build was fixed. In the logs I noticed that the version 5.2.0 was being used, although locally I could get only the version 5.1.0 (with 'nuget update -self').

Azure pipeline missing references

I'm trying to use the Azure pipelines to build and publish my projects. Unfortunately there is not much documentation or Q&A around.
My solution contains 12 libraries, most with .net core/standard, one with angular (But this is not the problem). In visual studio building/publishing works. In my dev.azure workspace it doesn't.
this is my YAML-file
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
and the problem is, that all the references are missing while building:
Error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
does anyone have any idea on how to fix this? The nuget restore works.
This issue look like about dependencies fail. It should because your project have referenced the dependencies, but did not installed them during the pipeline.
You can try with executing dotnet restore first before calling your VSBuild task.