Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created February 19, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/232ee98675aea772854c2bed71e118c4 to your computer and use it in GitHub Desktop.
Save angelovstanton/232ee98675aea772854c2bed71e118c4 to your computer and use it in GitHub Desktop.
public class ResourcesPage
{
private readonly IWebDriver driver;
private readonly string url = @"https://automatetheplanet.com/resources/";
public ResourcesPage(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}
public string Url => this.url;
[FindsBy(How = How.Id, Using = "emailId")]
public IWebElement Email { get; set; }
[FindsBy(How = How.Id, Using = "nameId")]
public IWebElement Name { get; set; }
[FindsBy(How = How.Id, Using = "downloadBtnId")]
public IWebElement DownloadButton { get; set; }
[FindsBy(How = How.Id, Using = "successMessageId")]
public IWebElement SuccessMessage { get; set; }
public IWebElement GetGridElement(string productName, int rowNumber)
{
var xpathLocator = $"(//span[text()='{productName}'])[{rowNumber}]/ancestor::td[1]/following-sibling::td[7]/span";
return this.driver.FindElement(By.XPath(xpathLocator));
}
public void Navigate() => this.driver.Navigate().GoToUrl(this.url);
public void DownloadSourceCode(string email, string name)
{
this.Email.SendKeys(email);
this.Name.SendKeys(name);
this.DownloadButton.Click();
var successMessage = $"Thank you for downloading {name}! An email was sent to {email}. Check your inbox.";
var waitElem = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
waitElem.Until(ExpectedConditions.TextToBePresentInElementLocated(By.Id("successMessageId"), successMessage));
}
public void AssertSuccessMessage(string name, string email)
{
var successMessage = $"Thank you for downloading {name}! An email was sent to {email}. Check your inbox.";
Assert.AreEqual(successMessage, this.SuccessMessage.Text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment