【问题标题】:Selenium Webdriver error: An item with the same key has already been addedSelenium Webdriver 错误:已添加具有相同密钥的项目
【发布时间】:2017-11-18 01:32:56
【问题描述】:

有人可以建议我如何防止此错误:“已添加具有相同密钥的项目。”?

我有两个单独运行时运行良好的测试,但是当我在 Visual Studio 中“全部运行”时,我得到了那个错误。

[Binding]
public sealed class Steps
{
    private Squish squish = new Squish();
    private Tools tools = new Tools();

    [Given(@"I navigated to the Squish homepage")]
    public void GivenINavigatedToTheSquishHomepage()
    {
        squish.NavigateToURL("Squish.com");
        ScenarioContext.Current["siteTitle"] = squish.GetPageTitle();
    }

是否有任何替代 FeatureContext.Current.Add(key, value)?所以我不必直接存储任何东西?

【问题讨论】:

    标签: c# selenium selenium-webdriver webdriver


    【解决方案1】:

    我想你应该阅读有关并行测试运行的 specflow 文档http://specflow.org/documentation/Parallel-Execution/ 据说:

    您可能没有使用静态上下文属性 ScenarioContext.Current、FeatureContext.Current 或 ScenarioStepContext.Current。

    实际上你的错误是自我描述的——你已经在字典中用键“siteTitle”创建了项目

    【讨论】:

    • 知道了! FeatureContext.Current.Add(key, value) 有什么替代品吗?所以我不必直接存储任何东西?
    • 您可以使用实例变量并使用它 - 用于您的类 - [Binding] public seal class Steps { private Squish squish = new Squish();私人工具工具=新工具();私有字符串 pageTitle; [Given(@"我导航到 Squish 主页")] public void GivenINavigatedToTheSquishHomepage() { squish.NavigateToURL("Squish.com"); pageTitle = squish.GetPageTitle(); }
    猜你喜欢
    • 2017-01-02
    • 2017-08-02
    • 2011-01-27
    • 2018-10-03
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    相关资源
    最近更新 更多