有哪些方法可以在Selenium中跟踪打开的窗口?

时间:2016-06-30 04:17:37

标签: javascript c# asp.net selenium

想了解一下你们如何用Selenium跟踪打开的窗户的想法。下面的UI测试只测试2个窗口,但实际上我需要跟踪的大约4个窗口可以同时打开。

[TestMethod]
public void Multiple_windows_dictionary_tracker_test()
{
    //arrange
    _driver.Url = "http://localhost:58301/TestingMultiWindows.aspx";
    //Get something on page to make sure page loaded.
    IWebElement link = GetElement(By.Id("HyperLink1"));
    string windowOneTitle = "Window One";
    string windowTwoTitle = "Hello World";            
    //Track opened windows in dictionary
    Dictionary<string, string> openedWindows = new Dictionary<string, string>();
    openedWindows.Add(windowOneTitle, _driver.WindowHandles[0]);
    Inject_jQuery(string.Format("document.title = '{0}';", windowOneTitle), true);
    _wait.Until(x => _driver.Title == windowOneTitle);
    //act
    string secondWinKey = OpenNewWindow(windowTwoTitle, "HyperLink1", true);
    openedWindows.Add(windowTwoTitle, secondWinKey);
    //assert
    _wait.Until(x => _driver.Title == windowTwoTitle);
    _driver.SwitchTo().Window(openedWindows[windowOneTitle]);
    _wait.Until(x => _driver.Title == windowOneTitle);
}

0 个答案:

没有答案