Skip to content

Commit

Permalink
Added additional acceptance criteria validations and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Anderson authored and Rick Anderson committed Jul 26, 2024
1 parent ca3eb15 commit 4955c58
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Scenario: ManagingAccess

#Request Details:

When Reviewing a specific access request
When Reviewing a specific access request

Then I should be able to view detailed information provided by the user, including their role request and any justifications or additional comments

#Grant Access Button:

When Reviewing an access request

Then There should be a Grant Access button allowing me to approve the user's request
Then There should be a Grant Access button allowing me to approve the user's request "<RequestingAccessUser>"


#Role Assignment:

Expand Down Expand Up @@ -62,8 +63,8 @@ Scenario: ManagingAccess
#
#
Examples:
| UserName | ListingID | Description | ExpectedResult | ListingURL | AdditionalCCsTextBox | GovPhoneNumber | TakedownReason |
| CEUATST | 0 | ListingID - Boundary | pass | http://listingURL.com | richard.anderson@dxc.com | 9991231234 | Get a business license |
| UserName | ListingID | Description | ExpectedResult | ListingURL | RequestingAccessUser |AdditionalCCsTextBox | GovPhoneNumber | TakedownReason |
| CEUATST | 0 | ListingID - Boundary | pass | http://listingURL.com | STRDSSVrboDev |richard.anderson@dxc.com | 9991231234 | Get a business license |



28 changes: 15 additions & 13 deletions Test/UITest/SpecFlowProjectBDD/Features/ManagingAccess.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Test/UITest/SpecFlowProjectBDD/Helpers/AuthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public LogonTypeEnum SetLogonType(UserTypeEnum UserType)
return (_LogonType);
}

