Skip to content

Commit 28e2b7f

Browse files
authored
Merge pull request #9 from Artem-applitools/master
Add github actions
2 parents 8a3c3ac + 4255e92 commit 28e2b7f

File tree

4 files changed

+128
-66
lines changed

4 files changed

+128
-66
lines changed

.github/workflows/tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: 3.1.x
23+
- name: Restore dependencies
24+
run: dotnet restore
25+
- name: Build
26+
run: dotnet build --no-restore
27+
- name: Test
28+
run: dotnet test --no-build --verbosity normal

.github/workflows/updates.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Update
2+
3+
on:
4+
schedule:
5+
- cron: "0 12 * * *"
6+
workflow_dispatch:
7+
8+
env:
9+
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: 3.1.x
22+
23+
- name: Update dependencies
24+
run: |
25+
dotnet remove ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package Eyes.Selenium
26+
dotnet remove ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package Microsoft.NET.Test.Sdk
27+
dotnet remove ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package NUnit
28+
dotnet remove ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package NUnit3TestAdapter
29+
dotnet add ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package Eyes.Selenium
30+
dotnet add ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package Microsoft.NET.Test.Sdk
31+
dotnet add ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package NUnit
32+
dotnet add ./ApplitoolsTutorial/ApplitoolsTutorial.csproj package NUnit3TestAdapter
33+
34+
- name: Build
35+
run: dotnet build
36+
37+
- name: Test
38+
run: dotnet test --no-build --verbosity normal
39+
40+
- uses: mikeal/publish-to-github-action@master
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
BRANCH_NAME: 'master'

ApplitoolsTutorial/ApplitoolsTutorial.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Eyes.Selenium" Version="*" />
11+
<Folder Include="Properties\" />
1212
</ItemGroup>
1313

14-
<ItemGroup>
15-
<Folder Include="Properties\" />
14+
<ItemGroup>
15+
<PackageReference Include="Eyes.Selenium" Version="2.49.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
17+
<PackageReference Include="NUnit" Version="3.13.2" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
1619
</ItemGroup>
1720

1821
</Project>

ApplitoolsTutorial/UFGDemo.cs

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Applitools;
22
using Applitools.Selenium;
33
using Applitools.VisualGrid;
4+
using NUnit.Framework;
45
using OpenQA.Selenium;
56
using OpenQA.Selenium.Chrome;
67
using System;
@@ -10,45 +11,35 @@
1011

