Skip to content

Commit f7124eb

Browse files
committed
2 parents 219bebe + 2c44b91 commit f7124eb

File tree

18 files changed

+250
-67
lines changed

18 files changed

+250
-67
lines changed

src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ public void CreateUserAndApplication(out int accountId, out int applicationId)
109109
}
110110
}
111111

112+
public void CreateUser(TestUser testUser, int applicationId)
113+
{
114+
using (var uow = CreateUnitOfWork())
115+
{
116+
var accountRepos = new AccountRepository(uow);
117+
var account = new Account(testUser.Username, testUser.Password) { Email = testUser.Email };
118+
account.Activate();
119+
accountRepos.Create(account);
120+
var userRepos = new UserRepository(uow);
121+
var user = new User(account.Id, testUser.Username) { EmailAddress = testUser.Email };
122+
userRepos.CreateAsync(user).GetAwaiter().GetResult();
123+
124+
var appRepos = new ApplicationRepository(uow);
125+
var member = new ApplicationTeamMember(applicationId, account.Id, "Admin");
126+
appRepos.CreateAsync(member).GetAwaiter().GetResult();
127+
128+
uow.SaveChanges();
129+
}
130+
}
131+
112132
private void EnsureServerSettings(string baseUrl)
113133
{
114134
using (var con = _connectionFactory())
Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
11
using System;
22
using OpenQA.Selenium;
33
using OpenQA.Selenium.Support.UI;
4-
using Xunit.Sdk;
54

65
namespace codeRR.Server.Web.Tests.Helpers.Extensions
76
{
87
public static class WebDriverExtensions
98
{
10-
public static bool ElementIsPresent(this IWebDriver driver, By by)
11-
{
12-
var present = false;
13-
try
14-
{
15-
present = driver.FindElement(by).Displayed;
16-
}
17-
catch (NoSuchElementException)
18-
{
19-
}
20-
return present;
21-
}
22-
23-
public static bool ElementIsPresent(this IWebDriver driver, IWebElement element)
24-
{
25-
var present = false;
26-
try
27-
{
28-
present = element.Displayed;
29-
}
30-
catch (NoSuchElementException)
31-
{
32-
}
33-
return present;
34-
}
35-
369
public static bool WaitUntilElementIsPresent(this IWebDriver driver, By by, int timeout = 5)
3710
{
3811
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
@@ -59,5 +32,31 @@ public static string WaitUntilTitleEquals(this IWebDriver driver, string title,
5932

6033
return driver.Title;
6134
}
35+
36+
private static bool ElementIsPresent(this IWebDriver driver, By by)
37+
{
38+
var present = false;
39+
try
40+
{
41+
present = driver.FindElement(by).Displayed;
42+
}
43+
catch (NoSuchElementException)
44+
{
45+
}
46+
return present;
47+
}
48+
49+
private static bool ElementIsPresent(this IWebDriver driver, IWebElement element)
50+
{
51+
var present = false;
52+
try
53+
{
54+
present = element.Displayed;
55+
}
56+
catch (NoSuchElementException)
57+
{
58+
}
59+
return present;
60+
}
6261
}
6362
}

src/Server/Coderr.Server.Web.Tests/Pages/Account/ActivationRequestedPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
55
{
66
public class ActivationRequestedPage : BasePage
77
{
8-
public ActivationRequestedPage(IWebDriver webDriver) : base(webDriver, (string) "Account/ActivationRequested", (string) "Account registered - codeRR")
8+
public ActivationRequestedPage(IWebDriver webDriver) : base(webDriver, "Account/ActivationRequested", "Account registered - codeRR")
99
{
1010
}
1111

src/Server/Coderr.Server.Web.Tests/Pages/Account/LoginPage.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
66
{
77
public class LoginPage : BasePage
88
{
9-
public LoginPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Login", (string) "Login - codeRR")
9+
public LoginPage(IWebDriver webDriver) : base(webDriver, "Account/Login", "Login - codeRR")
1010
{
1111
}
1212

@@ -19,19 +19,19 @@ public LoginPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Login
1919
[FindsBy(How = How.Id, Using = "Password")]
2020
public IWebElement PasswordField { get; set; }
2121

22-
public HomePage LoginWithValidCredentials()
22+
public IPage LoginWithValidCredentials(string userName, string password)
2323
{
2424
NavigateToPage();
2525

2626
UserNameField.Clear();
27-
UserNameField.SendKeys(TestUser.Username);
27+
UserNameField.SendKeys(userName);
2828

2929
PasswordField.Clear();
30-
PasswordField.SendKeys(TestUser.Password);
30+
PasswordField.SendKeys(password);
3131

3232
SignInButton.Click();
3333

34-
return new HomePage(WebDriver);
34+
return PageHelper.ResolvePage(WebDriver);
3535
}
3636

3737
public LoginPage LoginWithNonExistingUserWithoutPasswordSpecified()

src/Server/Coderr.Server.Web.Tests/Pages/Account/LogoutPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
44
{
55
public class LogoutPage : BasePage
66
{
7-
public LogoutPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Logout", (string) "")
7+
public LogoutPage(IWebDriver webDriver) : base(webDriver, "Account/Logout", "")
88
{
99
}
1010

src/Server/Coderr.Server.Web.Tests/Pages/Account/RegisterPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
77
{
88
public class RegisterPage : BasePage
99
{
10-
public RegisterPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Register", (string) "Register account - codeRR")
10+
public RegisterPage(IWebDriver webDriver) : base(webDriver, "Account/Register", "Register account - codeRR")
1111
{
1212
}
1313

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Support.PageObjects;
3+
using OpenQA.Selenium.Support.UI;
4+
5+
namespace codeRR.Server.Web.Tests.Pages
6+
{
7+
public class ApplicationPage : BasePage
8+
{
9+
public ApplicationPage(IWebDriver webDriver, int id) : base(webDriver, "#/application/{id}", "")
10+
{
11+
Url = Url.Replace("{id}", id.ToString());
12+
}
13+
14+
[FindsBy(How = How.Id, Using = "pageTitle")]
15+
public IWebElement PageTitle { get; set; }
16+
17+
public void VerifyIsCurrentPage()
18+
{
19+
Wait.Until(ExpectedConditions.TitleIs(Title));
20+
}
21+
22+
public void VerifyIncidentReported()
23+
{
24+
var by = By.PartialLinkText("Value cannot be null");
25+
//var element = WebDriver.FindElement(by);
26+
Wait.Until(ExpectedConditions.ElementExists(by));
27+
}
28+
}
29+
}

src/Server/Coderr.Server.Web.Tests/Pages/BasePage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace codeRR.Server.Web.Tests.Pages
88
{
9-
public class BasePage
9+
public class BasePage : IPage
1010
{
1111
protected IWebDriver WebDriver;
1212
protected WebDriverWait Wait;
1313
protected string BaseUrl { get; }
14-
protected string Url { get; set; }
14+
public string Url { get; set; }
1515
public string Title { get; }
1616

1717
protected readonly TestUser TestUser = WebTest.TestUser;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace codeRR.Server.Web.Tests.Pages
2+
{
3+
public interface IPage
4+
{
5+
string Url { get; set; }
6+
string Title { get; }
7+
}
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
using codeRR.Server.Web.Tests.Pages.Account;
4+
using OpenQA.Selenium;
5+
6+
namespace codeRR.Server.Web.Tests.Pages
7+
{
8+
public class PageHelper
9+
{
10+
public static IPage ResolvePage(IWebDriver webDriver)
11+
{
12+
var match = Regex.Match(webDriver.Url, @"/#/$", RegexOptions.IgnoreCase);
13+
if (match.Success)
14+
return new HomePage(webDriver);
15+
match = Regex.Match(webDriver.Url, @"/Account/Login", RegexOptions.IgnoreCase);
16+
if (match.Success)
17+
return new LoginPage(webDriver);
18+
match = Regex.Match(webDriver.Url, @"/#/application/(\d+)", RegexOptions.IgnoreCase);
19+
if(match.Success)
20+
return new ApplicationPage(webDriver, Convert.ToInt16(match.Groups[1].Value));
21+
22+
throw new ArgumentOutOfRangeException($"Url: {webDriver.Url}, Title: {webDriver.Title}");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)