public LogonTypeEnum? Authenticate(string UserName, UserTypeEnum UserType)
public LogonTypeEnum? Authenticate(string UserName, string Password, UserTypeEnum UserType)
{
_TestUserName = UserName;
_TestPassword = _AppSettings.GetUser(_TestUserName) ?? string.Empty;
_TestPassword = Password;
_LogonType = SetLogonType(UserType);

_Driver.Url = _AppSettings.GetServer("default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void IAttemptToAccessTheDataSharingSystem(string UserName, string Email,
AuthHelper authHelper = new AuthHelper(_Driver);

//Authenticate user using IDir or BCID depending on the user
authHelper.Authenticate(_TestUserName, _UserType);
authHelper.Authenticate(_TestUserName, _TestPassword, _UserType);

}

Expand Down
132 changes: 87 additions & 45 deletions Test/UITest/SpecFlowProjectBDD/StepDefinitions/ManagingAccess.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using Configuration;
using DataBase.Entities;
using DataBase.UnitOfWork;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using OpenQA.Selenium;
using OpenQA.Selenium.DevTools.V118.Debugger;
using SpecFlowProjectBDD.Helpers;
using System.Reflection.Metadata;
using TechTalk.SpecFlow.CommonModels;
using TestFrameWork.Models;
using UITest.PageObjects;
using UITest.TestDriver;
Expand All @@ -26,6 +31,12 @@ public sealed class ManagingAccess
private string _TestPassword;
private bool _ExpectedResult = false;
AppSettings _AppSettings;
private DssUserIdentity _RequestingUserIdentity;
private bool _OriginalEnabledValue;
private string _OriginalAccessRequestStatusCd = string.Empty;
private DssDbContext _DssDBContext;
private IUnitOfWork _UnitOfWork;
private SFEnums.Environment _Environment = SFEnums.Environment.LOCAL;

public ManagingAccess(SeleniumDriver Driver)
{
Expand All @@ -37,15 +48,39 @@ public ManagingAccess(SeleniumDriver Driver)
_PathFinderPage = new PathFinderPage(_Driver);
_IDirPage = new IDirLoginPage(_Driver);
_AppSettings = new AppSettings();

DbContextOptions<DssDbContext> dbContextOptions = new DbContextOptions<DssDbContext>();

string dbConnectionString = _AppSettings.GetConnectionString(_Environment.ToString().ToLower()) ?? string.Empty;

_DssDBContext = new DssDbContext(dbContextOptions, dbConnectionString);
_UnitOfWork = new UnitOfWork(_DssDBContext);
}

[SetUp]
public void Setup()
{
}

[AfterScenario("ManagingAccess")]
public void TearDown()
{
if (null != _RequestingUserIdentity)
{
_RequestingUserIdentity.AccessRequestStatusCd = _OriginalAccessRequestStatusCd;
_DssDBContext.SaveChanges();
}
}


//User Authentication
//[Given(@"I am an authenticated LG staff member and the expected result is ""(.*)""")]
[Given(@"that I am an authenticated government user ""(.*)"" and the expected result is ""(.*)""")]
public void GivenIAmAauthenticatedGovernmentUser(string UserName, string ExpectedResult)
{
_TestUserName = UserName;
_TestPassword = _AppSettings.GetUser(_TestUserName) ?? string.Empty;

_ExpectedResult = ExpectedResult.ToUpper() == "PASS" ? true : false;

_Driver.Url = _AppSettings.GetServer("default");
Expand All @@ -55,7 +90,7 @@ public void GivenIAmAauthenticatedGovernmentUser(string UserName, string Expecte
AuthHelper authHelper = new AuthHelper(_Driver);

//Authenticate user using IDir or BCID depending on the user
authHelper.Authenticate(_TestUserName, UserTypeEnum.BCGOVERNMENTSTAFF);
authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.BCGOVERNMENTSTAFF);


IWebElement TOC = null;
Expand Down Expand Up @@ -90,7 +125,8 @@ public void ThereShouldBeADedicatedSectionForManagingUserAccessRequests()
{
string selector = "body > app-root > app-layout > div.content > app-user-management > div.table-card-container";

bool result = (bool)_ManagingAccessPage.ManageAccessSection.JSCheckVisability(selector);
//bool result = (bool)_ManagingAccessPage.UserTable.JSCheckVisability(selector);
bool result = (bool)_ManagingAccessPage.UserTable.IsEnabled();

ClassicAssert.IsTrue(result);
}
Expand All @@ -108,67 +144,38 @@ public void INavigateToTheUserAccessRequestSection()
public void IShouldSeeAListDisplayingAllUserAccessRequestss()
{
bool result = false;
string selector = "#pn_id_14-table";
result = (bool)_ManagingAccessPage.ManageAccessSection.JSCheckVisability(selector); ;
//result = (bool)_ManagingAccessPage.ManageAccessSection.ExecuteJavaScript(@"document.querySelector(""#pn_id_14-table"").checkVisibility()");

result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#user-table"").checkVisibility()");
ClassicAssert.IsTrue(result);

selector = "#pn_id_14-table > tbody";
result = (bool)_ManagingAccessPage.ManageAccessSection.JSCheckVisability(selector);
//result = (bool)_ManagingAccessPage.ManageAccessSection.ExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > tbody"").checkVisibility()");
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#table-header"").checkVisibility()");
ClassicAssert.IsTrue(result);

selector = "#pn_id_14-table > thead > tr > th:nth-child(3)";

IJavaScriptExecutor js = _Driver.Driver as IJavaScriptExecutor;
var script = @"
try {
var elem = document.querySelector('" + selector + @"');
console.log('Element:', elem);
if (elem) {
console.log('Element found');
if (elem.textContent.toLowerCase().trim() === 'first name') {
return(true);
} else {
console.error('FirstName Not Found');
return false;
}
} else {
console.error('Element not found');
return false;
}
} catch (e) {
console.error('Error:', e);
return false;
}";

result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > thead > tr > th:nth-child(3)"").textContent.toLowerCase().trim() === ""first name""");

//result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(script);
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#givenNm_th"").textContent.toLowerCase().trim() === ""first name""");

ClassicAssert.IsTrue(result);

result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector('#pn_id_14-table > thead > tr > th:nth-child(4)').textContent.toLowerCase().trim() === 'last name'");
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#familyNm_th"").textContent.toLowerCase().trim() === 'last name'");
ClassicAssert.IsTrue(result);

result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > thead > tr > th:nth-child(7)"").textContent.toLowerCase().trim() === ""organization""");
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#orgName_th"").textContent.toLowerCase().trim() === ""organization""");
ClassicAssert.IsTrue(result);

