Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# system.collection.generic.keyNotFoundException_C#_Selenium_Generics_Specflow - Fatal编程技术网

C# system.collection.generic.keyNotFoundException

C# system.collection.generic.keyNotFoundException,c#,selenium,generics,specflow,C#,Selenium,Generics,Specflow,尝试打开浏览器时,我收到System.Collections.Generic.KeyNotFoundException。谁能调查一下这个问题吗。请查找以下文件 App.Config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="specFlow" type="TechTalk.SpecFlow.Configurati

尝试打开浏览器时,我收到System.Collections.Generic.KeyNotFoundException。谁能调查一下这个问题吗。请查找以下文件

App.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
    <section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration" />
  </configSections>

<appSettings>
    <add key="seleniumBaseUrl" value="http://www.verivox.de/" />
</appSettings>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="TechTalk.SpecFlow" publicKeyToken="0778194805d6db41" culture="neutral" />
        <assemblyIdentity name="TechTalk.SpecFlow" publicKeyToken="0778194805d6db41" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="1.9.0.77" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <autofac>
    <components>
      <component name="IE" type="OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Chrome" type="OpenQA.Selenium.Chrome.ChromeDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <!-- Example of using an injected RemoteDriver:
      <component
              name="IE"
              type="Baseclass.Contrib.SpecFlow.Selenium.NUnit.RemoteWebDriver, Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin"
              service="OpenQA.Selenium.IWebDriver, WebDriver"
              instance-scope="per-dependency">
        <parameters>
          <parameter name="url" value="http://127.0.0.1:4444/wd/hub" />
          <parameter name="browser" value="InternetExplorer">
          </parameter>
        </parameters>
      </component>-->
    </components>
  </autofac></configuration>
我的步骤定义文件

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings;
using OpenQA.Selenium;
using TechTalk.SpecFlow;
using Verivox.Pages;

namespace Verivox.Steps
{
    [Binding]
    class StrompreisvergleichSteps
    {

        [Given(@"I am on Verivox Home Page")]
        public void GivenIAmOnVerivoxHomePage()
        {
            Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
            PropertyCollection.currentPage = new HomePage();

        }

        [When(@"I have entered (.*) and (.*)")]
        public void WhenIHaveEnteredAnd(String postalCode, String Usage)
        {
            PropertyCollection.currentPage.As<HomePage>().EnterPostalCode(postalCode);
            PropertyCollection.currentPage.As<HomePage>().EnterUsage(Usage);
        }

        [When(@"I clicked on Jetzt verglei button")]
        public void WhenIClickedOnJetztVergleiButton()
        {
            PropertyCollection.currentPage = PropertyCollection.currentPage.As<HomePage>().SubmitStrom();
        }

        [When(@"I clik on Jetzt wechsein button in the eprimo in Strom Page")]
        public void WhenIClikOnJetztWechseinButtonInTheEprimoInStromPage()
        {
            PropertyCollection.currentPage = PropertyCollection.currentPage.As<StromPage>().clickItemJetztButton();
        }

        [Then(@"the eprimo Strom page appear")]
        public void ThenTheEprimoStromPageAppear()
        {
            PropertyCollection.currentPage.As<EprimoPage>().verifyPageHeader();

        }

    }
}
使用系统;
使用System.Collections.Generic;
使用系统配置;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings;
使用OpenQA.Selenium;
使用TechTalk.SpecFlow;
使用Verivox.Pages;
命名空间Verivox.Steps
{
[有约束力]
类StrompreisvergleichSteps
{
[给出(@“我在Verivox主页上”)]
public void GivenIAmOnVerivoxHomePage()
{
Browser.Current.Navigate().gotour(ConfigurationManager.AppSettings[“seleniumBaseUrl]”);
PropertyCollection.currentPage=新主页();
}
[当(@“我已输入(.*)和(.*))]
输入AND时为公共无效(字符串postalCode、字符串用法)
{
PropertyCollection.currentPage.As().EnterPostalCode(postalCode);
PropertyCollection.currentPage.As().EnterUsage(用法);
}
[当(@“我点击了Jetzt verglei按钮”)]
当点击NjetzTvergleibutton()时公共无效
{
PropertyCollection.currentPage=PropertyCollection.currentPage.As().SubmitStrom();
}
[当(@“我点击eprimo中Strom页面中的Jetzt Wechsen按钮”)]
公共无效时,如在深空区内的按钮()
{
PropertyCollection.currentPage=PropertyCollection.currentPage.As()。单击项目JetzButton();
}
[然后(@“出现eprimo Strom页面”)]
public void Then the PrimitosComplage出现()
{
PropertyCollection.currentPage.As().verifyPageHeader();
}
}
}

错误发生在哪一行?你调试过这个问题吗?嗨,山姆,它在Browser.Current失败了。您可以在步骤定义文件中找到它。我可能在App.config文件中遗漏了什么。您使用的是SpecFlow>=2吗?Baseclass.Contrib.SpecFlow.Selenium.NUnit仅适用于SpecFlow 1.9。
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings;
using OpenQA.Selenium;
using TechTalk.SpecFlow;
using Verivox.Pages;

namespace Verivox.Steps
{
    [Binding]
    class StrompreisvergleichSteps
    {

        [Given(@"I am on Verivox Home Page")]
        public void GivenIAmOnVerivoxHomePage()
        {
            Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
            PropertyCollection.currentPage = new HomePage();

        }

        [When(@"I have entered (.*) and (.*)")]
        public void WhenIHaveEnteredAnd(String postalCode, String Usage)
        {
            PropertyCollection.currentPage.As<HomePage>().EnterPostalCode(postalCode);
            PropertyCollection.currentPage.As<HomePage>().EnterUsage(Usage);
        }

        [When(@"I clicked on Jetzt verglei button")]
        public void WhenIClickedOnJetztVergleiButton()
        {
            PropertyCollection.currentPage = PropertyCollection.currentPage.As<HomePage>().SubmitStrom();
        }

        [When(@"I clik on Jetzt wechsein button in the eprimo in Strom Page")]
        public void WhenIClikOnJetztWechseinButtonInTheEprimoInStromPage()
        {
            PropertyCollection.currentPage = PropertyCollection.currentPage.As<StromPage>().clickItemJetztButton();
        }

        [Then(@"the eprimo Strom page appear")]
        public void ThenTheEprimoStromPageAppear()
        {
            PropertyCollection.currentPage.As<EprimoPage>().verifyPageHeader();

        }

    }
}