我在Specflow中遇到问题。由于某些原因,每个步骤都会启动chrome的新实例。 你能帮忙吗?
对于跟随测试,启动3个步骤,3个chrome实例。
Feature: Home
Background:
Given The QA Department site
Scenario: QA Department title
When QA site open
Then QA site tile must be "UI Testing Site"
第一个实例具有我想要的内容,而其他两个我不知道为什么启动的内容为空。
namespace QAtests.SpecFlow_Steps.Home
{
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
[Binding]
class HomeTestSteps
{
private readonly MainPage mainPage = new MainPage();
private readonly PageHelper pageHelper = new PageHelper();
public HomeTestSteps()
{
}
[When(@"QA Department site open")]
public void GivenQADepartmentSiteOpen()
{
var url = this.mainPage.ValiteSiteAddress();
Assert.AreEqual(url,this.mainPage.siteURL);
}
[Then(@"QA Department site tile must be ""(.*)""")]
public void ThenQADepartmentSiteTileMustBe(string pageTile)
{
var title = this.pageHelper.GetElementTitle();
Assert.AreEqual(pageTile,title);
}
}
}
主页类仅设置网址并检查元素
namespace QAtests.Pages.Main
{
public class MainPage
{
private ChromeDriver driver = new ChromeDriver();
private readonly string elementTitle = "//title";
public readonly string siteURL = "http://uitest.duodecadits.com/";
public MainPage()
{
}
public void StartSite()
{
try
{
this.driver.Navigate().GoToUrl(siteURL);
}
catch (Exception e)
{
throw new Exception("Can´t set address.",e);
}
}
public void Close()
{
this.driver.Close();
}
public string ValiteSiteAddress()
{
return this.driver.Url;
}
public IWebElement ElementTitleisVisible()
{
try
{
return this.driver.FindElement(By.XPath(elementTitle));
}
catch(Exception e){
throw new Exception("Element tile not found.",e);
}
}
}
}
我认为这与
的声明有关private ChromeDriver driver = new ChromeDriver();