-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:6.0 | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN dotnet restore | ||
|
||
ENV RUN_IT true | ||
|
||
# run tests on docker run | ||
ENTRYPOINT ["dotnet", "test", "--filter", "FullyQualifiedName~IntegrationTests"] |
24 changes: 24 additions & 0 deletions
24
visual-dotnet/SauceLabs.Visual.IntegrationTests/IntegrationTestAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Interfaces; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace SauceLabs.Visual.IntegrationTests; | ||
|
||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public class IntegrationTestAttribute : NUnitAttribute, IApplyToTest | ||
{ | ||
public void ApplyToTest(Test test) | ||
{ | ||
if (test.RunState == RunState.NotRunnable) | ||
{ | ||
return; | ||
} | ||
|
||
if (Environment.GetEnvironmentVariable("RUN_IT") != "true") | ||
{ | ||
test.RunState = RunState.Ignored; | ||
test.Properties.Set(PropertyNames.SkipReason, "This test runs only when RUN_IT is \"true\""); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
visual-dotnet/SauceLabs.Visual.IntegrationTests/LoginPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using OpenQA.Selenium.Remote; | ||
|
||
namespace SauceLabs.Visual.IntegrationTests; | ||
|
||
public class LoginPage | ||
{ | ||
private RemoteWebDriver? Driver { get; set; } | ||
private VisualClient? VisualClient { get; set; } | ||
|
||
[SetUp] | ||
public async Task Setup() | ||
{ | ||
var browserOptions = Utils.GetBrowserOptions(); | ||
var sauceOptions = Utils.GetSauceOptions(); | ||
browserOptions.AddAdditionalOption("sauce:options", sauceOptions); | ||
|
||
var sauceUrl = Utils.GetOnDemandURL(); | ||
Driver = new RemoteWebDriver(sauceUrl, browserOptions); | ||
Driver.ExecuteScript("sauce:job-name=NUnit C#/.Net Visual Session"); | ||
|
||
VisualClient = await VisualClient.Create(Driver, Region.UsWest1); | ||
TestContext.Progress.WriteLine($"Build: {VisualClient.Build.Url}"); | ||
} | ||
|
||
[IntegrationTest] | ||
[Test] | ||
public async Task LoginPage_ShouldOpen() | ||
{ | ||
Driver.Navigate().GoToUrl("https://www.saucedemo.com"); | ||
await VisualClient.VisualCheck("Login Page"); | ||
} | ||
|
||
[TearDown] | ||
public async Task Teardown() | ||
{ | ||
await VisualClient.Finish(); | ||
Driver?.Quit(); | ||
VisualClient?.Dispose(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
visual-dotnet/SauceLabs.Visual.IntegrationTests/SauceLabs.Visual.IntegrationTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/> | ||
<PackageReference Include="NUnit" Version="3.13.2"/> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/> | ||
<PackageReference Include="Selenium.WebDriver" Version="4.18.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SauceLabs.Visual\SauceLabs.Visual.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
using OpenQA.Selenium.Firefox; | ||
using OpenQA.Selenium.Safari; | ||
|
||
namespace SauceLabs.Visual.IntegrationTests; | ||
|
||
internal static class Utils | ||
{ | ||
public static Dictionary<string, string> GetSauceOptions() | ||
{ | ||
return new Dictionary<string, string> | ||
{ | ||
{ "username", GetSauceUsername() }, | ||
{ "accessKey", GetSauceAccessKey() } | ||
}; | ||
} | ||
|
||
public static string GetSauceUsername() | ||
{ | ||
var username = Environment.GetEnvironmentVariable("SAUCE_USERNAME"); | ||
if (string.IsNullOrEmpty(username)) | ||
{ | ||
throw new Exception("No SAUCE_USERNAME found"); | ||
} | ||
|
||
return username; | ||
} | ||
|
||
public static string GetSauceAccessKey() | ||
{ | ||
var accessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"); | ||
if (string.IsNullOrEmpty(accessKey)) | ||
{ | ||
throw new Exception("No SAUCE_ACCESS_KEY found"); | ||
} | ||
|
||
return accessKey; | ||
} | ||
|
||
public static string GetSauceRegion() | ||
{ | ||
var region = Environment.GetEnvironmentVariable("SAUCE_REGION"); | ||
if (string.IsNullOrEmpty(region)) | ||
{ | ||
return "us-west-1"; | ||
} | ||
|
||
return region; | ||
} | ||
|
||
public static Uri GetOnDemandURL() | ||
{ | ||
var regionName = GetSauceRegion(); | ||
var tld = regionName == "staging" ? "net" : "com"; | ||
return new Uri("https://ondemand." + regionName + ".saucelabs." + tld + "/wd/hub"); | ||
} | ||
|
||
public static DriverOptions GetBrowserOptions() | ||
{ | ||
var browser = Environment.GetEnvironmentVariable("BROWSER_NAME"); | ||
DriverOptions browserOptions = browser switch | ||
{ | ||
"Firefox" => new FirefoxOptions(), | ||
"Safari" => new SafariOptions(), | ||
_ => new ChromeOptions(), | ||
}; | ||
|
||
browserOptions.PlatformName = | ||
Environment.GetEnvironmentVariable("PLATFORM_NAME") ?? "Windows 11"; | ||
browserOptions.BrowserVersion = | ||
Environment.GetEnvironmentVariable("BROWSER_VERSION") ?? "latest"; | ||
return browserOptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters