SpecFlow with VS2010 CodedUI tests

1,334 views
Skip to first unread message

Thierry Cattel

unread,
Jan 22, 2011, 7:15:33 AM1/22/11
to SpecFlow
Hi all,

I wanted to use SF with coded UI tests.
The only adaptation required is in the generated code for features,
replace

//
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
[Microsoft.VisualStudio.TestTools.UITesting.CodedUITest()]

If not we get an error related to the browser technology (supposedly
not IE) which is not supported...

I tested with non UI tests and it keeps working.
Could not figure out whether it is possible to tune the code generator
by some configuration/template ?

Would it be thinkable to adapt Specflow in a coming release to support
VS coded UI tests ?

Thanks in adv,
Regards,

Thierry

radv...@gmail.com

unread,
Jan 23, 2011, 2:25:19 AM1/23/11
to SpecFlow
I posted a question about this on
http://stackoverflow.com/questions/4697287/specflow-and-visual-studio-2010-coded-ui-test-integration

Thierry, would you or anybody else write a blog post or add another
comment on how would this work at design and run time logically.
I have yet to dig into CodedUI tests.

I don't see a problem of creating a different attribute from code
generation methods inside Specflow.
I would like to understand how all of this can fit together.I doubt it
is only an attribute change.
I think a new value for testing framework in app.config/web.config
needs to be created to allow code generation inside Specflow to
generate
specific code for CodedUI tests.

Let me explain my screnario. I have a bunch of HTML Mock Ups pages
(html, js, css, images) hyper-linked together that are created by a
web developer/designer
(so I need to comply to this Design-Centric approch) and now I need to
add nteractivity and show sample data
by adding code behind (MVC 3 with Razor view engine, EF4 (possibly
Code First Approach), POCO,
SQL Server) using Specflow. Since I already have front end GUI done I
would like to provide fake data to the controllers using fake
repositories
so I will have the correct behaviour from the GUI stand of point. I
would prefer to first work on creating presentation model (ViewModel)
and later add Data Layer as POCO
classes. The reason for trying to use Data-Driven Coded UI Test is to
automate creation of Tests from Test cases/scenarios that I already
have defined.
I need to mentioned that I have use case descriptions and I believe
that Test cases correspond to user stories.

Can somebody use real world Test cases like these to try to explain
how to incorporate CodedUI Tests logically and then we will see how to
do it programmatically inside Specflow.

Test case/Scenario #
Steps
Data Expected Results
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Register a Shopper 1 Launch the test
storefront http://mystore.com/index
Welcome page is loaded.
with invalid password 2 Click Sign In
link
Sign In page is loaded.
3 Click Register
under New
Customer Register
page is loaded.
. 4 Enter relevant
information with Logon ID = Shopper18
Registration failure with the following Tooltip
invalid
password Password =
shop message:

Verify Password = shop Password must be at least 6
characters long

Verify Password = Shopper1101 and contain at least one number and
at least one letter.

Street Address = 82 N Avenue
...
======================================================================================================================================
Register a Shopper with 1 Launch the test
storefront http://mystore.com/index
Welcome page is loaded.
mismatched passwords 2 Click Sign In
link
Sign In page is loaded.
3 Click Register
under New Customer Register page is loaded.
. 4 Enter relevant
information and Logon ID = Shopper19
Registration failure with the following Tooltip
click
Submit Password =
Shopper1101 message:

Verify Password = Shopper11011 Password must be at least 6
characters long

Street Address = 82 N Avenue and contain at least one number and
at least one letter.
...
======================================================================================================================================


Thanks,
Rad

Alister Scott

unread,
Feb 14, 2011, 5:42:35 PM2/14/11
to SpecFlow
I think it's as simple as allowing what attributes can be added to the
generated class.

I have added a feature request for this at: https://github.com/techtalk/SpecFlow/issues#issue/39

Thanks,
Alister Scott
Brisbane, Australia

On Jan 23, 5:25 pm, "radvi...@gmail.com" <radvi...@gmail.com> wrote:
> I posted a question about this onhttp://stackoverflow.com/questions/4697287/specflow-and-visual-studio...
>
> Thierry, would you or anybody else  write a blog post or add another
> comment on how would this work at design and run time logically.
> I have yet to dig into CodedUI tests.
>
> I don't see a problem of creating a different attribute from code
> generation methods inside Specflow.
> I would like to understand how all of this can fit together.I doubt it
> is only an attribute change.
> I think a new value for testing framework in app.config/web.config
> needs to be created to allow code generation inside Specflow to
> generate
> specific code for CodedUI tests.
>
> Let me explain my screnario. I have a bunch of HTML Mock Ups pages
> (html, js, css, images) hyper-linked together that are created by a
> web developer/designer
> (so I need to comply to this Design-Centric approch) and now I need to
> add nteractivity and show sample data
> by adding code behind (MVC 3 with Razor view engine, EF4 (possibly
> Code First Approach), POCO,
> SQL Server) using Specflow. Since I already have front end GUI done I
> would like to provide fake data to the controllers using fake
> repositories
> so I will have the correct behaviour from the GUI stand of point. I
> would prefer to first work on creating presentation model (ViewModel)
> and later add Data Layer as POCO
> classes. The reason for trying to use Data-DrivenCodedUITest is to
> > I tested with nonUItests and it keeps working.
> > Could not figure out whether it is possible to tune the code generator
> > by some configuration/template ?
>
> > Would it be thinkable to adapt Specflow in a coming release to support
> > VScodedUItests ?

