Skip to content

Commit bb8d5ae

Browse files
authored
Merge pull request #57 from mjohanss/master
Using correct environment variable to detect if being run by a build …
2 parents 9f1e37d + 3bd5de3 commit bb8d5ae

File tree

14 files changed

+320
-27
lines changed

14 files changed

+320
-27
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using codeRR.Server.SqlServer.Core.Accounts;
1313
using codeRR.Server.SqlServer.Core.Applications;
1414
using codeRR.Server.SqlServer.Core.Users;
15+
using codeRR.Server.SqlServer.Tests.Models;
1516
using Coderr.Server.PluginApi.Config;
1617
using Griffin.Data;
1718
using Griffin.Data.Mapper;
@@ -38,6 +39,8 @@ public TestDataManager(Func<IDbConnection> connectionFactory)
3839
/// </remarks>
3940
public int AccountId { get; private set; }
4041

42+
public TestUser TestUser { get; set; }
43+
4144
public Application Application { get; private set; }
4245

4346
/// <summary>
@@ -119,7 +122,7 @@ private void EnsureServerSettings(string baseUrl)
119122
}
120123

121124
var sql = $@"INSERT INTO Settings (Section, Name, Value) VALUES
122-
('BaseConfig', 'AllowRegistrations', 'False'),
125+
('BaseConfig', 'AllowRegistrations', 'True'),
123126
('BaseConfig', 'BaseUrl', '{baseUrl}'),
124127
('BaseConfig', 'SenderEmail', 'webtests@coderrapp.com'),
125128
('BaseConfig', 'SupportEmail', 'webtests@coderrapp.com'),
@@ -184,11 +187,11 @@ public void ResetDatabase(string baseUrl)
184187
protected void CreateUserAndApplication(IAdoNetUnitOfWork uow, out int accountId, out int applicationId)
185188
{
186189
var accountRepos = new AccountRepository(uow);
187-
var account = new Account("arne", "123456") {Email = "arne@som.com"};
190+
var account = new Account(TestUser.Username, TestUser.Password) {Email = TestUser.Email};
188191
account.Activate();
189192
accountRepos.Create(account);
190193
var userRepos = new UserRepository(uow);
191-
var user = new User(account.Id, "arne") {EmailAddress = "arne@som.com"};
194+
var user = new User(account.Id, TestUser.Username) {EmailAddress =TestUser.Email};
192195
userRepos.CreateAsync(user).GetAwaiter().GetResult();
193196

194197
var appRepos = new ApplicationRepository(uow);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace codeRR.Server.SqlServer.Tests.Models
2+
{
3+
public class TestUser
4+
{
5+
public string Username { get; set; }
6+
public string Password { get; set; }
7+
public string Email { get; set; }
8+
}
9+
}

src/Server/Coderr.Server.Web.Tests/Helpers/Extensions/WebDriverExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,31 @@ public static bool ElementIsPresent(this IWebDriver driver, By by)
2020
return present;
2121
}
2222

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+
2336
public static bool WaitUntilElementIsPresent(this IWebDriver driver, By by, int timeout = 5)
2437
{
2538
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
2639
return wait.Until(d => d.ElementIsPresent(by));
2740
}
2841

