Selenium 场景前和场景后挂钩在specflow中不起作用
我的SeleniumSteps.cs代码中有以下代码 我正试图在调试这些测试时启动余震Selenium 场景前和场景后挂钩在specflow中不起作用,selenium,specflow,Selenium,Specflow,我的SeleniumSteps.cs代码中有以下代码 我正试图在调试这些测试时启动余震 using PrivateDomain; using Machine.Specifications; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Drawing.Imagin
using PrivateDomain;
using Machine.Specifications;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using TechTalk.SpecFlow;
namespace Functional.Steps
{
public class SeleniumSteps : PrivateDomain.Steps.SeleniumSteps
{
#region Hooks
[BeforeScenario]
public void Before()
{
// before
}
[AfterTestRun, Scope(Tag = null)]
public new static void AfterTestRun()
{
// after testrun
}
[AfterScenario]
public void AfterScenarioErrorScreenshot()
{
// after scenario
}
#endregion
}
}
using OpenQA.Selenium;
using TechTalk.SpecFlow;
namespace PrivateDomain.Steps
{
[Binding]
[Scope(Tag = "Selenium")]
public class SeleniumSteps
{
protected static IWebDriver webDriver;
public SeleniumSteps();
public virtual IWebDriver WebDriver { get; }
[AfterTestRun]
[Scope(Tag = null)]
public static void AfterTestRun();
[AfterScenarioAttribute(new[] { })]
public virtual void AfterScenario();
}
}
我的功能文件如下所示:
删除详细信息
@Customer_Portal
Feature: Account Management - Registration
In order to create an account
As a customer
I want to register my details with the application
Scenario: Register
# Registration Form
When I navigate to "/Customer/Account/Register"
// more code...
Scenario: Required Fields
// more code...
Scenario: Invalid Contact Details
// more code...
Scenario: Insufficient Password Strength
// more code...
Scenario: Password Mismatch
// more code...
Scenario: Already Registered
// more code...
Scenario: Invalid Activation
// more code...
Scenario: Already Activated
// more code...
当我调试一个测试时,我可以看到调试器正在运行后调试部分。
然而,无论是之前的场景还是之后的场景都没有被执行
有人能告诉我我做错了什么吗?首先,正如Sandesh在回答中指出的,您缺少SeleniumSteps子类的[Binding]属性。仅仅在基类中有[Binding]是不够的,您必须将它应用于钩子方法或步骤定义绑定所在的每个类,因为这就是specflow在幕后搜索钩子和绑定的方式。它类似于范围标识符。若您未将[Binding]属性放置到类中,specflow将不会在该类中搜索潜在的钩子方法或绑定。文件链接:
这个链接也很有用。检查RunOfTheShipe给出的答案:您的SeleniumSteps中缺少[Binding]属性
namespace Functional.Steps
{
[Binding]
public class SeleniumSteps : PrivateDomain.Steps.SeleniumSteps
{
#region Hooks
[BeforeScenario]
public void Before()
{
// before
}
}
}
感谢回复-[Binding]属性存在。我尝试了你提到的步骤,但不幸的是结果相同。你知道为什么Postestrun被成功调用,而其他的没有吗?不,我不知道为什么是这样。您可以编辑您的问题,并提供更多关于定义钩子的类的信息吗?您的类是否在其他任何地方用于继承?能否显示您的.feature文件?以及与功能和场景关联的标记。请用它更新您的问题。好的,有几个解决方案。请尝试下一步:1。您可以从公共类SeleniumSteps或2中删除[ScopeTag=Selenium]。只需为同一类添加另一个Scope属性,如:[ScopeTag=Customer\u Portal]或3。只需在您的功能中添加新的@Selenium标签:帐户管理-注册谢谢各位-建议3对我来说很有效。基类实际上来自一个dll,所以我不能更改它。在我的功能文件中添加标记对我很有效