Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIH-10523 Added a login journey for a newly created user to the end2end test scenario #266

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions UI.AutomationTests/Admin/AdminWebUITest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UI.AutomationTests.Reporters;

namespace UI.AutomationTests.Admin;

public abstract class AdminWebUiTest : CommonUiTest
Expand All @@ -13,6 +11,7 @@ protected virtual async Task OneTimeSetup()
EnvConfigSettings = ConfigRootBuilder.EnvConfigInstance();
BookingsApiClient = await VhApiClientFactory.CreateBookingsApiClient();
UserApiClient = await VhApiClientFactory.CreateUserApiClient();
NotifyApiClient = VhApiClientFactory.CreateNotificationApiClient();
}

[SetUp]
Expand Down
1 change: 1 addition & 0 deletions UI.AutomationTests/Admin/Booking/BookHearingTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using UI.Common.Utilities;

namespace UI.AutomationTests.Admin.Booking;
Expand Down
2 changes: 2 additions & 0 deletions UI.AutomationTests/CommonUiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V1.Requests.Enums;
using BookingsApi.Contract.V1.Responses;
using Notify.Interfaces;
using UI.AutomationTests.Reporters;
using UI.PageModels.Extensions;
using UI.PageModels.Utilities;
Expand All @@ -16,6 +17,7 @@ public abstract class CommonUiTest
protected readonly List<string> CreatedUsers = new();
protected BookingsApiClient BookingsApiClient;
protected UserApiClient UserApiClient;
protected IAsyncNotificationClient NotifyApiClient { get; set; }
protected TestReporter UiTestReport;
protected EnvironmentConfigSettings EnvConfigSettings = ConfigRootBuilder.EnvConfigInstance();
protected async Task<JusticeUserResponse> CreateVhTeamLeaderJusticeUserIfNotExist(string username)
Expand Down
1 change: 1 addition & 0 deletions UI.AutomationTests/UI.AutomationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="BookingsApi.Client" Version="3.1.9" />
<PackageReference Include="ExtentReports" Version="5.0.4" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GovukNotify" Version="7.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
Expand Down
8 changes: 8 additions & 0 deletions UI.AutomationTests/VhApiClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Net.Http.Headers;
using BookingsApi.Client;
using Notify.Client;
using Notify.Interfaces;
using UI.Common.Security;
using UserApi.Client;
using VideoApi.Client;
Expand Down Expand Up @@ -41,6 +43,12 @@ public static async Task<UserApiClient> CreateUserApiClient()
return UserApiClient.GetClient(apiClientConfiguration.UserApiUrl, httpClient);
}

public static IAsyncNotificationClient CreateNotificationApiClient()
{
var apiClientConfiguration = ConfigRootBuilder.ApiClientConfigurationInstance();
return new NotificationClient(apiClientConfiguration.NotifyApiKey);
}

