Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ public void CreateUserAndApplication(out int accountId, out int applicationId)
}
}

public void CreateUser(TestUser testUser, int applicationId)
{
using (var uow = CreateUnitOfWork())
{
var accountRepos = new AccountRepository(uow);
var account = new Account(testUser.Username, testUser.Password) { Email = testUser.Email };
account.Activate();
accountRepos.Create(account);
var userRepos = new UserRepository(uow);
var user = new User(account.Id, testUser.Username) { EmailAddress = testUser.Email };
userRepos.CreateAsync(user).GetAwaiter().GetResult();

var appRepos = new ApplicationRepository(uow);
var member = new ApplicationTeamMember(applicationId, account.Id, "Admin");
appRepos.CreateAsync(member).GetAwaiter().GetResult();

uow.SaveChanges();
}
}

private void EnsureServerSettings(string baseUrl)
{
using (var con = _connectionFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Xunit.Sdk;

namespace codeRR.Server.Web.Tests.Helpers.Extensions
{
public static class WebDriverExtensions
{
public static bool ElementIsPresent(this IWebDriver driver, By by)
{
var present = false;
try
{
present = driver.FindElement(by).Displayed;
}
catch (NoSuchElementException)
{
}
return present;
}

public static bool ElementIsPresent(this IWebDriver driver, IWebElement element)
{
var present = false;
try
{
present = element.Displayed;
}
catch (NoSuchElementException)
{
}
return present;
}

public static bool WaitUntilElementIsPresent(this IWebDriver driver, By by, int timeout = 5)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
Expand All @@ -59,5 +32,31 @@ public static string WaitUntilTitleEquals(this IWebDriver driver, string title,

return driver.Title;
}

private static bool ElementIsPresent(this IWebDriver driver, By by)
{
var present = false;
try
{
present = driver.FindElement(by).Displayed;
}
catch (NoSuchElementException)
{
}
return present;
}

private static bool ElementIsPresent(this IWebDriver driver, IWebElement element)
{
var present = false;
try
{
present = element.Displayed;
}
catch (NoSuchElementException)
{
}
return present;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
{
public class ActivationRequestedPage : BasePage
{
public ActivationRequestedPage(IWebDriver webDriver) : base(webDriver, (string) "Account/ActivationRequested", (string) "Account registered - codeRR")
public ActivationRequestedPage(IWebDriver webDriver) : base(webDriver, "Account/ActivationRequested", "Account registered - codeRR")
{
}

Expand Down
10 changes: 5 additions & 5 deletions src/Server/Coderr.Server.Web.Tests/Pages/Account/LoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
{
public class LoginPage : BasePage
{
public LoginPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Login", (string) "Login - codeRR")
public LoginPage(IWebDriver webDriver) : base(webDriver, "Account/Login", "Login - codeRR")
{
}

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

public HomePage LoginWithValidCredentials()
public IPage LoginWithValidCredentials(string userName, string password)
{
NavigateToPage();

UserNameField.Clear();
UserNameField.SendKeys(TestUser.Username);
UserNameField.SendKeys(userName);

PasswordField.Clear();
PasswordField.SendKeys(TestUser.Password);
PasswordField.SendKeys(password);

SignInButton.Click();

return new HomePage(WebDriver);
return PageHelper.ResolvePage(WebDriver);
}

public LoginPage LoginWithNonExistingUserWithoutPasswordSpecified()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
{
public class LogoutPage : BasePage
{
public LogoutPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Logout", (string) "")
public LogoutPage(IWebDriver webDriver) : base(webDriver, "Account/Logout", "")
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace codeRR.Server.Web.Tests.Pages.Account
{
public class RegisterPage : BasePage
{
public RegisterPage(IWebDriver webDriver) : base(webDriver, (string) "Account/Register", (string) "Register account - codeRR")
public RegisterPage(IWebDriver webDriver) : base(webDriver, "Account/Register", "Register account - codeRR")
{
}

Expand Down
29 changes: 29 additions & 0 deletions src/Server/Coderr.Server.Web.Tests/Pages/ApplicationPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;

namespace codeRR.Server.Web.Tests.Pages
{
public class ApplicationPage : BasePage
{
public ApplicationPage(IWebDriver webDriver, int id) : base(webDriver, "#/application/{id}", "")
{
Url = Url.Replace("{id}", id.ToString());
}

[FindsBy(How = How.Id, Using = "pageTitle")]
public IWebElement PageTitle { get; set; }

public void VerifyIsCurrentPage()
{
Wait.Until(ExpectedConditions.TitleIs(Title));
}

public void VerifyIncidentReported()
{
var by = By.PartialLinkText("Value cannot be null");
//var element = WebDriver.FindElement(by);
Wait.Until(ExpectedConditions.ElementExists(by));
}
}
}
4 changes: 2 additions & 2 deletions src/Server/Coderr.Server.Web.Tests/Pages/BasePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace codeRR.Server.Web.Tests.Pages
{
public class BasePage
public class BasePage : IPage
{
protected IWebDriver WebDriver;
protected WebDriverWait Wait;
protected string BaseUrl { get; }
protected string Url { get; set; }
public string Url { get; set; }
public string Title { get; }

protected readonly TestUser TestUser = WebTest.TestUser;
Expand Down
8 changes: 8 additions & 0 deletions src/Server/Coderr.Server.Web.Tests/Pages/IPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace codeRR.Server.Web.Tests.Pages
{
public interface IPage
{
string Url { get; set; }
string Title { get; }
}
}
25 changes: 25 additions & 0 deletions src/Server/Coderr.Server.Web.Tests/Pages/PageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Text.RegularExpressions;
using codeRR.Server.Web.Tests.Pages.Account;
using OpenQA.Selenium;

namespace codeRR.Server.Web.Tests.Pages
{
public class PageHelper
{
public static IPage ResolvePage(IWebDriver webDriver)
{
var match = Regex.Match(webDriver.Url, @"/#/$", RegexOptions.IgnoreCase);
if (match.Success)
return new HomePage(webDriver);
match = Regex.Match(webDriver.Url, @"/Account/Login", RegexOptions.IgnoreCase);
if (match.Success)
return new LoginPage(webDriver);
match = Regex.Match(webDriver.Url, @"/#/application/(\d+)", RegexOptions.IgnoreCase);
if(match.Success)
return new ApplicationPage(webDriver, Convert.ToInt16(match.Groups[1].Value));

throw new ArgumentOutOfRangeException($"Url: {webDriver.Url}, Title: {webDriver.Title}");
}
}
}
35 changes: 35 additions & 0 deletions src/Server/Coderr.Server.Web.Tests/Tests/AdminUserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using codeRR.Server.Web.Tests.Helpers.Extensions;
using codeRR.Server.Web.Tests.Pages;
using OpenQA.Selenium;
using Xunit;

namespace codeRR.Server.Web.Tests.Tests
{
[Trait("Category", "Integration")]
public class AdminUserTests : LoggedInTest, IDisposable
{
private readonly IPage _homePage;

public AdminUserTests()
{
_homePage = Login();
}

[Fact]
public void Admin_Should_have_create_new_application_menu_item()
{
UITest(() =>
{
Assert.IsType<HomePage>(_homePage);
Assert.Equal("Overview", WebDriver.WaitUntilTitleEquals(_homePage.Title));
Assert.NotNull(WebDriver.FindElement(By.XPath("//a/span[.='Create new application']")));
});
}

public void Dispose()
{
Logout();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using codeRR.Server.Web.Tests.Pages;
using System;
using codeRR.Server.Web.Tests.Pages;
using Xunit;

namespace codeRR.Server.Web.Tests.Tests
{
[Trait("Category", "Integration")]
public class ConfigureApplicationPageTests : LoggedInTest
public class ConfigureApplicationPageTests : LoggedInTest, IDisposable
{
public ConfigureApplicationPageTests()
{
Login();
}

[Fact]
public void Should_not_be_able_to_create_application_without_name_specified()
{
UITest(() =>
{
Login();

var sut = new ConfigureApplicationPage(WebDriver)
.CreateApplication(string.Empty);

//TODO: Verify error message
sut.VerifyIsCurrentPage();

Logout();
});
}

Expand All @@ -28,8 +30,6 @@ public void Should_be_able_to_create_application()
{
UITest(() =>
{
Login();

var applicationName = "TestApplication";

var sut = new ConfigureApplicationPage(WebDriver)
Expand All @@ -42,9 +42,12 @@ public void Should_be_able_to_create_application()
homePage.VerifyIsCurrentPage();

homePage.HasApplicationInNavigation(applicationName);

Logout();
});
}

public void Dispose()
{
Logout();
}
}
}
19 changes: 13 additions & 6 deletions src/Server/Coderr.Server.Web.Tests/Tests/HomePageTests.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
using codeRR.Server.Web.Tests.Pages;
using System;
using codeRR.Server.Web.Tests.Pages;
using Xunit;

namespace codeRR.Server.Web.Tests.Tests
{
[Trait("Category", "Integration")]
public class HomePageTests : LoggedInTest
public class HomePageTests : LoggedInTest, IDisposable
{
public HomePageTests()
{
Login();
}

[Fact]
public void Should_be_able_to_navigate_to_myfirstapp_application()
{
UITest(() =>
{
Login();

var sut = new HomePage(WebDriver);
sut.NavigateToPage();

sut.NavigationMyTestApp.Click();

sut.VerifyNavigatedToMyTestApp();

Logout();
});
}

public void Dispose()
{
Logout();
}
}
}
Loading