Skip to content

Commit d5b9d65

Browse files
committed
Added headless mode for CI/CD
1 parent bed94eb commit d5b9d65

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

.github/workflows/test.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ jobs:
88
build-and-test:
99
runs-on: ubuntu-latest
1010

11+
env:
12+
CI: true
13+
1114
steps:
1215
- name: Checkout code
1316
uses: actions/checkout@v3

SeleniumTests/lib/base/UiTestBase.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using SeleniumTests.lib.config;
2+
using OpenQA.Selenium.Chrome;
3+
4+
namespace SeleniumTests.lib.Base;
5+
6+
public abstract class UiTestBase
7+
{
8+
private ChromeDriver?_driver;
9+
10+
[SetUp]
11+
public void Setup()
12+
{
13+
var options = new ChromeOptions();
14+
15+
if (Config.IsCi)
16+
{
17+
options.AddArgument("--headless=new");
18+
options.AddArgument("--disable-gpu");
19+
options.AddArgument("--no-sandbox");
20+
options.AddArgument("--disable-dev-shm-usage");
21+
}
22+
23+
_driver = new ChromeDriver(options);
24+
_driver.Manage().Window.Maximize();
25+
}
26+
27+
[TearDown]
28+
public void Teardown()
29+
{
30+
_driver?.Quit();
31+
_driver?.Dispose();
32+
}
33+
}

SeleniumTests/lib/config/Config.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
namespace lib.config;
1+
namespace SeleniumTests.lib.config;
22

33
public static class Config
44
{
5-
public static string BaseUrl => "https://demoqa.com";
5+
public static string BaseUrl =>
6+
Environment.GetEnvironmentVariable("BASE_URL") ?? "https://demoqa.com";
7+
8+
public static bool IsCi =>
9+
Environment.GetEnvironmentVariable("CI")?.ToLower() == "true";
10+
611
public static string ApiUrl => "https://demoqa.com";
12+
713
}

SeleniumTests/lib/helpers/ApiClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using lib.config;
1+
using SeleniumTests.lib.config;
22

33
namespace SeleniumTests.lib.helpers;
44

SeleniumTests/tests/UiHomePageTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using lib.config;
1+
using SeleniumTests.lib.config;
22
using OpenQA.Selenium.Chrome;
33
using SeleniumTests.lib.pages;
44

0 commit comments

Comments
 (0)