private static async Task<string> GenerateBookingsApiToken(ApiClientConfiguration apiClientConfiguration)
{
return await new TokenProvider(apiClientConfiguration)
Expand Down
38 changes: 34 additions & 4 deletions UI.AutomationTests/Video/EndToEndTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using BookingsApi.Contract.V1.Responses;
using UI.Common.Utilities;
using UI.PageModels.Pages.Video.Participant;
Expand All @@ -14,7 +15,8 @@ public class EndToEndTest : VideoWebUiTest
private string _hearingIdString;
private ConferenceDetailsResponse _conference;
private JusticeUserResponse _justiceUser;

private readonly Regex _tempPassword = new(@"(?<=temporary password: )[\S]+");

[Test]
[Category("a11y")]
[Category("video")]
Expand All @@ -27,13 +29,14 @@ public class EndToEndTest : VideoWebUiTest
public async Task EndToEnd()
{
var hearingScheduledDateAndTime = DateUtil.GetNow(EnvConfigSettings.RunOnSauceLabs || EnvConfigSettings.RunHeadlessBrowser).AddMinutes(5);
var hearingDto = HearingTestData.CreateHearingDto(HearingTestData.JudgePersonalCode,
HearingTestData.JudgeUsername, scheduledDateTime: hearingScheduledDateAndTime);
var hearingDto = HearingTestData.CreateHearingDto(HearingTestData.JudgePersonalCode, HearingTestData.JudgeUsername, scheduledDateTime: hearingScheduledDateAndTime);
var newUser = HearingTestData.CreateNewParticipantDto();
hearingDto.NewParticipants.Add(newUser);
await TestContext.Out.WriteLineAsync(
$"Attempting to book a hearing with the case name: {hearingDto.CaseName} and case number: {hearingDto.CaseNumber}");

await BookHearing(hearingDto);

//Login
var vhoVenueSelectionPage = LoginAsVho(HearingTestData.VhOfficerUsername, EnvConfigSettings.UserPassword);
ParticipantDrivers[HearingTestData.VhOfficerUsername].VhVideoWebPage = vhoVenueSelectionPage;
Expand All @@ -42,6 +45,11 @@ await TestContext.Out.WriteLineAsync(

// loop through all participants in hearing and login as each one
Parallel.ForEach(hearingDto.Participants, ParticipantLoginToWaitingRoomJourney);

// login with new user with temp password journey
var newUserTempPassword = await GetTempPasswordForUser(newUser.ContactEmail);
NewParticipantLoginToWaitingRoom(newUser, newUserTempPassword);
hearingDto.Participants.Add(newUser);

var testParticipantWaitingRoom = (ParticipantWaitingRoomPage)ParticipantDrivers[testParticipant.Username].VhVideoWebPage;
ccHearingPanel.ValidateParticipantStatusAfterLogin(testParticipant.Id, _conference.Id.ToString());
Expand Down Expand Up @@ -92,6 +100,12 @@ private void ParticipantLoginToWaitingRoomJourney(BookingParticipantDto particip
var participantUsername = participant.Username;
var participantPassword = EnvConfigSettings.UserPassword;
var participantHearingList = LoginAsParticipant(participantUsername, participantPassword, participant.Role == GenericTestRole.Representative, participant.VideoFileName);
JourneyToWaitingRoom(participant, participantHearingList, participantUsername);
}

private void JourneyToWaitingRoom(BookingParticipantDto participant, ParticipantHearingListPage participantHearingList,
string participantUsername)
{
var participantWaitingRoom = participantHearingList
.SelectHearing(_conference.Id).GoToEquipmentCheck()
.GoToSwitchOnCameraMicrophonePage()
Expand All @@ -101,6 +115,13 @@ private void ParticipantLoginToWaitingRoomJourney(BookingParticipantDto particip
ParticipantDrivers[participantUsername].VhVideoWebPage = participantWaitingRoom;
}

private void NewParticipantLoginToWaitingRoom(BookingParticipantDto participant, string tempPassword)
{
var participantUsername = participant.Username;
var participantHearingList = LoginAsParticipant(participantUsername, tempPassword, participant.Role == GenericTestRole.Representative, participant.VideoFileName, isNew: true);
JourneyToWaitingRoom(participant, participantHearingList, participantUsername);
}

private CommandCentrePage CsoCommandCentreJourney(VhoVenueSelectionPage vhoVenueSelectionPage, BookingDto hearingDto,
out CommandCentreHearing ccHearingPanel, out ParticipantResponse testParticipant)
{
Expand Down Expand Up @@ -167,4 +188,13 @@ private async Task BookHearing(BookingDto bookingDto)
justiceUserDisplayName: _justiceUser.FullName,
justiceUserUsername: _justiceUser.Username);
}

private async Task<string> GetTempPasswordForUser(string email)
{
var allNotifications = await NotifyApiClient.GetNotificationsAsync("email");
var newUserEmails = allNotifications.notifications.Find(x =>
x.emailAddress == email &&
x.subject.Contains("Confirming the date, time, and sign in details of your video hearing"));
return _tempPassword.Match(newUserEmails!.body).Value;
}
}
7 changes: 5 additions & 2 deletions UI.AutomationTests/Video/VideoWebUiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public async Task OneTimeSetup()
{
BookingsApiClient = await VhApiClientFactory.CreateBookingsApiClient();
VideoApiClient = await VhApiClientFactory.CreateVideoApiClient();
NotifyApiClient = VhApiClientFactory.CreateNotificationApiClient();
}

[SetUp]
Expand Down Expand Up @@ -133,11 +134,13 @@ protected VhoVenueSelectionPage LoginAsVho(string username, string password)
return loginPage.LogInAsVho(username, password);
}

protected ParticipantHearingListPage LoginAsParticipant(string username, string password, bool isRep, string videoFileName)
protected ParticipantHearingListPage LoginAsParticipant(string username, string password, bool isRep, string videoFileName, bool isNew = false)
{
var participant = InitVideoWebParticipant(username, isRep ? JourneyType.Representative : JourneyType.Citizen, videoFileName);
var loginPage = NavigateToVideoWeb(participant.Driver.GetDriver());
return loginPage.LogInAsParticipant(username, password);
return isNew
? loginPage.LogInAsNewParticipant(username, password)
: loginPage.LogInAsParticipant(username, password);
}

protected QuickLinkJoinYourHearingPage LoginAsQuickLinkUser(string quickLinkJoinUrl, string displayName)
Expand Down
3 changes: 2 additions & 1 deletion UI.AutomationTests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"VideoApiUrl": "https://vh-video-api.dev.platform.hmcts.net/",
"VideoApiResourceId": "https://vh-video-api.dev.platform.hmcts.net",
"UserApiUrl": "https://vh-user-api.dev.platform.hmcts.net/",
"UserApiResourceId": "https://vh-user-api.dev.platform.hmcts.net"
"UserApiResourceId": "https://vh-user-api.dev.platform.hmcts.net",
"NotifyApiKey": "Notifykey"
},
"TestDataConfiguration": {
"AudioLinkCaseNumber": "VIH 9831"
Expand Down
1 change: 1 addition & 0 deletions UI.Common/Configuration/ApiClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class ApiClientConfiguration
public string VideoApiResourceId { get;set; }
public string UserApiUrl { get; set; }
public string UserApiResourceId { get; set; }
public string NotifyApiKey { get; set; }
}
11 changes: 2 additions & 9 deletions UI.Common/Security/TokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@

