Created
February 22, 2016 14:19
-
-
Save sjtipton/19a4bc5a40d2d63bafc4 to your computer and use it in GitHub Desktop.
C# Selenium test dependent on Angular ngClick event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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