0
我正在運行一個使用c#,selenium和specflow的自動化測試套件。如果可能的話,我希望能夠看到爲當前場景分配了哪些標記,以便我可以爲每個場景實例化某種瀏覽器類型。這甚至可以使用XUnit?在WebDriver方法中獲取Specflow標記
登錄功能文件:
Feature: Login
In order to login to DRIVE
As a user
We have to enter login details
Background:
Given I am on the login page
@headless
Scenario: Logging in as a valid user
And I enter a valid user and password
When I submit the login form
Then The user should be logged in
WebDriverContext.cs文件
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;
namespace Drive.Acceptance.Tests
{
public interface IWebDriverContext {
IWebDriver GetDriver();
}
public class WebDriverContext : IWebDriverContext
{
private static volatile WebDriverContext _instance;
private static readonly object Lock = new object();
public static IWebDriverContext Instance
{
get
{
if (_instance == null)
{
lock (Lock)
{
if (_instance == null)
_instance = new WebDriverContext();
}
}
return _instance;
}
}
public IWebDriver GetDriver()
{
lock (Lock)
{
// TODO: create headless browser if scenario is tagged with @headless
if (!TagName.Contains("headless")) {
return new ChromeDriver();
}
else {
return new PhantomJSDriver();
}
}
}
}
}