BDD SpecFlow当前上下文中不存在名称ConfigurationManager

时间:2016-11-20 13:25:23

标签: c# bdd specflow

我正在使用Visual Studio 2015中的SpecFlow 2.1.0尝试BDD 我想使用App.config文件来指定我想要使用的浏览器,例如Chrome浏览器和网址。 要使用它,我应该使用以下代码行:

ConfigurationManager.AppSettings["browser"];

但我收到错误:

The name ConfigurationManager does not exist in the current context

我提到ConfigurationManager的步骤如下:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Assist;

namespace SpecflowFirst.Steps
{
    [Binding]
    class GoogleSearchSteps
    {
        private static IWebDriver _driver;  

        [Given(@"I have navigated to Google page")]
        public void GivenIHaveNavigatedToGooglePage()
        {
            string driverConfig = ConfigurationManager.AppSettings["browser"];
            _driver = new ChromeDriver(@"E:\Selenium\Browser Drivers\");
            ConfigureDriver();
            _driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["baseURL"];)

        }
// etc more steps below

我的App.config文件如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
  <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="NUnit" />
</specFlow>
  <appSettings>
    <add key="baseURL" value="http://www.google.co.uk"/>
    <add key="browser" value="Chrome"/>
  </appSettings>

</configuration>

我错过了参考包还是我的语法错了?

感谢您的帮助,Riaz

0 个答案:

没有答案