Skip to content

Instantly share code, notes, and snippets.

@sjtipton
Created February 22, 2016 14:19
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 sjtipton/19a4bc5a40d2d63bafc4 to your computer and use it in GitHub Desktop.
Save sjtipton/19a4bc5a40d2d63bafc4 to your computer and use it in GitHub Desktop.
C# Selenium test dependent on Angular ngClick event
/* Helper class */
public sealed class ElementInteractionHelper
{
private readonly IJavaScriptExecutor _executor;
private const string NgClick = "arguments[0].click();";
public ElementInteractionHelper() { }
public ElementInteractionHelper(InternetExplorerDriver driver)
{
_executor = driver;
}
public void InvokeNgClickOnElement(IWebElement element)
{
_executor.ExecuteScript(NgClick, element);
}
}
/* Test method */
// All properties used are assumed to be defined higher up in the test file (not shown for brevity)
[TestMethod]
public void ClickingHelpShouldDisplayCorrectHelpContent()
{
// arrange
CurrentPage.Url.PathName = "path/to/page";
var interactionHelper = new ElementInteractionHelper(IeDriver);
// act
IeDriver.Navigate().GoToUrl(CurrentPage.Url.AbsoluteUrl());
var target = IeDriver.FindElement(By.CssSelector("div.page-header"));
var helpButton = target.FindElement(By.CssSelector("button i.fa-question-circle"));
interactionHelper.InvokeNgClickOnElement(helpButton);
// assert
var helpSection = IeDriver.FindElement(By.CssSelector("div.panel"));
var helpSectionHeading = helpSection.FindElement(By.CssSelector("div.panel-heading"));
Assert.AreEqual("Help", helpSectionHeading.Text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment