I have a .NET Angular App (from the dotnet new angular cli command) that has Cypress setup in the /ClientApp folder. I can run the tests that I have on my local computer.
What I am wanting to do is to be able to run an azure pipeline, which spins up the angular and .net app. Then run the cypress tests and then if it finds an error stop the pipeline, otherwise just move onto the next step.
I have tried using a powershell script in the pipeline yml, and I have tried running the dotnet run &
script but it just either hangs or just isn’t around for the next step of the process when cypress runs as cyrpress complains that it cannot reach the localhost:44442 location.
I was wondering if perhaps running this in Docker in the azure pipeline might help? Or whether cypress has trouble connecting to the localhost domain within the pipeline because its in a different task?
2
Answers
So it took a little while but I finally found a solution I was happy with. So within my angular project I added the npm packages:
concurrently
andwait-on
.Then I added the following commands to my ClientApp/package.json file:
So the
run-dotnet
command will spin up an instance of the .NET web app. Now normally this waits until someone tries to access one of the .NET provided urls before it starts angular. Which we don't want to wait on.So then the command
npm run start
is executed to run the angular project.Then the
npx wait-on https://localhost:44415 && npm run cy:run
waits until the angular localhost port: 44415 is used (this is the usual port that your angular project runs on locally) and then runs the cypress commands.This will run cypress and then when it has finished its tests it will finish returning a success code.
So to run this in azure_pipelines.yml I added this:
Thanks to everyone who responded above and your questions gave me some direction but this seemed less of a hacky solution and also easier to run locally and without the need for Visual Studio.
Yes, You can Dockerize your
Asp.net core + Angular app
and Publish your application to Azure Container Registry, Then create a DockerFile with docker-compose.yml file and run below YAML script to run the Cypress Test, Refer below:-I Published my
.Net + Angular app
toAzure Container Registry
like below:-My docker-compose.yml file:-
Include it in the root of your repository:-
My Azure DevOps yaml pipeline:-
Make sure you run all these tasks in the same stage.
After running your cypress tests, You can inspect the Test results with Powershell task in your yaml pipeline like below:-