简体   繁体   English

C# Selenium 驱动程序 - 完成后关闭所有 web 页面

[英]C# Selenium driver - close all web pages after finish

        [SetUp]
        public void Setup()
        {
           //open web page
        }
        [Test]
        public void Test()
        {
           //test stuff
        }

C# selenium driver has two methods, you can set up for example opening browser and going to specific web page, and then testing specific elements, so you don't have to write opening part in each test method. C# selenium驱动有两种方法,可以设置例如打开浏览器,进入特定的web页面,然后在每个方法中测试具体的元素,所以你不必写打开部分。

But then all these web pages will stay open until you close them manually.但是所有这些 web 页面将保持打开状态,直到您手动关闭它们。 Is there an equivalent for Setup that runs after test has been completed, so you can close browser automatically?测试完成后是否有等效的Setup运行,以便您可以自动关闭浏览器?

Here is a way you can close each browser after the test finishes (assuming you are using Nunit and not MSTest , which it appears you are).这是一种可以在测试完成后关闭每个浏览器的方法(假设您使用的是Nunit而不是MSTest ,看起来您就是这样)。 You would place this at the bottom, after all your tests:在所有测试之后,您会将其放在底部:

[TearDown]
public void TearDown()
{
    if (driver != null)
    {
        driver.Dispose();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用SendKeys函数后C#Selenium Web驱动程序异常 - C# Selenium Web Driver Exception after using SendKeys Function Selenium (C#) Chrome 驱动程序:自 Chrome web 驱动程序版本 77 起,页面加载不再像以前那样管理 - Selenium (C#) Chrome driver: the pages loading is not managed as before since the version 77 of the Chrome web driver 使用Selenium 2 / Web驱动程序与C# - using Selenium 2 / Web Driver with C# C#中的Selenium Web驱动程序消息验证 - Selenium Web Driver Message validation in C# C#硒对URL的远程Web驱动程序服务器的HTTP请求在60秒后超时 - C# selenium HTTP request to the remote web driver server for URL timed out after 60 seconds Selenium C#-模拟后运行Selenium驱动程序时发生异常 - Selenium C# - exception when run selenium driver after impersonate 在Ubuntu 16.04中使用C#运行Selenium Web驱动程序 - Run Selenium web-driver with C# in Ubuntu 16.04 如何使用Selenium Web Driver和C#清除浏览器cookie - How to clear browser cookies using Selenium Web Driver and C# 无法将密钥发送到 Selenium Web 驱动程序 C# 中的文本框 - Unable to send keys to the text box in Selenium Web Driver C# Selenium 2.0远程Web驱动程序无法使用C#启动IEDriver - Selenium 2.0 Remote web driver fails to start IEDriver with C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM