【问题标题】:Is there is any method in Selenium class to close the browser at the end of the Selenium Test?Selenium 类中是否有任何方法可以在 Selenium 测试结束时关闭浏览器?
【发布时间】:2016-01-05 00:42:44
【问题描述】:

我正在通过 selenium-webdriver 测试我的测试用例。我的网络应用程序有一些设置操作,如单击、选择等。我使用了selenium.click() 方法。在测试结束时,我想自动关闭一个弹出窗口。有什么方法可以关闭 Selenium 类中的弹出窗口或浏览器吗?请帮助我是 selenium webdriver 测试的初学者。我用的是selenium server 2.37.0,浏览器是IE。

这是我的代码 sn-p:

namespace SeleniumTests
{                
    // this is my test method        
    [TestMethod]
    public void TheJan6Test()
    {
        selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://rcm-bpmt.apmoller.net");
        selenium.Start();
        verificationErrors = new StringBuilder();
        selenium.Open("workspace/faces/jsf/workspace/workspace.xhtml");


        // Here the steps regarding the automation of browser
        selenium.Type("id=portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionsTableSearch__OCID0__input", "198545");
        selenium.Click("id=portletComponentWorkList_viewNormalModeWorkList_viewPanel_searchWorkList");
        selenium.Click("id=portletComponentWorkList:viewNormalModeWorkList:viewPanel:instanceListTableWorkList:_OCID1_:executeLabel");

       //I want to close the popup after this step
       //At the end of test i want to close the one popup window automatically.Is there is any method to close the popup window or browser in Selenium Class
    }
}

请帮助我如何在测试结束时关闭弹出窗口。

【问题讨论】:

  • 谷歌上有大量资源供您查找。您是否尝试过搜索?
  • 这需要更多上下文。弹出窗口可以是很多东西,例如基本的 JS 弹出窗口、jQuery 模式对话框、一些疯狂的 HTML5 弹出窗口或物理浏览器窗口。那是什么?为我们提供有关该应用程序的更多上下文。此外,您使用的是旧的、已弃用的 (Selenium RC) 版本的 Selenium。

标签: c# selenium nunit


【解决方案1】:

如果我查看http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/AllMembers_T_Selenium_DefaultSelenium.htm#methodTableToggle上的api

selenium.Close 用于关闭弹出窗口

selenium.Stop(或 Quit)用于结束当前 Selenium 测试会话(通常会杀死浏览器)

【讨论】:

    【解决方案2】:

    也许这会对你有所帮助

    [TearDown]
    public void cleanup()
    {
        driver.Close();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 2023-02-19
      • 2017-02-09
      • 2011-11-26
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      相关资源
      最近更新 更多