namespace UI.Common.Security;

public class TokenProvider
public class TokenProvider(ApiClientConfiguration apiClientConfiguration)
{
private readonly ApiClientConfiguration _apiClientConfiguration;

public TokenProvider(ApiClientConfiguration apiClientConfiguration)
{
_apiClientConfiguration = apiClientConfiguration;
}

public async Task<string> GetClientAccessToken(string clientId, string clientSecret, string clientResource)
{
var result = await GetAuthorisationResult(clientId, clientSecret, clientResource);
Expand All @@ -21,7 +14,7 @@ public async Task<string> GetClientAccessToken(string clientId, string clientSec
private async Task<AuthenticationResult> GetAuthorisationResult(string clientId, string clientSecret,
string clientResource)
{
var authority = $"{_apiClientConfiguration.Authority}{_apiClientConfiguration.TenantId}";
var authority = $"{apiClientConfiguration.Authority}{apiClientConfiguration.TenantId}";
var app = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecret)
Expand Down
2 changes: 1 addition & 1 deletion UI.PageModels/Pages/Admin/Booking/HearingDetailsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public SummaryPage BookAHearingJourney(BookingDto bookingDto, bool isMultiDay =

var addParticipantPage = assignJudgePage.GotToNextPage();

addParticipantPage.AddParticipants(bookingDto.Participants);
addParticipantPage.AddAllParticipantsFromDto(bookingDto);

var videoAccessPointsPage = addParticipantPage.GoToVideoAccessPointsPage();
videoAccessPointsPage.AddVideoAccessPoints(bookingDto.VideoAccessPoints);
Expand Down
10 changes: 9 additions & 1 deletion UI.PageModels/Pages/Admin/DashboardPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public class DashboardPage(IWebDriver driver, int defaultWaitTime) : VhAdminWebP
private readonly By _bookHearingButton = By.Id("bookHearingBtn");
private readonly By _unallocatedHearingsNextSevenDays = By.Id("unallocated-hearings-next-seven-days");
private readonly By _unallocatedHearingsNextThirtyDays = By.Id("unallocated-hearings-next-thirty-days");

private readonly By _unallocatedHearingsToday = By.Id("unallocated-hearings-today");
private readonly By _unallocatedHearingsTomorrow = By.Id("unallocated-hearings-tomorrow");
private readonly By _workAllocationButton = By.Id("manageWorkAllocationBtn");
private readonly By _manageTeamButton = By.Id("manageTeamBtn");
private readonly By _changePasswordButton = By.Id("changePasswordBtn");

protected override void ConfirmPageHasLoaded()
{
Expand Down Expand Up @@ -71,6 +71,14 @@ public ManageTeamPage GoToManageTeam()
return new ManageTeamPage(Driver, DefaultWaitTime);
}

public ChangePasswordPage GoToChangePassword()
{
WaitForApiSpinnerToDisappear();
ClickElement(_changePasswordButton);
Driver.TakeScreenshotAndSave(GetType().Name, "Clicked Change Password Button");
return new ChangePasswordPage(Driver, DefaultWaitTime);
}

private int GetNumberOfUnallocatedHearings(By locator)
{
var text = GetText(locator);
Expand Down
14 changes: 13 additions & 1 deletion UI.PageModels/Pages/VhLoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public abstract class VhLoginPage : VhPage
private readonly By _passwordField = By.Id("i0118");
private readonly By _signInBtn = By.Id("idSIButton9"); // also the next button
private readonly By _usernameTextfield = By.Id("i0116");

private readonly By _currentPasswordField = By.Id("currentPassword");
private readonly By _newPasswordField = By.Id("newPassword");
private readonly By _confirmNewPasswordField = By.Id("confirmNewPassword");
protected VhLoginPage(IWebDriver driver, int defaultWaitTime) : base(driver, defaultWaitTime, useAltLocator:false)
{
}
Expand All @@ -19,4 +21,14 @@ protected void EnterLoginDetails(string username, string password)
EnterText(_passwordField, password);
ClickElement(_signInBtn);
}

protected string UpdateUserPassword(string currentPassword, string? newPassword = null)
{
newPassword ??= currentPassword+currentPassword;
EnterText(_currentPasswordField, currentPassword);
EnterText(_newPasswordField, newPassword);
EnterText(_confirmNewPasswordField, newPassword);
ClickElement(_signInBtn);
return newPassword;
}
}
13 changes: 8 additions & 5 deletions UI.PageModels/Pages/Video/VideoWebLoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

namespace UI.PageModels.Pages.Video;

public class VideoWebLoginPage : VhLoginPage
public class VideoWebLoginPage(IWebDriver driver, int defaultWaitTime) : VhLoginPage(driver, defaultWaitTime)
{
public VideoWebLoginPage(IWebDriver driver, int defaultWaitTime) : base(driver, defaultWaitTime)
{
}

public JudgeHearingListPage LogInAsJudge(string username, string password)
{
EnterLoginDetails(username, password);
Expand All @@ -21,6 +17,13 @@ public ParticipantHearingListPage LogInAsParticipant(string username, string pas
return new ParticipantHearingListPage(Driver, DefaultWaitTime);
}

public ParticipantHearingListPage LogInAsNewParticipant(string username, string password)
{
EnterLoginDetails(username, password);
UpdateUserPassword(password);
return new ParticipantHearingListPage(Driver, DefaultWaitTime);
}

public StaffMemberVenueListPage LogInAsStaffMember(string username, string password)
{
EnterLoginDetails(username, password);
Expand Down
Loading