public void ClickAllControlsOnPage_UsingReflection_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <a href=""#"">test</a> <button>test</button> <input type=""text"" value=""test""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); ControlBase a = window.Find <HtmlHyperlink>(By.SearchProperties("InnerText=test")); a.Click(); List <Type> list = new List <Type>(); list.Add(typeof(HtmlHyperlink)); list.Add(typeof(HtmlButton)); list.Add(typeof(HtmlEdit)); MethodInfo getMethodInfo = typeof(BrowserWindowUnderTest).GetMethod("Find", new[] { typeof(By) }); foreach (Type t in list) { MethodInfo test = getMethodInfo.MakeGenericMethod(t); ControlBase control; if ((t == typeof(HtmlEdit)) || (t == typeof(HtmlTextArea))) { control = (ControlBase)test.Invoke(window, new object[] { By.ValueAttribute("test") }); } else { //window.Find<t>("InnerText=test"); control = (ControlBase)test.Invoke(window, new object[] { By.SearchProperties("InnerText=test") }); } //Act control.Click(); if (control is HtmlEdit) { (control as HtmlEdit).Text = "text"; } else if (control is HtmlTextArea) { (control as HtmlTextArea).Text = "text"; } } window.Close(); } }
private static PageBase ClickAndGetPage(this ControlBase control) { control.Click(); return((PageBase)control.GetRootContainer()); }