我目前正在使用C#,nunit
和Selenium構建一個自動化項目,我試圖設置一個安裝類,它將在運行任何TestFixture
之前初始化硒webdriver,他們已經結束,並試圖從TestFixture
在每個TestFixture
OneTimeSetUp
屬性中獲得該webdriver,可以這樣做,或者我應該改變selenium類爲靜態,以便能夠獲得每個TestFixture
安裝程序中的驅動程序字段?將參數傳遞給TestFixture OneTimeSetUp從SetUpFixture
這樣的基本結構是這樣的:
[SetUpFixture]
public class Test
{
[OneTimeSetUp]
public void Init()
{
_driver = new Driver();
}
}
[TestFixture]
public class FirstTest
{
[OneTimeSetUp]
public void Init()
{
xxxxxxxxxx - here I need to initialize a class with the driver from the setup class
}
}
是否要爲每個測試初始化和關閉驅動程序,或者僅針對所有測試進行一次? – Guy
對於所有測試來說,setupfixture應該在所有測試之前運行setup一次,然後在所有測試完成後關閉驅動程序一次,然後拆卸它。 –
爲什麼不創建一個類並在構造函數中初始化驅動程序並繼承這個類到你想要的類? – Sham