![](/img/trans.png)
[英]C# NUnit(3.11) SetUp/OneTimeSetUp and TearDown/OneTimeTearDown functions not invoked on test run
[英]C# NUnit SetUp and TearDown functions not running when using SpecFlow
我正在嘗試使用NUnit和Selenium創建自動化測試,但是無法使SetUp和TearDown函數正常工作。
[Binding] [SetUpFixture]
public class AuthenticatorSteps
{
IWebDriver _driver;
WebDriverWait wait;
string username;
string password;
[SetUp]
public void SetUp()
{
_driver = new ChromeDriver();
wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
}
[TearDown]
public void TearDown()
{
_driver.Close();
}
[Given(@"I am on the site")]
public void GivenIAmOnTheSite()
{
_driver.Manage().Window.Maximize();
_driver.Navigate().GoToUrl("https://qa02-ukcasino.bedegaming.net");
wait.Until(x => x.FindElement(By.CssSelector(AuthenticatorElements.LoginButton)));
}
他們根本沒有被召集。 如果我將代碼放在步驟本身中,則我正在使用的代碼會起作用,但是這需要我添加一個步驟。 然后,當我應該能夠使用TearDown函數時,瀏覽器應該關閉。
這是單元測試嗎?
將您的[SetUpFixture]
更改為[TestFixture]
。
(注意:如果您使用的是NUnit 2.5或更高版本,則可以刪除[TestFixture])
后者用於一次設置,而前者用於每次測試的設置。
這是SpecFlow測試嗎?
我還假設您將SpecFlows測試運行程序設置為NUnit 。
您需要使用BeforeScenario
或BeforeFeature
屬性,而不是NUnit屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.