开发者

How can I add a datasource to a UIMap method instead of a Test Method (VS 2010 Coded UI Test)

I have a 2010 Coded UI Test that performs some actions against a website. I am a开发者_高级运维ble to add a datasource to a "Test Method" which loops the entire method once per record.

But, what I really want to do is loop only a portion of the test which is just a single recorded method in the UIMap.

Let's say the test method looks something like this:

//[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestCommunities.xml", "Community", DataAccessMethod.Sequential), DeploymentItem("Tests\\WebTests\\DataSources\\TestCommunities.xml"), TestMethod]        
public void LoginCreateCommunities()
    {
        this.UIMap.LoginAdmin();
        //this.UIMap.CreateCommunityParams.UIItem0EditText = TestContext.DataRow["CommunityName"].ToString();
        this.UIMap.CreateCommunity();
        this.UIMap.LogoffClose();
    }

It's only UIMap.CreateCommunity() that I want to loop the datasource. I do not want all 3 methods to execute per record in the datasource, which is what happens when I attach the datasource to the test method (the portion commented out above).

Is there a way to achieve what I'm trying to do here?

Thanks.


You have to use the ClassInitialize and ClassCleanup methods. You place it in the #region Additional test attributes area at the bottom. So for you it'd look something like:

    #region Additional test attributes

    [ClassInitialize]
    static public void ClassInit(TestContext context)
    {
        Playback.Initialize();
        try
        {
            sharedTest.LoginAdmin();
        }
        finally
        {
            Playback.Cleanup();
        }

    }


    [ClassCleanup]
    static public void ClassCleanup()
    {
        Playback.Initialize();
        try
        {
            sharedTest.LogoffClose();
        }
        finally
        {
            Playback.Cleanup();
        }
    }

    #endregion


first you have to define a new UIMap in your codedUI class

[CodedUITest]
public class CodedUITest1
{
    static private UIMap sharedTest = new UIMap();

    ....

    [ClassInitialize()]
    static public void ClassInit(TestContext context)
    {
        Playback.Initialize();
        try
        {
            sharedTest.RecordedStartApp();
        }
        finally
        {
            Playback.Cleanup();
        } 
    }

    [ClassCleanup()]
    static public void ClassCleanup()
    {
        Playback.Initialize();
        try
        {
            sharedTest.RecordedCloseApp();
        }
        finally
        {
            Playback.Cleanup();
        } 
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