Skip to content

Commit

Permalink
Merge branch 'main' into env-var-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed May 21, 2024
2 parents f517368 + 9ffe814 commit 574fdaf
Show file tree
Hide file tree
Showing 166 changed files with 28,089 additions and 127 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/js-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: JS (build)

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

defaults:
run:
working-directory: visual-js

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node 18
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Build with lerna
run: |
corepack enable
yarn install
npm run lint --workspaces --if-present
npm run build --workspaces --if-present
npm run test --workspaces --if-present
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
37 changes: 37 additions & 0 deletions .github/workflows/js-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: JS (release)

on:
workflow_dispatch: {}

defaults:
run:
working-directory: visual-js

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node 18
uses: actions/setup-node@v4
with:
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Setup Git
if: ${{ steps.prep.outputs.tag_name == '' }}
run: |
git config --global user.name "sauce-visual-bot"
git config --global user.email "[email protected]"
- name: Build
run: |
corepack enable
yarn install
npm run build --workspaces --if-present
- name: upgrade & publish version(s)
run: |
npx changeset version
npx changeset publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
- name: Push to git
run: git push --follow-tags
4 changes: 3 additions & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
with:
python-version: '3.10'
- name: Install Python build utilities
run: pip install -r requirements/build.txt
run: pip install -r requirements/dev.txt
- name: Build
run: python -m build
- name: Test
run: python -m pytest
4 changes: 3 additions & 1 deletion .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
with:
python-version: '3.10'
- name: Install Python build utilities
run: pip install -r requirements/build.txt
run: pip install -r requirements/dev.txt
- name: Build
run: python -m build
- name: Test
run: python -m pytest

pypi-publish:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ This repository contains the SDKs for Sauce Labs Visual.