result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > thead > tr > th:nth-child(6)"").textContent.toLowerCase().trim() === ""email address""");
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#emailAddressDsc_th"").textContent.toLowerCase().trim() === ""email address""");
ClassicAssert.IsTrue(result);
}


//Request Details
[When("Reviewing a specific access request")]
[When(@"Reviewing a specific access request")]
public void ReviewingASpecificAccessRequest()
{
}

[Then("I should be able to view detailed information provided by the user, including their role request and any justifications or additional comments")]
public void ShouldBeAbleToViewDetailedInformationProvidedByTheUser()
{
bool result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > tbody > tr:nth-child(1)"").checkVisibility()");
bool result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#row-0"").checkVisibility()");
ClassicAssert.IsTrue(result);
}

Expand All @@ -178,22 +185,57 @@ public void ReviewingAnAccessRequest()
{
}

[Then("There should be a Grant Access button allowing me to approve the user's request")]
public void ThereShouldBeAGrantAccessButton()
[Then(@"There should be a Grant Access button allowing me to approve the user's request ""(.*)""")]
public void ThereShouldBeAGrantAccessButton(string RequestingAccessUserEmail)
{
bool result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > tbody > tr:nth-child(1) > td:nth-child(9) > span > p-inputswitch > div"").checkVisibility()");

//Get email for first user in list
string email = (string)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#row-0 > td:nth-child(6)"").innerText");

//////////////////// DB Setup ////////////////////////////////////////
// Retrieve the user identity
_RequestingUserIdentity = _DssDBContext.DssUserIdentities.FirstOrDefault(p => p.EmailAddressDsc == email);
if (null == _RequestingUserIdentity)
{
throw new NotFoundException($"{email} not found in Identities table");
}
_OriginalAccessRequestStatusCd = _RequestingUserIdentity.AccessRequestStatusCd;
_RequestingUserIdentity.AccessRequestStatusCd = "Requested";

_DssDBContext.SaveChanges();

/////////////////////////////////////////////////////////////

_ManagingAccessPage.Driver.Navigate().Refresh();

bool result = false;

//Wait for control to become visable
for (int i = 0; i <= 3; i++)
{
if ((bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#row-0 > td:nth-child(8)"").checkVisibility()"))
{
result = true;
break;
}
System.Threading.Thread.Sleep(1000);
}
result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#row-0 > td:nth-child(8)"").checkVisibility()");

ClassicAssert.IsTrue(result);
}

//Role Assignment - NYI
[When("Clicking the Grant Access button")]
public void ClickingTheGrantAccessButton()
{
_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#form-approve-0-btn"").click()");
}

[Then("I should be prompted to assign the appropriate roles to the user based on their request and the system's role hierarchy")]
public void IShouldBePromptedToAssignTheAppropriateRolesToTheUser()
{
_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#cancel-dialog-btn"").click()");
}


Expand All @@ -217,7 +259,7 @@ public void ReviewingAnAccessRequestThatHasBeenGranted()
[Then("There should be a Remove Access option allowing me to remove the user's access if it is deemed inappropriate or unnecessary")]
public void ThereShouldBeARemoveAccessOption()
{
bool result = (bool)_ManagingAccessPage.ManageAccessSection.JSExecuteJavaScript(@"document.querySelector(""#pn_id_14-table > tbody > tr:nth-child(1) > td:nth-child(9) > span > p-inputswitch > div"").checkVisibility()");
bool result = (bool)_ManagingAccessPage.UserTable.JSExecuteJavaScript(@"document.querySelector(""#access-status-0-insw"").checkVisibility()");
ClassicAssert.IsTrue(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe

_UserType = userHelper.SetUserType(UserType);
//Authenticate user using IDir or BCID depending on the user
authHelper.Authenticate(UserName, _UserType);
authHelper.Authenticate(_TestUserName, _TestPassword, _UserType);

IWebElement TOC = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe
AuthHelper authHelper = new AuthHelper(_Driver);

//Authenticate user using IDir or BCID depending on the user
authHelper.Authenticate(_TestUserName, UserTypeEnum.LOCALGOVERNMENT);
authHelper.Authenticate(_TestUserName, _TestPassword, UserTypeEnum.LOCALGOVERNMENT);

IWebElement TOC = null;

Expand Down
Loading

0 comments on commit 4955c58

Please sign in to comment.