1112
namespace ApplitoolsTutorial
1213
{
14+
[TestFixture]
1315
public class UFGDemo
1416
{
15-
16-
public static void Main(string[] args)
17-
{
18-
// Create a new chrome web driver
19-
IWebDriver webDriver = new ChromeDriver();
20-
21-
// Create a runner with concurrency of 1
22-
VisualGridRunner runner = new VisualGridRunner(new RunnerOptions().TestConcurrency(1));
23-
17+
private EyesRunner runner;
18+
private Eyes eyes;
19+
private IWebDriver driver;
20+
21+
[SetUp]
22+
public void BeforeEach() {
23+
var CI = Environment.GetEnvironmentVariable("CI");
24+
var options = new ChromeOptions();
25+
if(CI != null) {
26+
options.AddArguments("headless");
27+
}
28+
// Use Chrome browser
29+
driver = new ChromeDriver(options);
30+
31+
//Initialize the Runner for your test with concurrency of 5.
2432
// Create Eyes object with the runner, meaning it'll be a Visual Grid eyes.
25-
Eyes eyes = new Eyes(runner);
26-
27-
SetUp(eyes);
33+
runner = new VisualGridRunner(new RunnerOptions().TestConcurrency(5));
2834

29-
try
30-
{
31-
// ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
32-
// but then change the above URL to https://demo.applitools.com/index_v2.html
33-
// (for the 2nd run)
34-
UltraFastTest(webDriver, eyes);
35-
36-
}
37-
finally
38-
{
39-
TearDown(webDriver, runner);
40-
}
41-
42-
}
43-
44-
public static void SetUp(Eyes eyes)
45-
{
35+
// Initialize the eyes SDK (IMPORTANT: make sure your API key is set in the APPLITOOLS_API_KEY env variable).
36+
eyes = new Eyes(runner);
4637

4738
// Initialize eyes Configuration
4839
Configuration config = new Configuration();
4940

5041
// You can get your api key from the Applitools dashboard
51-
config.SetApiKey("APPLITOOLS_API_KEY");
42+
config.SetApiKey(Environment.GetEnvironmentVariable("APPLITOOLS_API_KEY"));
5243

5344
// create a new batch info instance and set it to the configuration
5445
config.SetBatch(new BatchInfo("Ultrafast Batch"));
@@ -69,47 +60,44 @@ public static void SetUp(Eyes eyes)
6960

7061
}
7162

72-
public static void UltraFastTest(IWebDriver webDriver, Eyes eyes)
73-
{
74-
75-
try
76-
{
77-
78-
// Navigate to the url we want to test
79-
webDriver.Url = "https://demo.applitools.com";
63+
[Test]
64+
public void UFGTest(){
65+
// Start the test by setting AUT's name, window or the page name that's being tested, viewport width and height
66+
eyes.Open(driver, "Demo App - csharp ufg", "Smoke Test", new Size(800, 600));
8067

81-
// Call Open on eyes to initialize a test session
82-
eyes.Open(webDriver, "Demo App - csharp", "Ultrafast grid demo", new Size(800, 600));
68+
// Navigate the browser to the "ACME" demo app. To see visual bugs after the first run, use the commented line below instead.
69+
driver.Url = "https://demo.applitools.com/";
70+
//driver.Url = "https://demo.applitools.com/index_v2.html";
8371

84-
// check the login page with fluent api, see more info here
85-
// https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html
86-
eyes.Check(Target.Window().Fully().WithName("Login page"));
72+
// Visual checkpoint #1 - Check the login page. using the fluent API
73+
// https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html?Highlight=fluent%20api
74+
eyes.Check(Target.Window().Fully().WithName("Login Window"));
8775

88-
webDriver.FindElement(By.Id("log-in")).Click();
76+
// This will create a test with two test steps.
77+
driver.FindElement(By.Id("log-in")).Click();
78+
79+
// Visual checkpoint #2 - Check the app page.
80+
eyes.Check(Target.Window().Fully().WithName("App Window"));
8981

90-
// Check the app page
91-
eyes.Check(Target.Window().Fully().WithName("App page"));
92-
93-
// Call Close on eyes to let the server know it should display the results
94-
eyes.CloseAsync();
82+
// End the test.
83+
eyes.CloseAsync();
84+
}
9585

96-
}
97-
catch (Exception e)
98-
{
99-
eyes.AbortAsync();
100-
}
86+
[TearDown]
87+
public void AfrerEach(){
88+
// Close the browser.
89+
driver.Quit();
10190

102-
}
91+
// If the test was aborted before eyes.close was called, ends the test as aborted.
92+
eyes.AbortIfNotClosed();
10393

104-
private static void TearDown(IWebDriver webDriver, VisualGridRunner runner)
105-
{
106-
// Close the browser
107-
webDriver.Quit();
94+
//Wait and collect all test results
95+
// we pass false to this method to suppress the exception that is thrown if we
96+
// find visual differences
97+
TestResultsSummary allTestResults = runner.GetAllTestResults();
10898

109-
// we pass false to this method to suppress the exception that is thrown if we
110-
// find visual differences
111-
TestResultsSummary allTestResults = runner.GetAllTestResults();
112-
System.Console.WriteLine(allTestResults);
99+
// Print results
100+
Console.WriteLine(allTestResults);
113101
}
114102

115103
}

0 commit comments

Comments
 (0)