42+
public static bool WaitUntilElementIsPresent(this IWebDriver driver, IWebElement element, int timeout = 5)
43+
{
44+
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
45+
return wait.Until(d => d.ElementIsPresent(element));
46+
}
47+
2948
public static string WaitUntilTitleEquals(this IWebDriver driver, string title, int timeout = 5)
3049
{
3150
try
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Support.UI;
3+
4+
namespace codeRR.Server.Web.Tests.Pages.Account
5+
{
6+
public class ActivationRequestedPage : BasePage
7+
{
8+
public ActivationRequestedPage(IWebDriver webDriver) : base(webDriver, (string) "Account/ActivationRequested", (string) "Account registered - codeRR")
9+
{
10+
}
11+
12+
public void VerifyIsCurrentPage()
13+
{
14+
Wait.Until(ExpectedConditions.TitleIs(Title));
15+
}
16+
}
17+
}

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

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
using OpenQA.Selenium.Support.PageObjects;
33
using OpenQA.Selenium.Support.UI;
44

5-
namespace codeRR.Server.Web.Tests.Pages
5+
namespace codeRR.Server.Web.Tests.Pages.Account
66
{
77
public class LoginPage : BasePage
88
{
9-
private const string UserName = "arne";
10-
private const string Password = "123456";
11-
12-
public LoginPage(IWebDriver webDriver) : base(webDriver, "Account/Login", "Login - codeRR")
9+
public LoginPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Login", (string) "Login - codeRR")
1310
{
1411
}
1512

@@ -27,24 +24,66 @@ public HomePage LoginWithValidCredentials()
2724
NavigateToPage();
2825

2926
UserNameField.Clear();
30-
UserNameField.SendKeys(UserName);
27+
UserNameField.SendKeys(TestUser.Username);
3128

3229
PasswordField.Clear();
33-
PasswordField.SendKeys(Password);
30+
PasswordField.SendKeys(TestUser.Password);
3431

3532
SignInButton.Click();
3633

3734
return new HomePage(WebDriver);
3835
}
3936

37+
public LoginPage LoginWithNonExistingUserWithoutPasswordSpecified()
38+
{
39+
NavigateToPage();
40+
41+
UserNameField.Clear();
42+
UserNameField.SendKeys("NonExistingUsername");
43+
44+
PasswordField.Clear();
45+
46+
SignInButton.Click();
47+
48+
return this;
49+
}
50+
51+
public LoginPage LoginWithNonExistingUserWithPasswordSpecified()
52+
{
53+
NavigateToPage();
54+
55+
UserNameField.Clear();
56+
UserNameField.SendKeys("NonExistingUsername");
57+
58+
PasswordField.Clear();
59+
PasswordField.SendKeys(TestUser.Password);
60+
61+
SignInButton.Click();
62+
63+
return this;
64+
}
65+
4066
public LoginPage LoginWithNoUserNameSpecified()
4167
{
4268
NavigateToPage();
4369

4470
UserNameField.Clear();
4571

4672
PasswordField.Clear();
47-
PasswordField.SendKeys(Password);
73+
PasswordField.SendKeys(TestUser.Password);
74+
75+
SignInButton.Click();
76+
77+
return this;
78+
}
79+
80+
public LoginPage LoginWithNoUserNameAndNoPasswordSpecified()
81+
{
82+
NavigateToPage();
83+
84+
UserNameField.Clear();
85+
86+
PasswordField.Clear();
4887

4988
SignInButton.Click();
5089

@@ -56,7 +95,7 @@ public LoginPage LoginWithNoPasswordSpecified()
5695
NavigateToPage();
5796

5897
UserNameField.Clear();
59-
UserNameField.SendKeys(UserName);
98+
UserNameField.SendKeys(TestUser.Username);
6099

61100
PasswordField.Clear();
62101

@@ -70,10 +109,10 @@ public LoginPage LoginWithWrongPasswordSpecified()
70109
NavigateToPage();
71110

72111
UserNameField.Clear();
73-
UserNameField.SendKeys(UserName);
112+
UserNameField.SendKeys(TestUser.Username);
74113

75114
PasswordField.Clear();
76-
PasswordField.SendKeys(Password.Substring(1));
115+
PasswordField.SendKeys(TestUser.Password.Substring(1));
77116

78117
SignInButton.Click();
79118

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using OpenQA.Selenium;
22

3-
namespace codeRR.Server.Web.Tests.Pages
3+
namespace codeRR.Server.Web.Tests.Pages.Account
44
{
55
public class LogoutPage : BasePage
66
{
7-
public LogoutPage(IWebDriver webDriver) : base(webDriver, "Account/Logout", "")
7+
public LogoutPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Logout", (string) "")
88
{
99
}
1010

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using codeRR.Server.Web.Tests.Helpers.Extensions;
2+
using OpenQA.Selenium;
3+
using OpenQA.Selenium.Support.PageObjects;
4+
using OpenQA.Selenium.Support.UI;
5+
6+
namespace codeRR.Server.Web.Tests.Pages.Account
7+
{
8+
public class RegisterPage : BasePage
9+
{
10+
public RegisterPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Register", (string) "Register account - codeRR")
11+
{
12+
}
13+
14+
[FindsBy(How = How.Id, Using = "UserName")]
15+
public IWebElement UserNameField { get; set; }
16+
17+
[FindsBy(How = How.Id, Using = "Password")]
18+
public IWebElement PasswordField { get; set; }
19+
20+
[FindsBy(How = How.Id, Using = "Password2")]
21+
public IWebElement RetypePasswordField { get; set; }
22+
23+
[FindsBy(How = How.Id, Using = "Email")]
24+
public IWebElement EmailField { get; set; }
25+
26+
[FindsBy(How = How.ClassName, Using = "btn-primary")]
27+
public IWebElement SignUpButton { get; set; }
28+
29+
[FindsBy(How = How.ClassName, Using = "field-validation-error")]
30+
public IWebElement ValidationErrorField { get; set; }
31+
32+
public void VerifyIsCurrentPage()
33+
{
34+
Wait.Until(ExpectedConditions.TitleIs(Title));
35+
}
36+
37+
public RegisterPage RegisterUsingAlreadyTakenUsername()
38+
{
39+
NavigateToPage();
40+
41+
ClearForm();
42+
43+
UserNameField.SendKeys(TestUser.Username);
44+
PasswordField.SendKeys(TestUser.Password);
45+
RetypePasswordField.SendKeys(TestUser.Password);
46+
EmailField.SendKeys(TestUser.Email);
47+
48+
SignUpButton.Click();
49+
50+
return this;
51+
}
52+
53+
public RegisterPage RegisterUsingAlreadyTakenEmail()
54+
{
55+
NavigateToPage();
56+
57+
ClearForm();
58+
59+
UserNameField.SendKeys(TestUser.Username + "2");
60+
PasswordField.SendKeys(TestUser.Password);
61+
RetypePasswordField.SendKeys(TestUser.Password);
62+
EmailField.SendKeys(TestUser.Email);
63+
64+
SignUpButton.Click();
65+
66+
return this;
67+
}
68+
69+
public ActivationRequestedPage RegisterNewUser()
70+
{
71+
NavigateToPage();
72+
73+
ClearForm();
74+
75+
UserNameField.SendKeys(TestUser.Username + "2");
76+
PasswordField.SendKeys(TestUser.Password);
77+
RetypePasswordField.SendKeys(TestUser.Password);
78+
EmailField.SendKeys("TestUser2@coderrapp.com");
79+
80+
SignUpButton.Click();
81+
82+
return new ActivationRequestedPage(WebDriver);
83+
}
84+
85+
public RegisterPage VerifyUsernameIsAlreadyTaken()
86+
{
87+
WebDriver.WaitUntilElementIsPresent(ValidationErrorField);
88+
return this;
89+
}
90+
91+
public RegisterPage VerifyEmailIsAlreadyTaken()
92+
{
93+
WebDriver.WaitUntilElementIsPresent(ValidationErrorField);
94+
return this;
95+
}
96+
97+
private void ClearForm()
98+
{
99+
UserNameField.Clear();
100+
PasswordField.Clear();
101+
RetypePasswordField.Clear();
102+
EmailField.Clear();
103+
}
104+
}
105+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using codeRR.Server.SqlServer.Tests.Models;
23
using OpenQA.Selenium;
34
using OpenQA.Selenium.Support.PageObjects;
45
using OpenQA.Selenium.Support.UI;
@@ -11,7 +12,9 @@ public class BasePage
1112
protected WebDriverWait Wait;
1213
protected string BaseUrl { get; }
1314
protected string Url { get; set; }
14-
protected string Title { get; }
15+
public string Title { get; }
16+
17+
protected readonly TestUser TestUser = WebTest.TestUser;
1518

1619
public BasePage(IWebDriver webDriver, string url, string title)
1720
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public HomePage(IWebDriver webDriver) : base(webDriver, "", "Overview")
1111
}
1212

1313
[FindsBy(How = How.XPath, Using = "//a/span[.=' MyTestApp ']")]
14-
public IWebElement FirstApplication { get; set; }
14+
public IWebElement NavigationMyTestApp { get; set; }
1515

1616
[FindsBy(How = How.Id, Using = "pageTitle")]
1717
public IWebElement PageTitle { get; set; }
@@ -41,9 +41,9 @@ public void VerifyIsCurrentPage()
4141
Wait.Until(ExpectedConditions.TitleIs("Overview"));
4242
}
4343

44-
public void VerifyNavigatedToFirstApplication()
44+
public void VerifyNavigatedToMyTestApp()
4545
{
46-
Wait.Until(ExpectedConditions.TextToBePresentInElement(PageTitle, Title));
46+
Wait.Until(ExpectedConditions.TextToBePresentInElement(PageTitle, "MyTestApp"));
4747
}
4848
}
4949
}

src/Server/Coderr.Server.Web.Tests/Tests/HomePageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace codeRR.Server.Web.Tests.Tests
77
public class HomePageTests : LoggedInTest
88
{
99
[Fact]
10-
public void Should_be_able_to_navigate_to_application()
10+
public void Should_be_able_to_navigate_to_myfirstapp_application()
1111
{
1212
UITest(() =>
1313
{
@@ -16,9 +16,9 @@ public void Should_be_able_to_navigate_to_application()
1616
var sut = new HomePage(WebDriver);
1717
sut.NavigateToPage();
1818

19-
sut.FirstApplication.Click();
19+
sut.NavigationMyTestApp.Click();
2020

21-
sut.VerifyNavigatedToFirstApplication();
21+
sut.VerifyNavigatedToMyTestApp();
2222

2323
Logout();
2424
});

0 commit comments

Comments
 (0)