Alister Scott

unread,
Feb 14, 2011, 7:15:36 PM2/14/11
to SpecFlow
Maybe it's not that simple.
One issue I see is that if you're using the [BeforeTestRun],
[BeforeScenario] etc. attributes, then coded UI tests still don't
work.

Any ideas?


namespace TT.EX.AutomatedAcceptanceTestsCodedUI
{
using System;
using Microsoft.VisualStudio.TestTools.UITesting;
using TechTalk.SpecFlow;

[Binding]
public class ManageBrowserSteps : StepDefinitionsBase
{
private static readonly Uri GoogleUrl = new Uri("http://
google.com");

[BeforeTestRun]
public static void StartBrowser()
{
Driver = BrowserWindow.Launch();
}

[BeforeScenario]
public static void GoToStartPage()
{
Driver.NavigateToUrl(GoogleUrl);
}


[AfterTestRun]
public static void TerminateWebDriver()
{
Driver.Close();

Thomy Kay

unread,
Feb 21, 2011, 1:41:42 PM2/21/11
to SpecFlow
Use Playback.Initialize() and Playback.Close() to put the CUIT runner
into context.

Thomy Kay

unread,
Feb 21, 2011, 1:43:59 PM2/21/11
to SpecFlow
Using a custom GeneratorProvider will do the job:

public class MsTest2010CodedUIGeneratorProvider :
MsTest2010GeneratorProvider
{
public override void
SetTestFixture(System.CodeDom.CodeTypeDeclaration typeDeclaration,
string title, string description)
{
base.SetTestFixture(typeDeclaration, title, description);
foreach (CodeAttributeDeclaration customAttrbute in
typeDeclaration.CustomAttributes)
{
if (customAttrbute.Name ==
"Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute")
{

typeDeclaration.CustomAttributes.Remove(customAttrbute);
break;
}
}

typeDeclaration.CustomAttributes.Add(new
CodeAttributeDeclaration(new
CodeTypeReference("Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute")));
}
}

The assembly goes to the SpecFlow path. Needs configuration in the
app.config then:

<specFlow>
<unitTestProvider name="MsTest.2010"
generatorProvider="My.SpecFlow.MsTest2010CodedUIGeneratorProvider,
My.SpecFlow"
runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTest2010RuntimeProvider,
TechTalk.SpecFlow"/>
</specFlow>

Alister Scott

unread,
Feb 23, 2011, 9:08:01 PM2/23/11
to SpecFlow
Thanks very much Thomy, I got this working as I visioned.
I have written about how to do this on the SpecFlow wiki:
https://github.com/techtalk/SpecFlow/wiki/Using-SpecFlow-with-CodedUI-API

Cheers,
Alister Scott
http://watirmelon.com/

On Feb 22, 4:43 am, Thomy Kay <thomy...@gmail.com> wrote:
> Using a custom GeneratorProvider will do the job:
>
>     public class MsTest2010CodedUIGeneratorProvider :
> MsTest2010GeneratorProvider
>     {
>         public override void
> SetTestFixture(System.CodeDom.CodeTypeDeclaration typeDeclaration,
> string title, string description)
>         {
>             base.SetTestFixture(typeDeclaration, title, description);
>             foreach (CodeAttributeDeclaration customAttrbute in
> typeDeclaration.CustomAttributes)
>             {
>                 if (customAttrbute.Name ==
> "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute")
>                 {
>
> typeDeclaration.CustomAttributes.Remove(customAttrbute);
>                     break;
>                 }
>             }
>
>             typeDeclaration.CustomAttributes.Add(new
> CodeAttributeDeclaration(new
> CodeTypeReference("Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute")));
>         }
>     }
>
> The assembly goes to theSpecFlowpath. Needs configuration in the
> > > SQL Server) usingSpecflow. Since I already have front end GUI done I
> > > would like to provide fake data to the controllers using fake
> > > repositories
> > > so I will have the correct behaviour from the GUI stand of point. I
> > > would prefer to first work on creating presentation model (ViewModel)
> > > and later add Data Layer as POCO
> > > classes. The reason for trying to use Data-DrivenCodedUITest is to
> > > automate creation ofTestsfrom Test cases/scenarios that I already
> > > have defined.
> > > I need to mentioned that I have use case descriptions and I believe
> > > that Test cases correspond to user stories.
>
> > > Can somebody use real world Test cases like these to try to explain
> > > how to incorporateCodedUITestslogically and then we will see how to
> > > > Would it be thinkable to adaptSpecflowin a coming release to support

patric...@guidance.eu.com

unread,
Nov 25, 2014, 6:46:56 AM11/25/14
to spec...@googlegroups.com
Hi Thomy, I am new to specflow and immediately need to use it for Code UI Testing, so I havce to learn this stuff quickly. Now one question
    Your custom generator provider replaces the UnitTesting.TestClassAttribute with 'codedUI testAttribute'; so far so good; but what of the other unitTesting bindings that spec flow automatically generates:
            UnitTesting.ClassInitializeAttribute()
            UnitTesting.ClassCleanupAttribute()
            UnitTesting.TestInitializeAttribute()
            UnitTesting.TestCleanupAttribute()
            and so on.

Is it necessary to replace any of these  too ?

Patrick Pope
Reply all
Reply to author
Forward
0 new messages