Skip to content

Commit f3f0f4f

Browse files
committed
Structure update, API tests added, CI/CD Setup
1 parent 60d211b commit f3f0f4f

File tree

10 files changed

+121
-8
lines changed

10 files changed

+121
-8
lines changed

.github/workflows/test.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Run .NET Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-and-test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Setup .NET
16+
uses: actions/setup-dotnet@v3
17+
with:
18+
dotnet-version: 8.0.x
19+
20+
- name: Restore dependencies
21+
run: dotnet restore
22+
23+
- name: Build project
24+
run: dotnet build --no-restore
25+
26+
- name: Run tests
27+
run: dotnet test --no-build --verbosity normal

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ obj/
5959
.idea
6060
.vscode
6161
.git
62+
63+
*.user

SeleniumTests/lib/config/Config.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace lib.config;
2+
3+
public static class Config
4+
{
5+
public static string BaseUrl => "https://demoqa.com";
6+
public static string ApiUrl => "https://demoqa.com";
7+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using lib.config;
2+
3+
namespace SeleniumTests.lib.helpers;
4+
5+
public class ApiClient
6+
{
7+
private readonly HttpClient _client = new();
8+
9+
public ApiClient()
10+
{
11+
_client.BaseAddress = new Uri(Config.ApiUrl);
12+
}
13+
14+
public async Task<string> GetBooks()
15+
{
16+
var response = await _client.GetAsync($"/BookStore/v1/Books");
17+
var book = await response.Content.ReadAsStringAsync();
18+
return book;
19+
}
20+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Text.Json;
2+
3+
namespace SeleniumTests.lib.helpers;
4+
5+
public static class JsonHelper
6+
{
7+
public static T Deserialize<T>(string json) =>
8+
JsonSerializer.Deserialize<T>(json)!;
9+
10+
public static string Serialize<T>(T obj) =>
11+
JsonSerializer.Serialize(obj);
12+
}

SeleniumTests/lib/models/BookDto.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace SeleniumTests.lib.models;
2+
3+
public class BookDto
4+
{
5+
public string isbn { get; set; }
6+
public string title { get; set; }
7+
public string subTitle { get; set; }
8+
public string author { get; set; }
9+
public string publish_date { get; set; }
10+
public string publisher { get; set; }
11+
public int pages { get; set; }
12+
public string description { get; set; }
13+
public string website { get; set; }
14+
}

SeleniumTests/lib/pages/HomePage.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using OpenQA.Selenium;
2+
using SeleniumTests.lib.selectors;
3+
4+
namespace SeleniumTests.lib.pages;
5+
6+
public class HomePage(IWebDriver driver)
7+
{
8+
public IWebElement Logo => driver.FindElement(By.CssSelector(HomePageSelectors.Logo));
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SeleniumTests.lib.selectors;
2+
3+
public static class HomePageSelectors
4+
{
5+
public const string Logo = "#app > header > a > img";
6+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using SeleniumTests.lib.helpers;
2+
3+
namespace SeleniumTests.tests;
4+
5+
public class ApiBookStoreTests
6+
{
7+
[Test]
8+
public async Task GetBooks_ShouldReturnBooksJson()
9+
{
10+
var api = new ApiClient();
11+
var books = await api.GetBooks();
12+
13+
Assert.That(books, Is.Not.Null);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using OpenQA.Selenium;
1+
using lib.config;
22
using OpenQA.Selenium.Chrome;
3+
using SeleniumTests.lib.pages;
34

4-
namespace SeleniumTests;
5+
namespace SeleniumTests.tests;
56

6-
public class HeaderLogoTest
7+
public class UiHomePageTests
78
{
89
private ChromeDriver?_driver;
910

@@ -15,12 +16,12 @@ public void Setup()
1516
}
1617

1718
[Test]
18-
public void Header_ShouldContain_Logo()
19+
public void HomePage_ShouldDisplay_Logo()
1920
{
20-
_driver!.Navigate().GoToUrl("https://demoqa.com");
21-
var logo = _driver.FindElement(By.XPath("//header/a/img"));
21+
_driver!.Navigate().GoToUrl(Config.BaseUrl);
22+
var homePage = new HomePage(_driver);
2223

23-
Assert.That(logo.Displayed, Is.True);
24+
Assert.That(homePage.Logo.Displayed, Is.True);
2425
}
2526

2627
[TearDown]
@@ -29,4 +30,4 @@ public void Teardown()
2930
_driver?.Quit();
3031
_driver?.Dispose();
3132
}
32-
}
33+
}

0 commit comments

Comments
 (0)