首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NUnit不会连续运行Selenium Webdriver C#测试

NUnit不会连续运行Selenium Webdriver C#测试
EN

Stack Overflow用户
提问于 2016-01-20 19:28:05
回答 1查看 1.7K关注 0票数 0

Selenium Webdriver 2.48,C#,NUnit 2.6.4,Chrome Driver当我从NUnit测试运行器运行我的测试时,如果单独运行,它们都通过了。

如果我选择一个主标题节点,并选择" run ",该组中的第一个测试将运行,其余测试将失败。

如果我让测试夹具在每次测试结束时关闭驱动程序,则会出现以下错误:"Invalid OPeration TearDown : No OPeration session“

如果安装了测试夹具并退出驱动程序,则会出现以下错误:“意外错误。System.Net.WebException:无法连接到远程服务器-> System.Net.Sockets.SocketException:无法连接到远程服务器->System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在TearDown connectFailure,Socket s4,Socket s6,Socket& socket,If地址&地址,ConnectSocketState状态,IAsyncResult asyncResult,Exception& exception)的System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)上主动拒绝了它127.0.0.1:13806”

使用driver.Quit()或driver.Close()对结果没有影响--只有组中的第一个测试在运行。

我已经找过了,但还是找不到解决方案。必须能够通过从最顶层节点运行来运行所有测试,而不是必须选择每个测试并单独运行它们。任何帮助都将不胜感激。谢谢。迈克尔

下面是一个在一个类中包含两个测试的示例。我已经从测试中删除了大多数方法,因为它们非常长。

代码语言:javascript
复制
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using NUnit.Framework;
using SiteCore.HousingRepairsLogic;

namespace SiteCore.HousingRepairsTests.DoorsAndWindowsTests
{
[TestFixture]
class DoorsTests
{
    private IWebDriver driver = new     ChromeDriver(@"C:\chromedriver_win32");

    [SetUp]
    public void setup()
    {
        HousingRepairsLogic.Utilities utilities = new Utilities(driver);
        utilities.NavigateToLogin();
    }

    [TearDown]

    public void teardown()
    {
        Utilities utilities = new Utilities(driver);
        utilities.CloseDriver();
    }


    [Test]

    public void LockRepair()
    {

        //Create Instance of the HomePage class
        HomePage homepage = new HomePage(driver);

        homepage.ClickHousingButton();
        homepage.RequestRepairButton();
        homepage.RequestRepairNowButton();
}
  [Test]

    public void ExternalWoodDoorFrameDamaged()
    {


        //Create Instance of the HomePage class
        HomePage homepage = new HomePage(driver);

        homepage.ClickHousingButton();
        homepage.RequestRepairButton();
        homepage.RequestRepairNowButton();

        //Create instance of TenancyPage class

        TenancyPage tenancy = new TenancyPage(driver);
        //proceed with login
        tenancy.ClickYesLoginButton();
        //enter username
        tenancy.EnterMyeAccountUserName();
        //enter password
        tenancy.EnterMyeAccountPassword();
        //click the login button
        tenancy.ClickLoginButton();
}
    }
EN

回答 1

Stack Overflow用户

发布于 2016-01-26 21:34:24

在fixture中初始化驱动程序一次,当它被声明时:

私有IWebDriver驱动=新ChromeDriver(@"C:\chromedriver_win32");

然后您的第一个测试运行,使用驱动程序和teardown关闭它。下一个测试不再使用驱动程序。您需要:在安装程序中重新初始化驱动程序,或者需要在fixture teardown中关闭它。

如果你选择在setup/teardown中初始化和关闭,你会看到驱动程序会为每个测试启动一个新的浏览器会话。这将确保你的测试是相互独立的,但它将花费更多的运行时间。

如果您希望在所有测试中重用浏览器会话:将初始化和闭包移至TestFixture Setup和TestFixture Teardown方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34898771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档