Skip to content

Commit a3c7a80

Browse files
committed
Account Summary page and tests + WebDriverFactory
1 parent 6c2fea8 commit a3c7a80

4 files changed

Lines changed: 130 additions & 21 deletions

File tree

Pages/AccountSummaryPage.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace CSharpSeleniumFramework.Pages
66

77
public class AccountSummaryPage : BasePage
88
{
9-
109
public AccountSummaryPage(IWebDriver driver) : base(driver) { }
1110

1211
public void VerifyAllSectionHeadersDisplayed()
@@ -18,5 +17,16 @@ public void VerifyAllSectionHeadersDisplayed()
1817
Assert.That(element.Displayed);
1918
}
2019
}
20+
21+
public string GetThXPath(IWebDriver driver, int boardIndex, int thIndex)
22+
{
23+
string xpath = $"(//div[@class='board-content'])[{boardIndex}]//table//th[{thIndex}]";
24+
return xpath = driver.FindElement(By.XPath(xpath)).Text;
25+
}
26+
27+
public string GetTdXpath(IWebDriver driver, int boardIndex, int tdIndex){
28+
string xpath = $"(//div[@class='board-content'])[{boardIndex}]//table//td[{tdIndex}]";
29+
return xpath = driver.FindElement(By.XPath(xpath)).Text;
30+
}
2131
}
2232
}

Tests/AccountSummaryTest.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,61 @@ public override void Setup()
2323
_loginPage.Login(username, password);
2424
_loginPage.ByPassSSLCertIssue();
2525
_homePage.ClickCheckingAccountActivityLink();
26+
_accountActivityPage.ClickAccountSummaryLink();
2627
}
2728

2829
[Test]
2930
[AllureFeature("Account Summary")]
3031
[AllureStory("Check all sections displayed on the page")]
3132
public void CheckSectionsDisplayed()
3233
{
33-
_accountActivityPage.ClickAccountSummaryLink();
34+
3435
_accountSummaryPage.VerifyAllSectionHeadersDisplayed();
3536
}
37+
38+
[Test]
39+
[AllureFeature("Account Summary")]
40+
[AllureStory("Check all table headers are displayed on the page")]
41+
public void CheckSectionTableHeaders()
42+
{
43+
var expectedValues = new (int board, int column, string expectedText)[]
44+
{
45+
(1, 1, "Account"),
46+
(1, 3, "Balance"),
47+
(2, 1, "Account"),
48+
(2, 3, "Balance"),
49+
(3, 1, "Account"),
50+
(3, 2, "Credit Card"),
51+
(3, 3, "Balance"),
52+
(4, 1, "Account"),
53+
(4, 3, "Balance")
54+
};
55+
56+
foreach (var (board, column, expectedText) in expectedValues)
57+
{
58+
var actualText = _accountSummaryPage.GetThXPath(_driver, board, column);
59+
Assert.That(actualText, Is.EqualTo(expectedText),
60+
$"Failed on board {board}, column {column}");
61+
}
62+
}
63+
64+
[Test]
65+
[AllureFeature("Account Summary")]
66+
[AllureStory("Check all table data matches expected")]
67+
public void CheckSectionTableData()
68+
{
69+
var expectedValues = new (int board, int column, string expectedText)[]
70+
{
71+
(1, 1, "Savings"),
72+
(1, 3, "$1000.9")
73+
};
74+
75+
foreach (var (board, column, expectedText) in expectedValues)
76+
{
77+
var actualText = _accountSummaryPage.GetTdXpath(_driver, board, column);
78+
Assert.That(actualText, Is.EqualTo(expectedText),
79+
$"Failed on board {board}, column {column}");
80+
}
81+
}
3682
}
3783
}

Tests/BaseTest.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,13 @@ public class BaseTest
2323
[SetUp]
2424
public virtual void Setup()
2525
{
26-
var options = new ChromeOptions();
27-
options.AddArguments(
28-
"--headless=new", // Use new headless mode (Chrome 109+)
29-
"--disable-gpu", // Disable GPU (helps in headless mode)
30-
"--window-size=1280x1024", // Ensure proper viewport size
31-
"--no-sandbox", // Bypass OS security restrictions (needed in CI/CD)
32-
"--disable-dev-shm-usage", // Prevents crashes in Docker/Linux environments
33-
"--disable-blink-features=AutomationControlled", // Reduces bot detection
34-
"--disable-extensions", // Ensures no unwanted browser extensions
35-
"--disable-popup-blocking", // Prevents unexpected popups
36-
"--remote-debugging-port=9222" // Useful for debugging headless runs
37-
);
38-
39-
_driver = new ChromeDriver(options);
40-
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); // Global implicit wait
26+
_driver = WebDriverFactory.CreateDriver(browser: "firefox", headless: true);
27+
InitPages();
28+
_basePage.VisitSite();
29+
}
4130

31+
private void InitPages()
32+
{
4233
_basePage = new BasePage(_driver);
4334
_homePage = new HomePage(_driver);
4435
_loginPage = new LoginPage(_driver);
@@ -47,10 +38,6 @@ public virtual void Setup()
4738
_accountActivityPage = new AccountActivityPage(_driver);
4839
_payBillsPage = new PayBillsPage(_driver);
4940
_accountSummaryPage = new AccountSummaryPage(_driver);
50-
_driver.Manage().Window.Maximize();
51-
52-
//Visit the application
53-
_basePage.VisitSite();
5441
}
5542

5643
[TearDown]

Utils/WebDriverFactory.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Chrome;
3+
using OpenQA.Selenium.Firefox;
4+
using OpenQA.Selenium.Edge;
5+
using System;
6+
7+
namespace CSharpSeleniumFramework.Utils
8+
{
9+
public static class WebDriverFactory
10+
{
11+
public static IWebDriver CreateDriver(string browser = "chrome", bool headless = false)
12+
{
13+
IWebDriver driver;
14+
15+
switch (browser.ToLower())
16+
{
17+
case "chrome":
18+
var chromeOptions = new ChromeOptions();
19+
20+
if (headless)
21+
{
22+
chromeOptions.AddArguments(
23+
"--headless=new",
24+
"--disable-gpu",
25+
"--window-size=1280x1024",
26+
"--no-sandbox",
27+
"--disable-dev-shm-usage",
28+
"--disable-blink-features=AutomationControlled",
29+
"--disable-extensions",
30+
"--disable-popup-blocking"
31+
);
32+
}
33+
34+
driver = new ChromeDriver(chromeOptions);
35+
break;
36+
37+
case "firefox":
38+
var firefoxOptions = new FirefoxOptions();
39+
if (headless)
40+
{
41+
firefoxOptions.AddArgument("--headless");
42+
}
43+
44+
driver = new FirefoxDriver(firefoxOptions);
45+
break;
46+
47+
case "edge":
48+
var edgeOptions = new EdgeOptions();
49+
if (headless)
50+
{
51+
edgeOptions.AddArgument("--headless=new");
52+
}
53+
54+
driver = new EdgeDriver(edgeOptions);
55+
break;
56+
57+
default:
58+
throw new ArgumentException($"Unsupported browser: {browser}");
59+
}
60+
61+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
62+
driver.Manage().Window.Maximize();
63+
return driver;
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)