我目前正在处理的应用程序遇到问题。工具:Selenium、Visual Studio、C#、PageObjecFactory、PageObjectModel
测试总结:我有一个应用程序,我在其中通过电子邮件地址进行搜索:搜索完成后,填充包含客人姓名的“卡片”。我发现的一个问题是某些卡片与电子邮件地址相关联,但名称不匹配。基本上,您必须单击“卡片”才能进入“详细信息”页面并验证您搜索的人是否与该卡片相关联。
为了实现这一点,我构建了一个 for 循环,它遍历“卡片”名称(作为关联方)。我遇到的问题是,当我使用所有卡片导航回原始页面时,我没有继续我的 for 循环。
我不确定是否甚至可以(在 for 循环中)导航到不同的页面,验证信息,然后导航回原始页面并从你在 forloop 中离开的地方继续。
页面模型
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;
}
}
测试班
[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);
}
}