在Selenium测试结束时,Selenium类中是否有任何方法可以关闭浏览器?

时间:2014-01-09 16:17:37

标签: c# selenium nunit

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

这是我的代码段:

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
    }
}

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

2 个答案:

答案 0 :(得分:1)

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

上的api

selenium.Close关闭弹出窗口

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

答案 1 :(得分:1)

可能这会对你有所帮助

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