public void PopupPageWithIndex() { // This test also shows the use of the WebTestConsole to add traces to the driver page // Navigate to the frameset HtmlPage page = new HtmlPage("TestFrameSet.htm"); //get the top frame WebTestConsole.Write("Get the top frame"); HtmlPage frame = page.GetFramePage("topFrame"); // click on the button that opens a new page WebTestConsole.Write("Click the openwindow button"); frame.Elements.Find("OpenWindow").Click(); // get popup window WebTestConsole.Write("Get the popup page"); HtmlPage popup = frame.GetPopupPage(1); // verify title of popup Assert.AreEqual("This is the Popup Page", popup.Elements.Find("h1", 0).GetInnerText()); // click on a button in popup window WebTestConsole.Write("Click on button inside popup"); popup.Elements.Find("ChangeSpanButton").Click(); Assert.AreEqual("Button has been clicked", popup.Elements.Find("TheSpan").GetInnerText()); //close the popup window WebTestConsole.Write("Click the button to close the popup"); popup.Elements.Find("CloseWindowButton").Click(); }
public void ExecuteCommand_ShouldSendsTracesOnlyForNextCommand() { //arrange MockCommandExecutor commandExec = new MockCommandExecutor(); commandExec.SetBrowserInfo(new BrowserInfo() { Data = "<html><body>Hello</body></html>" }); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test"); var testPage = new HtmlPage(); //act WebTestConsole.Clear(); WebTestConsole.Write("foo"); WebTestConsole.Write("bar"); testPage.Elements.Refresh(); //assert UnitTestAssert.AreEqual("GetPageDom", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual(2, commandExec.ExecutedCommands[0].Traces.Length); UnitTestAssert.AreEqual("foo", commandExec.ExecutedCommands[0].Traces[0]); UnitTestAssert.AreEqual("bar", commandExec.ExecutedCommands[0].Traces[1]); //act testPage.Elements.Refresh(); //assert UnitTestAssert.AreEqual(0, commandExec.ExecutedCommands[1].Traces.Length); }
public void ClearRemovesTraces() { WebTestConsole.Write("foo"); WebTestConsole.Write("bar"); Assert.IsTrue(WebTestConsole.GetTraces().Length > 0); WebTestConsole.Clear(); Assert.AreEqual(0, WebTestConsole.GetTraces().Length); }
public void WriteAddsMessageToList() { int originalCount = WebTestConsole.GetTraces().Length; WebTestConsole.Write("foo"); WebTestConsole.Write("bar"); Assert.AreEqual(originalCount + 2, WebTestConsole.GetTraces().Length); Assert.AreEqual("foo", WebTestConsole.GetTraces()[originalCount]); Assert.AreEqual("bar", WebTestConsole.GetTraces()[originalCount + 1]); }
private void RunTestsInternal(object state) { TestcaseExecutorTaskInfo taskInfo = (TestcaseExecutorTaskInfo)state; int threadId = Thread.CurrentThread.ManagedThreadId; // create a browser queue with this thread id CommandManager.CreateBrowserQueue(threadId); //notify the page that we just created a browser queue and send the thread id taskInfo.NotifyBrowserQueueCreated(threadId); BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.TestRunStarted); command.Description = "Test Run Started"; command.Handler.RequiresElementFound = false; command.Handler.SetArguments(_testcases.Count); CommandManager.ExecuteCommand(threadId, command, 10); OnTestRunStarted(new EventArgs()); foreach (Testcase testcase in taskInfo.Testcases) { testcase.TestcaseExecuting += new EventHandler <TestcaseExecutionEventArgs>(testcase_TestcaseExecuting); testcase.TestcaseExecuted += new EventHandler <TestcaseExecutionEventArgs>(testcase_TestcaseExecuted); // [05/05/2009] clear the traces that might have been left from a previous test. WebTestConsole.Clear(); try { testcase.Execute(); } catch (TimeoutException) { // Abort the test run if we receive a TimeoutException because // this likely means the browser has been closed and we don't // want the server to keep sending test commands and timing out // for each of them. return; } } command = new BrowserCommand(BrowserCommand.FunctionNames.TestRunFinished); command.Description = "Test Run Finished"; command.Handler.RequiresElementFound = false; BrowserInfo result = CommandManager.ExecuteCommand(threadId, command, 10); // Provide the results of the test run to anyone interested string log = result != null ? result.Data : null; taskInfo.RequestDetails.Add("TestLog", log); OnTestRunFinished(new TestRunFinishedEventArgs(taskInfo.Testcases, taskInfo.RequestDetails)); }