I am currently experiencing an issue with an application that I am working on. Tools: Selenium, Visual Studio, C#, PageObjecFactory, PageObjectModel
Summary of test: I have an application in which I search by an email address: After the search is completed "cards" populate that contain guests names. An issue I found is that some of the cards are associated to the email address but the names do not match. Basically you have to click on the "card" to go to "details" page and validate that the person you searched for is associated on that card.
To accomplish this I built a for loop which I iterate through the "cards" If the name on the card does not match the text I am looking for then I click into the "card" which navigates to the "details" page and I locate the name (as an associated party). The problem I am running into is that when I navigate back to the original page with all of the cards I am not continuing with my for loop.
I am not sure if it is even possible (while in a for loop) to navigate to a different page, validate info, and then navigate back to the original page AND continue right where you left off in the forloop.
Page Model
class LightHousePage
{
private IWebDriver driver;
public LightHousePage(IWebDriver driver)
{
this.driver = driver;
PageFactory.InitElements(driver, this);
}
[FindsBy(How = How.Id, Using = "search_input")]
[CacheLookup]
private IWebElement SearchBorrowers { get; set; }
[FindsBy(How = How.ClassName, Using = "task-info-section")]
[CacheLookup]
private IWebElement taskCard { get; set; }
//CoBorrower Icon
[FindsBy(How = How.ClassName, Using = "cls-2borrowercoborrower")]
[CacheLookup]
private IWebElement coBorrower { get; set; }
//CoBorrower Name
[FindsBy(How = How.XPath, Using = "//*[@id='mat-tab-content-0-0']/div/div/app-borrower-info/div/div/div[1]/div[1]/span[2]")]
[CacheLookup]
private IWebElement coBorrowerFullName { get; set; }
//Opportunity View Return to Main Tasks back button
[FindsBy(How = How.ClassName, Using = "back-button")]
[CacheLookup]
private IWebElement returnToMainTasks { get; set; }
/// <summary>
/// Utilze the search bar on the LIght house page
/// </summary>
/// <returns>The LoginPage class instance.</returns>
public LightHousePage searchInput (string searchText)
{
new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementToBeClickable(SearchBorrowers));
SearchBorrowers.Click();
SearchBorrowers.SendKeys(searchText);
SearchBorrowers.SendKeys(Keys.Enter);
Thread.Sleep(3000);
return this;
}
/// <summary>
/// email search varification
/// </summary>
/// <returns>The LoginPage class instance.</returns>
public LightHousePage validateCards2(string textToValidate)
{
List<IWebElement> tags = new List<IWebElement>(driver.FindElements(By.ClassName("task-info-section")));
for (int i = 0; i < tags.Count; i++)
{
if (!tags[i].Text.Contains(textToValidate))
{
tags[i].Click();
Thread.Sleep(2000);
coBorrower.Click();
if (coBorrowerFullName.Text.Contains(textToValidate))
{
returnToMainTasks.Click();
//appears to not be continuting loop prog
}
else
{
throw new Exception("LightHouse: Search Error");
}
}
}
return this;
}
}
Test Class
[TestClass]
public class LightHouseSearchByEmail : DesktopHeadlessLocalTestsBase
{
//public TestContext TestContext { get; set; }
private static IWebDriver driver;
private static NameValueCollection LighthouseUrls = ConfigurationManager.GetSection("Lighthouse/LighthouseUrls") as NameValueCollection;
private static string LighthouseUrl = LighthouseUrls.Get("LighthouseUrl");
private static readonly Logger logger = new Logger();
private readonly ExcelData excelData = new ExcelData();
[TestMethod]
public void TestMethod1()
{
driver = HeadlessDriverSetup();
driver.Navigate().GoToUrl(LighthouseUrl);
LightHousePage lp = new LightHousePage(driver);
OktaLoginPage op = new OktaLoginPage(driver);
logger.Log("Navigate to the Light House page", driver);
lp.searchInput("dummy.singer@veteransunited123.com");
lp.validateCards2("Cx.Assumption Carrie");
logger.Log("LightHouse CRM Search validation is complete", driver);
}
}