lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
506 stars 115 forks source link

[Question] Configure Canopy to run on Azure Devops #468

Closed MNie closed 5 years ago

MNie commented 5 years ago

I have a couple of tests and I want to run them on Azure DevOps. I run them locally by the following command:

dotnet run Project.AutomatedTests.fsproj

on Azure DevOps I tried to configure them the same way, so I have the following steps:

dotnet restore Project.sln
dotnet build Project.sln
dotnet run Project.AutomatedTests.dll

But Azure DevOps fails with following error:

2019-01-19T11:11:42.5195371Z ##[error]Error: /usr/bin/dotnet failed with return code: 1
2019-01-19T11:11:42.5219579Z ##[error]Dotnet command failed with non-zero exit code on the following projects : /home/vsts/work/1/s/backend/tests/Project.AutomatedTests/bin/Release/netcoreapp2.1/Project.AutomatedTests.dll,/home/vsts/work/1/s/backend/tests/Project.AutomatedTests/bin/Release/netcoreapp2.1/publish/Project.AutomatedTests.dll,/home/vsts/work/1/s/backend/tests/Project.AutomatedTests/obj/Release/netcoreapp2.1/Project.AutomatedTests.dll

I also tried running:

dotnet run Project.AutomatedTests.fsproj

But it fails with the same error.

I tried to run it with --project argument like that:

-v d --project /home/vsts/work/1/s/backend/tests/Project.AutomatedTests/Project.AutomatedTests.fsproj

but tests hangs up with the following exception:

 at Start.main(String[] _arg1) in /home/vsts/work/1/s/backend/tests/Project.AutomatedTests/Program.fs:line 17
   at canopy.classic.start(BrowserStartMode b) in C:\projects\canopy\src\canopy\canopy.fs:line 250
   at canopy.parallell.functions.start(BrowserStartMode b) in C:\projects\canopy\src\canopy\canopy.parallell.functions.fs:line 835
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)

Is there some information on how it should be configured to run on Azure DevOps? Or maybe I should use some test framework/library to run canopy like Expecto or something else?

lefthandedgoat commented 5 years ago

For the last error, you gave the stack trace but not the error.

it looks like it tired to launch chrome but could not.

You need both chrome installed on the machine that is running it + chrome driver.

I have never used Azure Devops, but I can give you some high level guidance for using canopy alone.

Canopy's test runner is really simple. It just loops over the tests and run them, increment the failed/passed test counters.

I always run from a console app, and my return code is the number of failed tests:

https://github.com/lefthandedgoat/canopyStarterKit/blob/master/canopyStarterKit/Program.fs#L28

If you want to use another testing framework to run the tests, like nUnit or expecto, that is fine too, but you will lose some of the nice things that the canopy runner has.

If you have chromedriver + chrome + the ability to run a console application in AzureDevops then it should work. One other consideration would be desktop resolution. I don't know how AzureDevops is setup, but a typical windows service only allows a resolution of 1028x768, and your website may not render well in that resolution. Linux allows you to create fake desktops with higher resolution and can be a better solution if this is a problem for you.

MNie commented 5 years ago

@lefthandedgoat it seems that I have to use Ubuntu agent and headless mode and everything works just fine. Thanks!

lefthandedgoat commented 5 years ago

Awesome! @MNie