- [C#](./visual-dotnet)
- [Java](./visual-java)
- [Python](./visual-python)
18 changes: 14 additions & 4 deletions visual-dotnet/SauceLabs.Visual/BuildFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ private static async Task<VisualBuild> FindBuildById(VisualApi api, string build
try
{
var build = (await api.Build(buildId)).EnsureValidResponse().Result;
if (build == null)
{
throw new VisualClientException($@"build {buildId} was not found");
}

return new VisualBuild(build.Id, build.Url, build.Mode);
}
catch (VisualClientException)
Expand All @@ -113,6 +118,11 @@ private static async Task<VisualBuild> FindBuildById(VisualApi api, string build
try
{
var build = (await api.BuildByCustomId(customId)).EnsureValidResponse().Result;
if (build == null)
{
throw new VisualClientException($@"build identified by {customId} was not found");
}

return new VisualBuild(build.Id, build.Url, build.Mode);
}
catch (VisualClientException)
Expand Down Expand Up @@ -144,10 +154,10 @@ private static async Task<VisualBuild> Create(VisualApi api, CreateBuildOptions
options.CustomId ??= EnvVars.CustomId;
var result = (await api.CreateBuild(new CreateBuildIn
{
Name = StringUtils.ValueOrDefault(EnvVars.BuildName, options.Name),
Project = StringUtils.ValueOrDefault(EnvVars.Project, options.Project),
Branch = StringUtils.ValueOrDefault(EnvVars.Branch, options.Branch),
DefaultBranch = StringUtils.ValueOrDefault(EnvVars.DefaultBranch, options.DefaultBranch),
Name = StringUtils.ValueOrDefault(options.Name, EnvVars.BuildName),
Project = StringUtils.ValueOrDefault(options.Project, EnvVars.Project),
Branch = StringUtils.ValueOrDefault(options.Branch, EnvVars.Branch),
DefaultBranch = StringUtils.ValueOrDefault(options.DefaultBranch, EnvVars.DefaultBranch),
CustomId = options.CustomId,
})).EnsureValidResponse();

Expand Down
11 changes: 9 additions & 2 deletions visual-dotnet/SauceLabs.Visual/FullPageConfig.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using SauceLabs.Visual.GraphQL;

Expand All @@ -6,15 +7,21 @@ namespace SauceLabs.Visual
public class FullPageConfig
{
public int? DelayAfterScrollMs { get; set; }
public bool? DisableCSSAnimation { get; set; }
public IEnumerable<string>? HideAfterFirstScroll { get; set; }
public bool? HideScrollBars { get; set; }
public int? ScrollLimit { get; set; }

internal FullPageConfigIn ToFullPageConfigIn()
{
return new FullPageConfigIn()
{
DelayAfterScrollMs = DelayAfterScrollMs,
HideAfterFirstScroll = HideAfterFirstScroll
DisableCSSAnimation = DisableCSSAnimation,
HideAfterFirstScroll = HideAfterFirstScroll,
HideScrollBars = HideScrollBars,
ScrollLimit = ScrollLimit
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class CreateSnapshotFromWebDriverIn
public string BuildUuid { get; }
[JsonProperty("diffingMethod")]
public DiffingMethod DiffingMethod { get; }
[JsonProperty("diffingOptions")]
public DiffingOptionsIn? DiffingOptions { get; set; }
[JsonProperty("ignoreRegions")]
public RegionIn[] IgnoreRegions { get; }
[JsonProperty("jobId")]
Expand Down Expand Up @@ -43,7 +45,8 @@ public CreateSnapshotFromWebDriverIn(
string? clipSelector,
string? suiteName,
string? testName,
FullPageConfigIn? fullPageConfig
FullPageConfigIn? fullPageConfig,
DiffingOptionsIn? diffingOptions
)
{
BuildUuid = buildUuid;
Expand All @@ -58,6 +61,7 @@ public CreateSnapshotFromWebDriverIn(
SuiteName = suiteName;
TestName = testName;
FullPageConfig = fullPageConfig;
DiffingOptions = diffingOptions;
}
}
}
30 changes: 30 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/DiffingOptionsIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Newtonsoft.Json;

namespace SauceLabs.Visual.GraphQL
{
public class DiffingOptionsIn
{
[JsonProperty("content")]
public bool Content { get; set; }
[JsonProperty("dimensions")]
public bool Dimensions { get; set; }
[JsonProperty("position")]
public bool Position { get; set; }
[JsonProperty("structure")]
public bool Structure { get; set; }
[JsonProperty("style")]
public bool Style { get; set; }
[JsonProperty("visual")]
public bool Visual { get; set; }

public DiffingOptionsIn(bool defaultValue)
{
Content = defaultValue;
Dimensions = defaultValue;
Position = defaultValue;
Structure = defaultValue;
Style = defaultValue;
Visual = defaultValue;
}
}
}
6 changes: 6 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/FullPageConfigIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ internal class FullPageConfigIn
{
[JsonProperty("delayAfterScrollMs")]
public int? DelayAfterScrollMs { get; set; }
[JsonProperty("disableCSSAnimation")]
public bool? DisableCSSAnimation { get; set; }
[JsonProperty("hideAfterFirstScroll")]
public IEnumerable<string>? HideAfterFirstScroll { get; set; }
[JsonProperty("hideScrollBars")]
public bool? HideScrollBars { get; set; }
[JsonProperty("scrollLimit")]
public int? ScrollLimit { get; set; }
}
}
19 changes: 19 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/RegionIn.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using OpenQA.Selenium;
using SauceLabs.Visual.Models;
using SauceLabs.Visual.Utils;

namespace SauceLabs.Visual.GraphQL
{
Expand All @@ -16,6 +17,8 @@ internal class RegionIn
public int Width { get; }
[JsonProperty("height")]
public int Height { get; }
[JsonProperty("diffingOptions")]
public DiffingOptionsIn? DiffingOptions { get; }

public RegionIn(int x, int y, int width, int height)
{
Expand All @@ -29,10 +32,26 @@ public RegionIn(string name, int x, int y, int width, int height) : this(x, y, w
Name = name;
}

public RegionIn(int x, int y, int width, int height, DiffingOptionsIn diffingOptions) : this(x, y, width, height)
{
DiffingOptions = diffingOptions;
}
public RegionIn(IWebElement input) : this(input.Location.X, input.Location.Y, input.Size.Width, input.Size.Height)
{ }

public RegionIn(IWebElement input, DiffingOptionsIn? options) : this(input.Location.X, input.Location.Y,
input.Size.Width, input.Size.Height)
{
DiffingOptions = options;
}

public RegionIn(IgnoreRegion input) : this(input.X, input.Y, input.Width, input.Height)
{ }

public RegionIn(SauceLabs.Visual.Models.Region input, DiffingOptionsIn? options) : this(input.X, input.Y, input.Width,
input.Height)
{
DiffingOptions = options;
}
}
}
3 changes: 2 additions & 1 deletion visual-dotnet/SauceLabs.Visual/Models/DiffingMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace SauceLabs.Visual.Models
public enum DiffingMethod
{
Simple,
Experimental
Experimental,
Balanced,
}
}
16 changes: 16 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/DiffingOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SauceLabs.Visual.Models
{
[Flags]
public enum DiffingOption
{
None = 0,
Content = 1 << 0,
Dimensions = 1 << 1,
Position = 1 << 2,
Structure = 1 << 3,
Style = 1 << 4,
Visual = 1 << 5,
}
}
18 changes: 18 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/Region.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SauceLabs.Visual.Models
{
public class Region
{
public int X { get; }
public int Y { get; }
public int Width { get; }
public int Height { get; }

public Region(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}
}
Loading

0 comments on commit 574fdaf

Please sign in to comment.