我正在尝试使用Specflow和Firefox使Selenium 2.4.0接受Javascript生成的"Confirm-Dialog".我在下面的步骤中找不到我应该做的事情.(尝试从各种Java实现中找到在.NET中执行此操作的等效方法,但它无法正常工作)
When I click "Delete" on the App
And I confirm the warning
Run Code Online (Sandbox Code Playgroud)
步骤定义......
[When(@"I confirm the warning")]
public void WhenIConfirmTheWarning()
{
// WebDriver.Something?
}
Run Code Online (Sandbox Code Playgroud) 在specflow自己的安装目录指南,它说,只有这样,它是使用.msi安装和大多数我的主题阅读教程告诉我下载并安装该安装文件,但是当我搜索的NuGet包经理,我发现还有一个可用的specflow包.
asp.net acceptance-testing visual-studio-2010 specflow nuget
我使用VS 2010 Pro在Windows Server 2008(而不是R2)上进行开发.我今天在我的机器上将SpecFlow更新到版本1.8.1,并Regenerate Feature Files通过右键单击包含一些SpecFlow特征文件的项目来选择在Visual Studio中.
对于最后一个版本1.7.1,在完成后我在生成的文件头中得到以下内容:
// SpecFlow Version:1.7.1.0
// SpecFlow Generator Version:1.7.0.0
// Runtime Version:4.0.30319.468
Run Code Online (Sandbox Code Playgroud)
现在,在安装1.8.1之后,我得到了这个:
// SpecFlow Version:1.8.1.0
// SpecFlow Generator Version:1.8.0.0
// Runtime Version:4.0.30319.239
Run Code Online (Sandbox Code Playgroud)
请注意将内部版本号更改468为239?我想知道(.NET)运行时版本的变化来自哪里.检查一些dll C:\Windows\Microsoft.NET\Framework64\v4.0.30319显示它们带有版本号4.0.30319.239- 所以如何"更新"(返回)到4.0.30319.468?
任何帮助/暗示赞赏.
我正在使用Watin编写specflow测试,用于使用T4MVC的Asp.Net MVC应用程序.
我发现自己在测试中使用了"魔术字符串"网址,这是我不喜欢的.
[Given(@"I am on the sign up page")]
public void GivenIAmOnTheSignUpPage()
{
string rootUrl = ConfigurationManager.AppSettings["RootUrl"];
string fullUrl = string.Format("{0}/Authentication/Signup",rootUrl);
WebBrowser.Current.GoTo(fullUrl);
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢使用我的T4MVC动作结果,就像我在MVC应用程序中那样,这样的......
[Given(@"I am on the sign up page")]
public void GivenIAmOnTheSignUpPage()
{
WebBrowser.Current.GoTo(MVC.Authentication.SignUp().ToAbsoluteUrl());
}
Run Code Online (Sandbox Code Playgroud)
我的ToAbsoluteUrl扩展方法
public static class RouteHelper
{
private static UrlHelper _urlHelper;
private static string _rootUrl;
public static string ToAbsoluteUrl(this ActionResult result)
{
EnsureUrlHelperInitialized();
var relativeUrl = _urlHelper.Action(result);
return string.Format("{0}/{1}", _rootUrl, relativeUrl);
}
private static void EnsureUrlHelperInitialized()
{
if (_urlHelper==null)
{
_rootUrl …Run Code Online (Sandbox Code Playgroud) 我正在使用SpecFlow和Nunit,我正在尝试使用TestFixtureSetUpAttribute设置我的环境测试,但它从未被调用过.
我已经尝试过使用MSTests和ClassInitialize属性,但同样的事情发生了.该函数未被调用.
任何想法为什么?
[Binding]
public class UsersCRUDSteps
{
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void TestInitialize()
{
// THIS FUNCTION IS NEVER CALLER
ObjectFactory.Initialize(x =>
{
x.For<IDateTimeService>().Use<DateTimeService>();
});
throw new Exception("BBB");
}
private string username, password;
[Given(@"I have entered username ""(.*)"" and password ""(.*)""")]
public void GivenIHaveEnteredUsernameAndPassword(string username, string password)
{
this.username = username;
this.password = password;
}
[When(@"I press register")]
public void WhenIPressRegister()
{
}
[Then(@"the result should be default account created")]
public void ThenTheResultShouldBeDefaultAccountCreated()
{
}
Run Code Online (Sandbox Code Playgroud)
解:
[Binding]
public class UsersCRUDSteps …Run Code Online (Sandbox Code Playgroud) 有没有办法用"显式"属性标记Specflow测试?我知道可以通过使用特殊标签@ignore来标记"忽略"属性.
我正在编写一个自定义插件来自定义SpecFlow生成的自动生成的代码文件.
构建解决方案并将其放入SpecFlow测试项目的"lib"文件夹之后.在保存我得到的SpecFlow功能文件时
Specflow plugin : Generation error: Missing [assembly:GeneratorPlugin] attribute in 'path to dll'
Run Code Online (Sandbox Code Playgroud)
即使我在插件程序集中标记了这一点
[assembly: GeneratorPluginAttribute(typeof(CustomGeneratorPlugin))]
Run Code Online (Sandbox Code Playgroud)
使用反射/自我测试我可以自己加载程序集并解析属性
代码在这里 - https://github.com/chrismckelt/SpecFlowCustomPlugin
有什么想法导致这个?谢谢
我想在每个SpecFlow测试的开头添加相同的行.
此行指定了一些随时间变化的场景列表,因此不可能为每个测试维护此列表.
例如:
Given I have set my site theme to <MyTheme>
|Theme Names|
|Theme 1 |
|Theme 2 |
|Theme 3 |
|Theme 4 |
|Theme 5 |
Run Code Online (Sandbox Code Playgroud)
我想对每个主题重复这个测试.主题列表不是一成不变的,应该保存在一个地方.
到目前为止,我已成功设法创建了一个Generator Plugin,我计划在生成测试类之前立即使用此插件来更改SpecFlow功能.但是,我无法在此上下文中看到编辑方案的方法.
是否可以从实现中获取和设置场景文本IUnitTestGeneratorProvider?
我没有开始使用这种方法,所以如果有人能提出更好的方法来做到这一点,那么我也会接受.
如果我得到一些错误的术语,我会道歉 - 我刚刚开始使用SpecFlow.
我正在添加这一部分,以澄清我实际上在追求什么.
假设我有一个包含800个测试的测试套件.我们有业务要求在每个可用主题上运行800个测试中的每一个.可用主题列表可以随时更改,并且将此列表保留在多个位置是不可行的.
所以,例如,如果我有以下两个测试:
例A:
Given I set context to < site >
Given I go to base url
When I type <username> in username field
When I type <password> in password field
When I click login button
Examples: …Run Code Online (Sandbox Code Playgroud) 什么是重用SpecFlow Given/When/Then步骤的最佳方法?我找到了三种具有所有特定优点和缺点的方法,但我不相信这是最好的方法.
我在一个解决方案
ProjectA中有两个项目:
[Binding]
public class BookSteps : StepsBase
{
[Given(@"the following books:")]
public void GivenTheFollowingBooks(Table table)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
ProjectB:
[Binding]
public class BookStepsReference : ProjectA.BookSteps { }
Run Code Online (Sandbox Code Playgroud)
这工作并且需要最少的工作.不幸的是,它打破了功能文件的智能感知:ProjectB功能文件中的步骤保持紫色.
ProjectB:
[Binding]
public class BookStepsReference : ProjectA.BookSteps
{
[Given(@"the following books:")]
public void GivenTheFollowingBooksReference(Table table)
{
base.GivenTheFollowingBooks(table);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行测试时,这会中断,因为自动生成的功能步骤会看到两个带有Given属性的方法"以下书籍:"并抛出一个模糊的引用异常.
ProjectB:
[Binding]
public class BookStepsReference
{
private ProjectA.BookSteps _bookSteps = new ProjectA.BookSteps();
[Given(@"the following books:")]
public void GivenTheFollowingBooks(Table table)
{
_bookSteps.GivenTheFollowingBooks(table);
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,并且还在Feature …
我在使用Spec-flow已经有好几天了.我正面临"找到多个匹配.导航到第一个匹配",而调试这个可以解决,但是当我运行整个解决方案时由于绑定中的歧义而失败.我在Single项目中运行了4个C类清单文件
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>(Multiple bindings for this line)
Given I get <outputDirectory>
Given I set saving Mode <ConversionMode>
Given I convert pdf using Conversion
Given I convert to Image <convertToFile>
Then I compare Images <getActualImagePath> and <getExpectedImagePath> and <pageCount>
Run Code Online (Sandbox Code Playgroud)
和步骤定义:
**Binding for Multiple steps is the below binding:**
Run Code Online (Sandbox Code Playgroud)
第一次绑定:
[Given(@"I get Inputs Folder and list of Files (.*) then (.*)")]
public void GivenIGetInputsFolderAndListOfFilesThen(string …Run Code Online (Sandbox Code Playgroud)