From fabeb9d745e7e5255e4e8d20d1092f41fea9e88a Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 2 Nov 2022 11:15:04 +0100 Subject: [PATCH] docs(#647): Add CLI commands to checkout and run example application --- examples/WeatherForecast/README.md | 9 ++++++++- .../tests/WeatherForecast.Test/WeatherForecastTest.cs | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/WeatherForecast/README.md b/examples/WeatherForecast/README.md index c28a48061..975590cfa 100644 --- a/examples/WeatherForecast/README.md +++ b/examples/WeatherForecast/README.md @@ -1,3 +1,10 @@ # Testcontainers for .NET WeatherForecast example -This example builds and ships a Blazor application in a Docker image build, runs a Docker container and executes tests against a running instance of the application. Testcontainers for .NET takes care of the Docker image build and the Docker container that hosts the application. Spin up as much as containers as you like and run your tests heavily in parallel. +This example builds and ships a Blazor application in a Docker image build, runs a Docker container and executes tests against a running instance of the application. Testcontainers for .NET takes care of the Docker image build and the Docker container that hosts the application. Spin up as much as containers as you like and run your tests heavily in parallel. Checkout and run the tests on your machine: + +```console +git clone git@github.com:testcontainers/testcontainers-dotnet.git +cd ./testcontainers-dotnet/examples/WeatherForecast/ +dotnet build WeatherForecast.sln +dotnet test WeatherForecast.sln +``` diff --git a/examples/WeatherForecast/tests/WeatherForecast.Test/WeatherForecastTest.cs b/examples/WeatherForecast/tests/WeatherForecast.Test/WeatherForecastTest.cs index 698d4a64f..7dfe45156 100644 --- a/examples/WeatherForecast/tests/WeatherForecast.Test/WeatherForecastTest.cs +++ b/examples/WeatherForecast/tests/WeatherForecast.Test/WeatherForecastTest.cs @@ -9,6 +9,7 @@ using DotNet.Testcontainers.Builders; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Support.UI; using WeatherForecast.Entities; using Xunit; @@ -69,7 +70,7 @@ public Web(WeatherForecastContainer weatherForecastContainer) [Fact] [Trait("Category", nameof(Web))] - public async Task Get_WeatherForecast_ReturnsSevenDays() + public void Get_WeatherForecast_ReturnsSevenDays() { // Given string ScreenshotFileName() => $"{nameof(Get_WeatherForecast_ReturnsSevenDays)}_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.png"; @@ -83,8 +84,8 @@ public async Task Get_WeatherForecast_ReturnsSevenDays() chrome.FindElement(By.TagName("fluent-button")).Click(); - await Task.Delay(TimeSpan.FromSeconds(1)) - .ConfigureAwait(false); + var wait = new WebDriverWait(chrome, TimeSpan.FromSeconds(10)); + wait.Until(webDriver => 1.Equals(webDriver.FindElements(By.TagName("span")).Count)); chrome.GetScreenshot().SaveAsFile(Path.Combine(CommonDirectoryPath.GetSolutionDirectory().DirectoryPath, ScreenshotFileName()));