Skip to content

Commit

Permalink
Merge pull request #603 from bcgov/ricander
Browse files Browse the repository at this point in the history
Make Javascript code another type of locator in the POM. Working for …
  • Loading branch information
ychung-mot authored Sep 5, 2024
2 parents f4c0756 + b83cf9e commit b224f41
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public void GivenIAmAauthenticatedGovernmentUser(string UserName, string Expecte

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public void GivenIAmAauthenticatedLGStaffMemberUser(string UserName, string Expe
if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();

_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public void WhenUserEntersValidLoginCredentialsAndClicksLoginButton(string UserN

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public void WhenUserEntersValidLoginCredentialsAndClicksLoginButton(string UserN

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public void WhenUserEntersValidLoginCredentialsAndClicksLoginButton(string UserN

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();
_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public void ThenIShouldBePromptedToAcceptTheTermsAndConditions()

if ((null != TOC) && (TOC.Displayed))
{
//Nested Angular controls obscure the TermsAndConditionsCheckbox. Need JS
_TermsAndConditionsPage.TermsAndConditionsCheckBox.JSExecuteJavaScript(@"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()");
_TermsAndConditionsPage.TermsAndConditionsCheckBox.Click();

_TermsAndConditionsPage.ContinueButton.Click();
}
}
Expand Down
7 changes: 5 additions & 2 deletions Test/UITest/TestFrameWork/Models/TermsAndConditionsModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace TestFrameWork.Models
{
public class TermsAndConditionsModel
{

{
public static string TermsAndCondititionsCheckBox { get => "body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"; }

public static string ContinueButton { get => "continue-btn"; }

public static string TermsAndCondititionsCheckBoxJS { get => @"document.querySelector(""body > app-root > app-layout > div.content > app-terms-and-conditions > p-card > div > div.p-card-body > div > div > div.checkbox-container > p-checkbox > div > div.p-checkbox-box"").click()"; }

}
}
2 changes: 1 addition & 1 deletion Test/UITest/TestFrameWork/PageObjects/BCIDPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BCIDPage(IDriver Driver)
_Driver = Driver;
_UserNameTextBox = new TextBox(Driver, Enums.FINDBY.ID, BCIDModel.UserName);
_PasswordTextBox = new TextBox(Driver, Enums.FINDBY.ID, BCIDModel.Password);
_ContinueButton = new(Driver, Enums.FINDBY.CSSSELECTOR, BCIDModel.ContinueButton);
_ContinueButton = new Button(Driver, Enums.FINDBY.CSSSELECTOR, BCIDModel.ContinueButton);
}


Expand Down
4 changes: 1 addition & 3 deletions Test/UITest/TestFrameWork/PageObjects/IDirLoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public IDirLoginPage(IDriver Driver)
_Driver = Driver;
_UserNameTextBox = new TextBox(Driver, Enums.FINDBY.ID, IDirLogonModel.IDRUserName);
_PasswordTextBox = new TextBox(Driver, Enums.FINDBY.ID, IDirLogonModel.IDRPassword);
_ContinueButton = new(Driver, Enums.FINDBY.CSSSELECTOR, IDirLogonModel.ContinueButton);
_ContinueButton = new Button(Driver, Enums.FINDBY.CSSSELECTOR, IDirLogonModel.ContinueButton);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace UITest.PageObjects
public class TermsAndConditionsPage
{
private CheckBox _TermsAndConditionsCheckBox;

private Button _ContinueButton;
private IDriver _Driver;

Expand All @@ -18,8 +19,8 @@ public class TermsAndConditionsPage
public TermsAndConditionsPage(IDriver Driver)
{
_Driver = Driver;
_TermsAndConditionsCheckBox = new CheckBox(Driver, Enums.FINDBY.CSSSELECTOR, TermsAndConditionsModel.TermsAndCondititionsCheckBox);
_ContinueButton = new Button(Driver, Enums.FINDBY.ID, TermsAndConditionsModel.ContinueButton);
_TermsAndConditionsCheckBox = new CheckBox(Driver, Enums.FINDBY.JAVASCRIPT, TermsAndConditionsModel.TermsAndCondititionsCheckBoxJS);
}
}
}
3 changes: 0 additions & 3 deletions Test/UITest/TestFrameWork/SeleniumObjects/DropDownList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ namespace UITest.TestObjectFramework
{
public class DropDownList : UIElement
{
private IDriver _Driver;

public DropDownList(IDriver Driver, Enums.FINDBY LocatorType, string Locator) : base(Driver)
{
_Driver = Driver;
base.Locator = Locator;
base.LocatorType = LocatorType;
}
Expand Down
32 changes: 18 additions & 14 deletions Test/UITest/TestFrameWork/SeleniumObjects/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ virtual public bool Click()
{
try
{
FindElement(LocatorType, Locator);
Element.Click();
if (LocatorType == Enums.FINDBY.JAVASCRIPT)
{
JSExecuteJavaScript(Locator);
}
else
{
FindElement(LocatorType, Locator);
Element.Click();
}
}
catch (Exception ex)
{
Expand All @@ -65,7 +72,15 @@ virtual public bool Click()

public bool FindElement(Enums.FINDBY By, string Locator)
{
Element = _Driver.FindElement(By, Locator);
if (By == Enums.FINDBY.JAVASCRIPT)
{
//do not try to locate
}
else
{
Element = _Driver.FindElement(By, Locator);
}

return (true);
}

Expand Down Expand Up @@ -117,17 +132,6 @@ public object JSExecuteJavaScript(string Script)
return (result);
}

/// <summary>
/// Finds a Web Element of the current locator type (Use when a locator can change)
/// </summary>
/// <param name="Locator"></param>
/// <returns></returns>
public IWebElement FindElement(string Locator)
{
Element = _Driver.FindElement(LocatorType, Locator);
return (Element);
}

public ReadOnlyCollection<IWebElement> FindElements(Enums.FINDBY By, string Locator)
{
ReadOnlyCollection<IWebElement> elements = _Driver.FindElements(By, Locator);
Expand Down

0 comments on commit b224f41

Please sign in to comment.