Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env var tests #32

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5be06b3
init
kb-kerem Apr 16, 2024
ba6f21d
try building test image
kb-kerem Apr 17, 2024
2f0c1f5
filter out java related stuff
kb-kerem Apr 18, 2024
c3c2292
filter out java related stuff
kb-kerem Apr 18, 2024
0934b18
filter out java related stuff
kb-kerem Apr 18, 2024
b9da636
fixes after review
kb-kerem Apr 19, 2024
8b8a746
fixes after review
kb-kerem Apr 19, 2024
4ce3465
try using github run id
kb-kerem Apr 19, 2024
0c545c8
dotnet
kb-kerem Apr 19, 2024
0f63c72
dotnet
kb-kerem Apr 19, 2024
e220b02
try using github run id
kb-kerem Apr 19, 2024
7a2c9d6
java test pipeline
kb-kerem Apr 19, 2024
a87c944
java test pipeline
kb-kerem Apr 19, 2024
9103d44
remove log
kb-kerem Apr 19, 2024
df7de3f
Merge branch 'testing-infra' into env-var-tests
kb-kerem Apr 19, 2024
d335b34
dotnet Dockerfile
kb-kerem Apr 19, 2024
5c1d8d3
close dotnet build
kb-kerem Apr 22, 2024
2ea1973
Merge branch 'main' into env-var-tests
kb-kerem Apr 22, 2024
f517368
add dotnet test to build pipeline
kb-kerem Apr 22, 2024
574fdaf
Merge branch 'main' into env-var-tests
kb-kerem May 21, 2024
6fa555f
py tests
kb-kerem May 21, 2024
d7aa2dd
Merge branch 'main' into env-var-tests
kb-kerem May 22, 2024
1914cfa
wdio tests
kb-kerem May 22, 2024
2465e4d
Merge branch 'main' into env-var-tests
kb-kerem May 22, 2024
4e9f596
wdio integration action
kb-kerem May 23, 2024
42a0fa2
wdio integration action
kb-kerem May 23, 2024
a4d8c72
wdio integration action
kb-kerem May 23, 2024
7d99fa8
wdio integration
kb-kerem May 23, 2024
cfccc2d
remove explicit wdio dependency
kb-kerem Jun 11, 2024
c2a52d9
Merge branch 'main' into env-var-tests
kb-kerem Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ jobs:
run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj --no-restore
- name: Test
run: dotnet test --verbosity normal

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push to local registry
uses: docker/build-push-action@v5
with:
context: '{{defaultContext}}:visual-dotnet'
tags: saucelabs/visual-dotnet
file: Dockerfile
load: true
- name: Run the integration tests
run: |
npm ci
npm run test
working-directory: tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
CONTAINER_IMAGE_NAME: saucelabs/visual-dotnet
24 changes: 24 additions & 0 deletions .github/workflows/java-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- 'visual-java/**'
- 'tests/**'
- .github/workflows/java-build.yml
pull_request:
paths:
Expand Down Expand Up @@ -36,3 +37,26 @@ jobs:
- name: Build and Lint with Maven
run: mvn -B verify --file pom.xml
if: matrix.version == '11'

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push to local registry
uses: docker/build-push-action@v5
with:
context: '{{defaultContext}}:visual-java'
tags: saucelabs/visual-java
file: Dockerfile
load: true
- name: Run the integration tests
run: |
npm ci
npm run test
working-directory: tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
CONTAINER_IMAGE_NAME: saucelabs/visual-java
41 changes: 41 additions & 0 deletions .github/workflows/wdio-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: wdio (integration test)

on:
push:
branches:
- main
paths:
- 'visual-js/visual-wdio/**'
- .github/workflows/js-build.yml
pull_request:
paths:
- 'visual-js/visual-wdio/**'
- .github/workflows/js-build.yml

defaults:
run:
working-directory: visual-js/visual-wdio

jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push to local registry
uses: docker/build-push-action@v5
with:
context: '{{defaultContext}}:visual-js/visual-wdio'
tags: saucelabs/visual-wdio
file: Dockerfile
load: true
- name: Run the integration tests
run: |
npm ci
npm run test
working-directory: tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
CONTAINER_IMAGE_NAME: saucelabs/visual-wdio
2 changes: 1 addition & 1 deletion tests/env-vars-custom-id.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildMode, BuildStatus, SauceRegion, getApi } from '@saucelabs/visual';
import { BuildStatus, SauceRegion, getApi } from '@saucelabs/visual';
import {
RE_VISUAL_BUILD_ID,
RE_VISUAL_BUILD_LINK,
Expand Down
11 changes: 11 additions & 0 deletions visual-dotnet/Dockerfile
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"]
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 visual-dotnet/SauceLabs.Visual.IntegrationTests/LoginPage.cs
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();
}
}
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>
77 changes: 77 additions & 0 deletions visual-dotnet/SauceLabs.Visual.IntegrationTests/Utils.cs
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;
}
}
6 changes: 6 additions & 0 deletions visual-dotnet/SauceLabs.Visual.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SauceLabs.Visual", "SauceLa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SauceLabs.Visual.Tests", "SauceLabs.Visual.Tests\SauceLabs.Visual.Tests.csproj", "{6D07FB36-1E01-4D6A-853F-E1548DBE234C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SauceLabs.Visual.IntegrationTests", "SauceLabs.Visual.IntegrationTests\SauceLabs.Visual.IntegrationTests.csproj", "{77A9E41F-CBB4-4E52-A3CE-8131E59B379D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{6D07FB36-1E01-4D6A-853F-E1548DBE234C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D07FB36-1E01-4D6A-853F-E1548DBE234C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D07FB36-1E01-4D6A-853F-E1548DBE234C}.Release|Any CPU.Build.0 = Release|Any CPU
{77A9E41F-CBB4-4E52-A3CE-8131E59B379D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77A9E41F-CBB4-4E52-A3CE-8131E59B379D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77A9E41F-CBB4-4E52-A3CE-8131E59B379D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77A9E41F-CBB4-4E52-A3CE-8131E59B379D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 13 additions & 0 deletions visual-java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM eclipse-temurin:11-jdk-alpine AS runner

RUN mkdir -p /workspace
WORKDIR /workspace

COPY ./.mvn /workspace/.mvn
COPY ./src /workspace/src
COPY ./pom.xml /workspace/
COPY ./mvnw /workspace/

RUN ./mvnw -q clean test-compile

ENTRYPOINT ["./mvnw", "-q", "test" ,"-Dtest=com.saucelabs.visual.integration.**"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.saucelabs.visual.integration;

import com.saucelabs.saucebindings.SaucePlatform;
import com.saucelabs.saucebindings.UnhandledPromptBehavior;
import com.saucelabs.saucebindings.junit5.SauceBaseTest;
import com.saucelabs.saucebindings.options.SauceOptions;
import com.saucelabs.visual.DataCenter;
import com.saucelabs.visual.VisualApi;
import com.saucelabs.visual.junit5.TestMetaInfoExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith({TestMetaInfoExtension.class})
class LoginPageIT extends SauceBaseTest {

public SauceOptions createSauceOptions() {
return SauceOptions.chrome()
.setPlatformName(SaucePlatform.WINDOWS_10)
.setUnhandledPromptBehavior(UnhandledPromptBehavior.IGNORE)
.setScreenResolution("1920x1080")
.build();
}

@Test
void checkLoginPage() {
VisualApi visual =
new VisualApi(
driver,
DataCenter.US_WEST_1,
System.getenv("SAUCE_USERNAME"),
System.getenv("SAUCE_ACCESS_KEY"));
driver.get("https://www.saucedemo.com");
visual.sauceVisualCheck("Login page");
System.out.println("Sauce Visual: " + visual.getBuild().getUrl());
}
}
13 changes: 13 additions & 0 deletions visual-js/visual-wdio/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18 AS runner

COPY ./integration-tests/configs ./configs
COPY ./integration-tests/helpers ./helpers
COPY ./integration-tests/pages ./pages
COPY ./integration-tests/specs ./specs

COPY ./integration-tests/package.json ./
COPY ./integration-tests/tsconfig.json ./

RUN npm install

ENTRYPOINT ["npm", "run", "login-test"]
Loading
Loading