locked
Adding UI Forms to Coded UI Testing RRS feed

  • Question

  • Hi,

            Can anyone pls help me to use windows UI form in codedUI ( the user has to check the test methods listed in that Form)

     

    thanks & regards,

    viswa


    viswa........
    Friday, January 13, 2012 7:06 AM

Answers

  • You should be creating another project in the solution of type 'Windows Forms Application', set as start up project with UI form of the kind you want. In this project, add reference to the dll created by your test project(this holds all the test methods and control definitions etc). You can use System.Reflection to list the test methods and allow end-user to execute them.

    Note that, the end user must have required installations to execute the test binaries.

    Also, for executing the test methods from outside of a test project, you need to manipulate Playback.Initialize() and Playback.Cleanup() methods explicitly.

    • Marked as answer by viswanathan.s Monday, January 23, 2012 9:42 AM
    Friday, January 20, 2012 7:06 AM

All replies

  • viswanathan,

    You can start by recording the actions using Coded UI Test Builder. Create a Test Project and add a CodedUITest into it. Choose Record options and record the actions.

    http://msdn.microsoft.com/en-us/library/dd286681.aspx

    -Tejas.

    • Proposed as answer by Ruiz Yi Monday, January 16, 2012 1:42 AM
    • Unproposed as answer by viswanathan.s Thursday, January 19, 2012 5:57 AM
    Friday, January 13, 2012 7:15 AM
  • hi Tejas,

               It seems u r not clear with my question.

    I have the many methods

    For Ex, i) Student_Creation

                ii) Student Mark updation ,,, etc..

    I wnt to run all such methods in an order. Such order of methods has to be listed for the Tester who can select the test methods that needs to be executed.

    hope u understand.. So i need to start up my test with an ui page listing some test methods. Pls help me

     

    thanks & regards

    viswa

     

     


    viswa........
    Wednesday, January 18, 2012 1:28 PM
  • You could create an Ordered Test?

    Test - New Test - Ordered Test

    Wednesday, January 18, 2012 3:43 PM
  • That means you want to provide UI in windows form through which end user should be able to select single/ multiple tests and execute them using a button. Correct me if I am wrong.

    Thursday, January 19, 2012 3:47 AM
  • Hi TejasJ

    Ya U are very correct.. i have idea to execute the selected tests but no idea to bring up UI in windows form.. There is a possiblity to add windows form but no idea to make it as start up form(as we use in windows application)

     

     

    thanks & regards,

    viswa


    viswa........

    Thursday, January 19, 2012 5:49 AM
  • hi Fletch

     

    the code snippet will not be given to the user and the user don know to create order test & don know to use VST  .. so the solution has to be executed as a patch file..

    thanks & regards,

    viswa.


    viswa........

    Thursday, January 19, 2012 5:52 AM
  • Hi viswa,

    Sorry that I am not clear your requirement.

    1. TejasJ said that you will privide this UI for End Users (you have confirmed it).

        1.1 Why not Testers but End Users choose the Test Methods?

        1.2 Will the End Users install VS2010?

     

        I think most of the End Users do not have VS2010 installed. If you want to run script in the environment without VS2010, it is better to use Windows UI Automation http://msdn.microsoft.com/en-us/library/ms753388.aspx

     

    2. If you want Testers to choose the options, you can add a Windows Form UI to the test project, and from the UI, Testers can choose the test methods.


    Ruiz Yi
    MSDN Community Support | Feedback to us
    Friday, January 20, 2012 3:05 AM
  • Hi Ruiz Yi,

            As u said

    "If you want Testers to choose the options, you can add a Windows Form UI to the test project, and from the UI, Testers can choose the test methods".


    I want to do the same but don know how to start the application running with that windows form(i.e windows form as start up form) no such option. so pls help me to do these
    thanks & Regards, viswa
    Friday, January 20, 2012 6:59 AM
  • You should be creating another project in the solution of type 'Windows Forms Application', set as start up project with UI form of the kind you want. In this project, add reference to the dll created by your test project(this holds all the test methods and control definitions etc). You can use System.Reflection to list the test methods and allow end-user to execute them.

    Note that, the end user must have required installations to execute the test binaries.

    Also, for executing the test methods from outside of a test project, you need to manipulate Playback.Initialize() and Playback.Cleanup() methods explicitly.

    • Marked as answer by viswanathan.s Monday, January 23, 2012 9:42 AM
    Friday, January 20, 2012 7:06 AM
  • Hi viswa,

    You need 2 projects to do this.

    1. You Windows Form Application.

        This is the application for the End Users. With it, End Users can Create a Student or Update Marks.

     

    2. The Test Project.

        2.1 Create a Coded UI Test

              You may record following method using the Coded UI Test Builder:

              LaunchApp();

              OpenCreateStudentForm();

              OpenUpdateMarksForm();

             CloseApp();

       2.2 Add a Windows Forms to this Test Project 

             This form may contains some checkbox

       2.3 Update the test method

           

            [TestMethod]   
            public CodedUITest1()
            {
                using (var options = new Form())
                {
                    options.ShowDialog();
                    
                     this.UIMap.LaunchApp();
                     
                     if(options.chkCreateStudent.Checked)
                     {
                             this.UIMap.CreateStudent();
                      }
                     if(options.chkCreateStudent.Checked)
                     {
                             this.UIMap.UpdateMark();
                      }
    
                      this.UIMap.CloseApp();
                }
            }
    


    Ruiz Yi
    MSDN Community Support | Feedback to us
    Friday, January 20, 2012 8:40 AM
  • Hi TejasJ,

           Can u explain briefly how to use "System.Reflection to list the test methods and allow end-user to execute them". Or is there is any examples that wil make me clear?


    thanks & Regards, viswa
    Monday, January 23, 2012 9:41 AM
  • Viswa,

    check this thread: http://social.msdn.microsoft.com/Forums/en-US/vsautotest/thread/6ee9647c-00b0-4815-b4c0-3c89889534e7.

    The attribute to search for would be "TestMethod" as each test in TestClass is attributed with "TestMethod"

    -Tejas.

    • Proposed as answer by TejasJ Wednesday, January 25, 2012 8:42 AM
    Monday, January 23, 2012 9:58 AM
  • Hi Ruiz Yi,

             I have 2 projects i) Windows form application  ii) Test Project

    am calling the methods of the test project in windows button click(i.e. in windows Project). I did this by adding the reference of 2nd(Test)project to the 1st project. But while getting executed am getting error as

    Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

    can any one pls help me to get out of this??!!...................


    thanks & Regards, viswa
    Wednesday, January 25, 2012 8:16 AM
  • hi TejasJ ,

             How to manipulate Playback.Initialize() and Playback.Cleanup() methods explicitly.?

    can u help me out on this..


    thanks & Regards, viswa
    Wednesday, January 25, 2012 8:21 AM
  • Viswa,

    If you are using a test project, you don't need to handle this. playback.Initialize() and Playback.Cleanup() are automatically called in the before and after test methods are/have executed.

    But if you are using another project type like class library/Console App/ Winform app, you will have to call these methods. Call Playback.Initialize() before executing first TestMethod. Call Playback.Cleanup() after all methods are finished:

    try
    {
       // Initialize playaback
       Playback.Initialize();
    
       // Call test methods to be executed
       Test.Test1(); 
    }
    finally
    {
       // Cleanup
       Playback.Cleanup();
    }
    

    If you face any issues, then you might need to also handle assembly resolving manually.

    -Tejas.

    • Proposed as answer by TejasJ Wednesday, January 25, 2012 8:48 AM
    Wednesday, January 25, 2012 8:48 AM
  • Hi tejasJ

    ya still am having problem..

    how to  handle assembly resolving manually..? could you help me out?


    thanks & Regards, viswa
    Wednesday, January 25, 2012 10:01 AM
  • Check this:

    http://blogs.kungfucoder.com/blog/post/2011/10/11/Coded-UI-Testing-Could-not-load-Visual-Studio-Test-Assembly.aspx

    -Tejas.


    Mark all the replies as Answer that helped you! Also Vote As Helpful if it really did :)


    • Proposed as answer by TejasJ Wednesday, January 25, 2012 10:10 AM
    • Edited by TejasJ Wednesday, January 25, 2012 10:18 AM
    Wednesday, January 25, 2012 10:10 AM