public frmAutomateIE() { InitializeComponent(); Program.closeClicked = false; try { webBrowser1 = new IEDriver(false, null, null, textBox1); webBrowser1.Open("about:blank"); textBox1.AppendText("Starting..." + Environment.NewLine); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
/// <summary> /// This is the "meat" of the decision engine. Take the test script, parse /// the XML element and attributes, then execute the proper step. /// </summary> private void RunTest() { XmlDocument doc = new XmlDocument(); doc.LoadXml(tecMain.Text); if (doc.SelectNodes("//testplan").Count > 0) { foreach (XmlNode step in doc.SelectSingleNode("//testplan").ChildNodes) { if (step.NodeType != XmlNodeType.Element) continue; string id = step.Attributes["id"] == null ? null : step.Attributes["id"].InnerText; string url = step.Attributes["url"] == null ? null : step.Attributes["url"].InnerText; string cellContents = step.Attributes["contents"] == null ? null : step.Attributes["contents"].InnerText; string value = step.Attributes["value"] == null ? null : step.Attributes["value"].InnerText; string tableId = step.Attributes["tableId"] == null ? null : step.Attributes["tableId"].InnerText; string pageName = step.Attributes["pageName"] == null ? null : step.Attributes["pageName"].InnerText; string pageTitle = step.Attributes["pageTitle"] == null ? null : step.Attributes["pageTitle"].InnerText; bool startsWith = bool.Parse(step.Attributes["startsWith"] == null ? "false" : step.Attributes["startsWith"].InnerText); bool caseSensitive = bool.Parse(step.Attributes["caseSensitive"] == null ? "false" : step.Attributes["caseSensitive"].InnerText); bool append = bool.Parse(step.Attributes["append"] == null ? "false" : step.Attributes["append"].InnerText); int index = int.Parse(step.Attributes["index"] == null ? "0" : step.Attributes["index"].InnerText); int cellOffset = int.Parse(step.Attributes["offset"] == null ? "0" : step.Attributes["offset"].InnerText); int cellPosition = int.Parse(step.Attributes["position"] == null ? "0" : step.Attributes["position"].InnerText); int inFrameNumber = int.Parse(step.Attributes["inFrameNumber"] == null ? "-1" : (step.Attributes["inFrameNumber"].InnerText == "" ? "-1" : step.Attributes["inFrameNumber"].InnerText)); int timeOut = int.Parse(step.Attributes["timeOut"] == null ? "30000" : (step.Attributes["timeOut"].InnerText == "" ? "-1" : step.Attributes["timeOut"].InnerText)); switch (step.Name.ToLowerInvariant()) { case "sleep": System.Threading.Thread.Sleep(timeOut); break; case "close": webBrowser1.Close(); break; case "attach": webBrowser1 = new IEDriver(true, pageName, pageTitle, textBox1); break; case "wait": webBrowser1.WaitForPageToLoad(timeOut, null, false); break; case "waitfor": webBrowser1.WaitForPageToLoad(timeOut, pageName, true); break; case "open": webBrowser1.Open(url); break; case "getpagetitle": webBrowser1.GetPageTitle(); break; case "getelementinnertext": webBrowser1.GetElementInnerText(inFrameNumber, id); break; case "getelementvalue": webBrowser1.GetElementValue(inFrameNumber, id); break; case "clickbutton": webBrowser1.ClickButton(inFrameNumber, id); break; case "clicknamedlink": webBrowser1.ClickNamedLink(inFrameNumber, id); break; case "clicktextlink": webBrowser1.ClickTextLink(inFrameNumber, value, caseSensitive); break; case "settextboxtext": webBrowser1.SetTextBoxText(inFrameNumber, "INPUT", id, value, append); break; case "settextareatext": webBrowser1.SetTextBoxText(inFrameNumber, "TEXTAREA", id, value, append); break; case "setselectvalue": webBrowser1.SetSelectValue(inFrameNumber, id, value); break; case "setcheckbox": webBrowser1.SetCheckableControl("CHECKBOX", inFrameNumber, index, id, value); break; case "setradiobutton": webBrowser1.SetCheckableControl("RADIOBUTTON", inFrameNumber, index, id, value); break; case "verifytext": webBrowser1.VerifyTextOnPage(inFrameNumber, value, caseSensitive); break; case "clicklinkintd": webBrowser1.ActionInTD(index, inFrameNumber, "LINK", tableId, cellContents, value, startsWith, cellOffset, cellPosition); break; case "setcheckboxintd": webBrowser1.ActionInTD(index, inFrameNumber, "CHECKBOX", tableId, cellContents, value, startsWith, cellOffset, cellPosition); break; case "setradiobuttonintd": webBrowser1.ActionInTD(index, inFrameNumber, "RADIOBUTTON", tableId, cellContents, value, startsWith, cellOffset, cellPosition); break; } } } }