2

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);
    }
}
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • Do the cards have links or javascript redirects? If its link, you could collect them and then navigate to each link to verify the information obtain from the primary page. – SILENT Aug 13 '20 at 22:19
  • That is a lot of code to read through and understand from scratch. Do you think you could please refactor it down the MRE? https://stackoverflow.com/help/minimal-reproducible-example – RichEdwards Aug 14 '20 at 13:36
  • I cut it down to just the code in question. I also added comments so hopefully my logic makes sense. – Brandon Jones Aug 14 '20 at 14:24
  • Where does the value of `coBorrower` get set? Can you please post the code for the entire class? – Greg Burghardt Aug 17 '20 at 14:41
  • @GregBurghardt - Let me know if I am missing something in the Page object class I provide the locator for the text of coborrower - [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; }************** In my looping method I validate that this element matches the text to validate if (coBorrowerFullName.Text.Contains(textToValidate)) { returnToMainTasks.Click(); } – Brandon Jones Aug 17 '20 at 15:54
  • Can you add the stack trace for the exception? – Greg Burghardt Aug 17 '20 at 16:55
  • @BrandonJones: I was able to resurrect some code from the edit history on your question. In the future, please [edit] your question when including code. Reading code in a comment is nigh impossible. – Greg Burghardt Aug 17 '20 at 16:56
  • After some discussion with a co-worker I am not sure if this is a valid issue any more- Thoughts - Once I navigate back to the 1st page that contains the cards there is not a way to pick up in the for loop where I "left off". If I start the for loop over then its going to just be an continuous loop with out any end. - issue being that the cards do not have a unique identifier. We utilize angular and from my understanding we can autopopulate unique id's. I can then use this Id to navigate back to where I left off in the forloop and continue. – Brandon Jones Aug 17 '20 at 17:21

0 Answers0