【发布时间】:2016-01-26 21:34:24
【问题描述】:
Selenium Webdriver 2.48、C#、NUnit 2.6.4、Chrome 驱动程序 当我从 NUnit 测试运行器运行我的测试时,如果单独运行,它们都会通过。
如果我选择一个主标题节点,并选择“运行”,组中的第一个测试将运行,其余的将失败。
如果我让测试夹具 [TearDown] 在每次测试结束时关闭驱动程序,则会出现以下错误: “无效的操作异常:没有这样的会话”
如果我让测试夹具 [TearDown] 退出驱动程序,则会出现以下错误: “意外错误。System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:无法建立连接,因为目标机器主动拒绝它 127.0.0.1:13806 在 System.Net.Sockets.Socket.DoConnect(端点 endPointSnapshot,SocketAddress 套接字地址) 在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& 套接字, IPAddress& 地址, ConnectSocketState 状态, IAsyncResult asyncResult, Exception& 异常)"
使用 driver.Quit() 或 driver.Close() 对结果没有影响 - 仅运行组中的第一个测试。
我已搜索但无法找到解决方案。必须可以通过从最顶层节点运行来运行所有测试,而不必选择每个测试并单独运行它们。任何帮助,将不胜感激。谢谢。迈克尔
这是一个在一个类中有两个测试的示例。我已经从测试中删除了大部分方法,因为它们很长。
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();
}
}
【问题讨论】:
-
您可以添加代码吗?具有设置、拆卸和测试方法的类
-
感谢您的回复。我编辑了原始消息并添加了代码。