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

ci adjustments #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions .github/workflows/TestProjectWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'

- name: Install Chrome dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget unzip xvfb libxi6 libgconf-2-4
sudo apt-get install -y google-chrome-stable
google-chrome --version
which google-chrome

- name: Set up display
run: |
export DISPLAY=:99
Xvfb :99 -ac &

- name: Restore dependencies
run: dotnet restore
Expand Down
19 changes: 19 additions & 0 deletions TestProject/TestProject/Core/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public static string BrowserType = GetAppSettingsValue("BrowserType", "Chrome");
public static string AppUrl = GetAppSettingsValue("ApplicationUrl", string.Empty);
public static string TestDataPath = GetAppSettingsValue("TestDataPath", string.Empty);
public static bool Headless = GetAppSettingsBoolValue("Headless", false);

public static string GetAppSettingsValue(string value, string defaultValue)
{
Expand All @@ -18,5 +19,23 @@

return configuration[$"{value}"] ?? defaultValue;
}

private static bool GetAppSettingsBoolValue(string value, bool defaultValue)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

IConfigurationRoot configuration = builder.Build();

string configValue = configuration[$"{value}"];

Check warning on line 31 in TestProject/TestProject/Core/Configuration.cs

View workflow job for this annotation

GitHub Actions / Build and tests

Converting null literal or possible null value to non-nullable type.

if (bool.TryParse(configValue, out bool result))
{
return result;
}

return defaultValue;
}
}
}
26 changes: 22 additions & 4 deletions TestProject/TestProject/Core/WebDriver/WebDriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,38 @@
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using TestProject.Core;

namespace TestProject.WebDriver
{
public static class WebDriverFactory
{
public static IWebDriver CreateWebDriver(BrowserType browserType)
{
public static IWebDriver CreateWebDriver()
{
/* TODO: @Aleh or @Valiantsina,
* please take a look on this condition, just took browser from configuration, and as out param we are getting enum.
*/
if (!Enum.TryParse(Configuration.BrowserType, true, out BrowserType browserType))
{
throw new ArgumentException($"Unsupported browser type: {Configuration.BrowserType}");
}

switch (browserType)
{
case BrowserType.Chrome:
{
var service = ChromeDriverService.CreateDefaultService();
ChromeOptions options = new ChromeOptions();
ChromeOptions options = new();
options.AddArgument("--no-sandbox");
options.AddArgument("disable-infobars");
options.AddArgument("--incognito");
options.AddArgument("--disable-dev-shm-usage");

// Add headless run option
if (Configuration.Headless)
{
options.AddArgument("--headless");
}
return new ChromeDriver(service, options, TimeSpan.FromSeconds(30));
}
case BrowserType.Edge:
Expand All @@ -28,10 +45,11 @@ public static IWebDriver CreateWebDriver(BrowserType browserType)
}
}
}

public enum BrowserType
{
Chrome,
Edge,
Firefox
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public partial class WebDriverWrapper

private const int WaitTimeInSeconds = 10;

public WebDriverWrapper(BrowserType browserType)
public WebDriverWrapper()
{
_driver = WebDriverFactory.CreateWebDriver(browserType);
_driver = WebDriverFactory.CreateWebDriver();
_timeout = TimeSpan.FromSeconds(WaitTimeInSeconds);
}

Expand Down
1 change: 0 additions & 1 deletion TestProject/TestProject/TestProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Selenium.Support" Version="4.22.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.22.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="126.0.6478.12600" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
8 changes: 2 additions & 6 deletions TestProject/TestProject/Tests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
using NUnit.Framework;
using TestProject.Core;
using TestProject.Core.WebDriver;
using TestProject.WebDriver;

namespace TestProject.TestsUI
{
public abstract class BaseTest
{
protected WebDriverWrapper WebDriverWrapper { get; private set; }

Check warning on line 9 in TestProject/TestProject/Tests/BaseTest.cs

View workflow job for this annotation

GitHub Actions / Build and tests

Non-nullable property 'WebDriverWrapper' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
protected Logger Logger { get; private set; }

Check warning on line 10 in TestProject/TestProject/Tests/BaseTest.cs

View workflow job for this annotation

GitHub Actions / Build and tests

Non-nullable property 'Logger' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[SetUp]
public virtual void SetUp()
{
var browserType = (BrowserType)Enum.Parse(typeof(BrowserType),
Configuration.BrowserType);

WebDriverWrapper = new WebDriverWrapper(browserType);
WebDriverWrapper = new WebDriverWrapper();
WebDriverWrapper.StartBrowser();
WebDriverWrapper.NavigateTo(Configuration.AppUrl);

Logger = Logger ?? new Logger();
Logger ??= new Logger();
}

[TearDown]
Expand Down
3 changes: 2 additions & 1 deletion TestProject/TestProject/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"BrowserType": "Chrome",
"ApplicationUrl": "https://www.epam.com",
"TestDataPath": "Data\\TestData.json"
"TestDataPath": "Data/TestData.json",
"Headless": true
}
Loading