Skip to content

Commit

Permalink
Adding webtests examples (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos authored Nov 12, 2020
1 parent 876ac17 commit c1acaa7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnetcore-iis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build-and-deploy:

runs-on: self-hosted

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
Expand Down Expand Up @@ -34,5 +34,5 @@ jobs:
- name: Run Web Test
run: |
dotnet build --configuration Release .\dotnet-core-webapp.webtest
cd .\dotnet-core-webapp.webtest
cd .\dotnet-core-webapp.webtests
dotnet test
33 changes: 30 additions & 3 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: .NET Core
on: [push]

jobs:
build:
build-and-deploy:

runs-on: ubuntu-latest

Expand All @@ -16,11 +16,14 @@ jobs:

# dotnet build and publish
- name: Build with dotnet
run: dotnet build --configuration Release
run: |
dotnet build --configuration Release ./dotnet-core-webapp/dotnetcore-webapp.csproj
- name: dotnet publish
run: |
dotnet publish -c Release -o dotnetcorewebapp
dotnet publish -c Release -o dotnetcorewebapp ./dotnet-core-webapp
# test for usage in versioning
- name: Hello world
run: echo Hello world, run number = $NBR
env:
Expand All @@ -34,6 +37,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectVersion: ${{ github.RUN_NUMBER }}
projectBaseDir: dotnet-core-webapp

# publish to Azure App Service
- name: 'Run Azure webapp deploy action using publish profile credentials'
Expand All @@ -47,3 +51,26 @@ jobs:
uses: wei/curl@v1
with:
args: -X GET https://dotnetcorewebapp19.azurewebsites.net/


webtest:

runs-on: windows-latest
needs: build-and-deploy

steps:
- uses: actions/checkout@v1
- name: Run Web Test
run: |
# overwrite the AppSettings.json
$pathToFile = "./dotnet-core-webapp.webtests/AppSettings.json"
$fileContent = Get-Content $pathToFile
$fileContent = $fileContent.Replace("http://localhost/dotnetcore-webapp/", "https://dotnetcorewebapp19.azurewebsites.net/")
Set-Content $pathToFile $fileContent
# build the test project
dotnet build --configuration Release ./dotnet-core-webapp.webtests
cd ./dotnet-core-webapp.webtests
# execute the tests
dotnet test
3 changes: 3 additions & 0 deletions dotnet-core-webapp.webtests/AppSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testUrl": "http://localhost/dotnetcore-webapp/"
}
30 changes: 30 additions & 0 deletions dotnet-core-webapp.webtests/Helpers/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.Configuration;

namespace dotnetcorewebapp.webtests.Helpers
{
public static class Configuration
{
public static IConfigurationRoot GetConfigurationRoot()
{
return new ConfigurationBuilder()
.AddJsonFile("AppSettings.json", optional: true)
.Build();
}

public static TestConfiguration GetApplicationConfiguration()
{
var configuration = new TestConfiguration();

var iConfig = GetConfigurationRoot();

ConfigurationBinder.Bind(iConfig, configuration);

return configuration;
}
}

public class TestConfiguration
{
public string testUrl { get; set; }
}
}
7 changes: 6 additions & 1 deletion dotnet-core-webapp.webtests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Threading;
using dotnetcorewebapp.webtests.Helpers;
using dotnetcorewebapp.webtests.PageObjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
Expand All @@ -11,7 +12,10 @@ namespace dotnetcorewebapp.webtests
[TestClass]
public class UnitTest1
{
private const string url = "http://localhost/dotnetcore-webapp/";
private static string GetUrl()
{
return Configuration.GetApplicationConfiguration().testUrl;
}
/// <summary>
/// Central store of the driver instance to use
/// </summary>
Expand All @@ -32,6 +36,7 @@ public static void ClassInitialize(TestContext context)
//Create the reference for our browser
Driver = new ChromeDriver(options);

var url = GetUrl();
//Navigate to start page
Driver.Navigate().GoToUrl(url);
}
Expand Down
25 changes: 20 additions & 5 deletions dotnet-core-webapp.webtests/dotnetcore-webapp.webtests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,32 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>

<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Selenium.WebDriver" Version="3.9.1" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.35.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="86.0.4240.2200" />
</ItemGroup>

<ItemGroup>
<None Update="AppSettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions dotnetcore-webapp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.30709.132
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetcore-webapp", "dotnet-core-webapp\dotnetcore-webapp.csproj", "{BDD47BF9-52F0-4C96-8827-BF074AC49ECE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnetcore-webapp.webtests", "dotnet-core-webapp.webtests\dotnetcore-webapp.webtests.csproj", "{D3175731-C420-46C3-A355-E3D87AD23D9C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetcore-webapp.webtests", "dotnet-core-webapp.webtests\dotnetcore-webapp.webtests.csproj", "{D3175731-C420-46C3-A355-E3D87AD23D9C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9C133C95-80C2-401C-99C1-B4E6F9E6778F}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -23,7 +23,8 @@ Global
{BDD47BF9-52F0-4C96-8827-BF074AC49ECE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDD47BF9-52F0-4C96-8827-BF074AC49ECE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3175731-C420-46C3-A355-E3D87AD23D9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3175731-C420-46C3-A355-E3D87AD23D9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3175731-C420-46C3-A355-E3D87AD23D9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3175731-C420-46C3-A355-E3D87AD23D9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit c1acaa7

Please sign in to comment.