locked
Coded UI Test - Can we create a New "UI Map" in the same project? RRS feed

  • Question

  • Hi guys ,

    I have a question regarding Coded UI tests,

    I create a new project for my test automation and recorded some Coded UI tests,   there is only one UIMap.ui test which included UIMap.cs file and UIMap.Designer.cs file.

    There are some tests that I missed as part of Smoke Tests and if I create a Coded UI Test for the new scenario.   The auto generated source code that was created for old scenarios are retaining but whatever the customized code that we added was deleting

    Now I want to Created new folder called "UP MAPS - Smoke Test Phase II" and created "Smoke Test Phase II Coded UI Test Map" 

    While  I am creating a new Coded UI Test under the "UP MAPS - Smoke Test Phase II"  folder ,  The "UIMAP" & "UI Map Designer files" that I created previously was checked out .    How can we create a new UI Designer map for my Phase II Scenarios?   Do  I need to create new Project altogether now ?  

    I know how to create multiple UP Maps for each scenario but I need to know if I have to create a new project as I have already had one UIMap.Designer.cs file that I don't want to override

    Please advise me at the earliest

    http://www.intertech.com/Blog/post/Coded-UI-Testing-with-Multiple-UI-Maps-%28Detailed%29.aspx

     

    Friday, December 16, 2011 6:40 PM

Answers

  • SriniTestAutomation,

     

    I have already created some coded UI Tests and the all the classes and methods are generated in the UIMAP.Designer.cs file

    This is the default behavior for actions recorded with the test recorder.

     

    When I create a new coded UI test , the UIMAP.DESIGNER.CS file is over riding and I don’t want to disturb this designer file bcoz some of my coded UI tests are running fine for some scenarios .

    Take your custom edits, and put them in UIMap.cs.  It is a partial class and will have access to all objects in the UIMap.Designer.cs file.  DO NOT MAKE MANUAL EDITS TO UIMAP.DESIGNER.CS.  Please read my previous response more carefully, as it seems you do not understand this fully.

     

    Then I created a UI Map folder and wanted to create new coded UI Map & coded UI tests for each scenario. When I created a new coded UI test, the UIMap.designer.cs file is checked out as soon as the record builder started

     It sounds like you are making edits to the orginal UIMap.uitest and not the new UIMap.  Right-click NewUIMap.uitest and click edit with test recorder.  To use the methods recorded in NewUIMap, you must refererence the new map in your test then instantiate an instance of that UIMap.  This does not occur automatically when using a manually added UIMap.  When you create a new CodedUI test, it will create the UIMap (UIMap.cs and UIMap.Designer.cs) and create the test (TestName.cs) which will contain a reference and instance of the UIMap it created.

    Here is an example:

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    //This is added Manually
    using TestProject.UIMaps.NewUIMap;
    
    namespace CodedUITest
    {
    
        [CodedUITest]
        public class CodedUITestClass
        {
            //Instantiate UIMaps here so we can use it in a TestMethod
            NewUIMap NewUIMap = new NewUIMap();
    
         }
    
            [TestMethod]
            public void Test1()
            {
                NewUIMap.NewTestMethod();
            }
    
    }
    

     

    Can’t I create a new Coded UI map in the same solution file? Do I need to create a new project altogether?

     As I stated previously, Right-Click your test project -> Add -> New Item -> Then select 'Coded UI Test Map'

     

    Cheers,

    Paul

    Please respect the time that is taken to respond to your questions by showing appreciation with the 'Vote as helpful'  or 'Mark as Answered'  buttons. 

     



    Monday, December 19, 2011 2:59 PM
  •  

    Hi Paul ,

    I am planning to create a UP Map for each scenario which I felt easier compare to moving the stuff from designer.cs file in coded ui test

    As part of that , I created a UI Map for Login scenario . and it created LoginUIMap.ui test , LoginUIMap.cs & LoginUIMap.designer.cs fiels

    "When I run the Test , it displayed "No Tests were run because no tests are loaded or these selected tests are disabled”

    Do I need to run the Coded UI Test and record the above scenario?   Can't we run the CODED UI Map file independently?

     

    Monday, December 19, 2011 5:02 PM
  • Sorry Srini, I misspoke.

    I would create a UI Map per page or complex control and I would create a coded UI test class per requirement (where a requirement has a handfull of scenarios)  I would NOT create a seperate class for every single scenario.  Alternatively you can group like requirements in the same class for example all login, logout, change password, and reset password tests might fit well in a class. 

     

    Consider using test categories and priorities to mark your various tests for inclusion in a smoke test, full regression test...

    http://www.edsquared.com/2009/09/25/Test+Categories+And+Running+A+Subset+Of+Tests+In+Team+Foundation+Server+2010.aspx


    Tim
    Monday, December 19, 2011 9:07 PM

All replies

  • SriniTestAutomation,
      The auto generated source code that was created for old scenarios are retaining but whatever the customized code that we added was deleting

     

    Your custom code is being deleted because you are editing the UIMap.Designer.cs file instead of the UIMap.cs partial class.  And the auto-generated code is retaining because you are editing the UIMap.Designer.cs file instead of the UIMap.uitest file.

    See below for an overview of the parts of a Coded UI test, with areas relevant to your issue underlined.

    When creating a Coded UI Test, 4 files are created.

    1. CodedUITest.cs - based on the name of the test created. This is the test class used to execute methods in your UIMap.cs and UIMap.Designer.cs classes

    2. UIMap.Designer.cs - This file contains a UIMap class with the attribute Generated Code. This code is regenerated upon modifications to UIMap.uitest which can be triggered by recording new controls or adding assertions. It is not intended to be modified by hand. This is meant to be done in UIMap.cs because UIMap.Designer.cs is a partial class which pairs with UIMap.cs. This means that all objects and methods in UIMap.Designer.cs can be referenced in UIMap.cs.  To change the code which is generated in this file, you must change the UIMap.uitest file, preferably with the Coded UI Test Editor ini Visual Studio Feature Pack 2.

    3. UIMap.cs - contains a partial UIMap which pairs with UIMap.Designer.cs by default, that does not initially contain any methods or properties. You can include custom code here which references objects and methods in UIMap.Designer.cs.  This code will persist on subsequent recordings or edits to UIMap.uitest.

    4. UIMap.uitest - contains an xml based structue which defines the control heirarchy, actions, properties, and recorded methods. This xml is used to create the generated code contained in UIMap.Designer.cs. Any changes to this file will trigger a new generation of UIMap.Designer.cs. Also, any changes here will automatically persist on subsequent recording or addition of controls. If you wish to make adjustments to an improperly recorded control (I.e. improperly found control heirarchy), it is suggested to repair the UIMap.uitest file by hand in an xml editor.

     

    I know how to create multiple UP Maps for each scenario but I need to know if I have to create a new project as I have already had one UIMap.Designer.cs file that I don't want to override

    Right-Click your test project -> Add -> New Item -> Then select 'Coded UI Test Map'

      

    Also See:

    Testing a Large Application with Multiple UI Maps

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

    &

    Walkthrough: Using multiple Coded UI maps in test automation

    http://blogs.msdn.com/b/anutthara/archive/2010/02/10/walkthrough-using-multiple-coded-ui-maps-in-test-automation.aspx

     

    Cheers,

    Paul



    Friday, December 16, 2011 8:15 PM
  • I have already created some coded UI Tests and the all the classes and methods are generated in the UIMAP.Designer.cs file

    When I create a new coded UI test , the UIMAP.DESIGNER.CS file is over riding and I don’t want to disturb this designer file  bcoz some of my coded UI  tests are running fine  for some scenarios .

    Then I created a UI Map folder and wanted to create new coded UI Map & coded UI tests for each scenario. When I created a new coded UI test, the UIMap.designer.cs file is checked out as soon as the record builder started

    Can’t I create a new Coded UI map in the same solution file? Do I need to create a new project altogether?


    Friday, December 16, 2011 9:49 PM
  • It is recommended that before making changes to the recorder generated code in *.Designer.cs file, you move that code into *.cs file which contains definition of same partial class. The changes made to *.cs file are retained on adding/editing recording. 

    You can add new uitest file using steps: Right-Click your test project -> Add -> New Item -> Then select 'Coded UI Test Map', and record new steps in it.


    -Tejas.
    Saturday, December 17, 2011 6:19 AM
  • SriniTestAutomation,

     

    I have already created some coded UI Tests and the all the classes and methods are generated in the UIMAP.Designer.cs file

    This is the default behavior for actions recorded with the test recorder.

     

    When I create a new coded UI test , the UIMAP.DESIGNER.CS file is over riding and I don’t want to disturb this designer file bcoz some of my coded UI tests are running fine for some scenarios .

    Take your custom edits, and put them in UIMap.cs.  It is a partial class and will have access to all objects in the UIMap.Designer.cs file.  DO NOT MAKE MANUAL EDITS TO UIMAP.DESIGNER.CS.  Please read my previous response more carefully, as it seems you do not understand this fully.

     

    Then I created a UI Map folder and wanted to create new coded UI Map & coded UI tests for each scenario. When I created a new coded UI test, the UIMap.designer.cs file is checked out as soon as the record builder started

     It sounds like you are making edits to the orginal UIMap.uitest and not the new UIMap.  Right-click NewUIMap.uitest and click edit with test recorder.  To use the methods recorded in NewUIMap, you must refererence the new map in your test then instantiate an instance of that UIMap.  This does not occur automatically when using a manually added UIMap.  When you create a new CodedUI test, it will create the UIMap (UIMap.cs and UIMap.Designer.cs) and create the test (TestName.cs) which will contain a reference and instance of the UIMap it created.

    Here is an example:

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    //This is added Manually
    using TestProject.UIMaps.NewUIMap;
    
    namespace CodedUITest
    {
    
        [CodedUITest]
        public class CodedUITestClass
        {
            //Instantiate UIMaps here so we can use it in a TestMethod
            NewUIMap NewUIMap = new NewUIMap();
    
         }
    
            [TestMethod]
            public void Test1()
            {
                NewUIMap.NewTestMethod();
            }
    
    }
    

     

    Can’t I create a new Coded UI map in the same solution file? Do I need to create a new project altogether?

     As I stated previously, Right-Click your test project -> Add -> New Item -> Then select 'Coded UI Test Map'

     

    Cheers,

    Paul

    Please respect the time that is taken to respond to your questions by showing appreciation with the 'Vote as helpful'  or 'Mark as Answered'  buttons. 

     



    Monday, December 19, 2011 2:59 PM
  •  

    Hi Paul ,

    I am planning to create a UP Map for each scenario which I felt easier compare to moving the stuff from designer.cs file in coded ui test

    As part of that , I created a UI Map for Login scenario . and it created LoginUIMap.ui test , LoginUIMap.cs & LoginUIMap.designer.cs fiels

    "When I run the Test , it displayed "No Tests were run because no tests are loaded or these selected tests are disabled”

    Do I need to run the Coded UI Test and record the above scenario?   Can't we run the CODED UI Map file independently?

     

    Monday, December 19, 2011 5:02 PM
  • Hi Srini, are you customizing code is in the xxx.cs file not the xxx.designer.cs?  Things in the xxx.cs file should never be overwritten or replaced by the Coded UI Test builder but things in the xxx.designer.cs file may be overwritten and therefore should not be hand edited.  Are you using feature pack 2 with the UI map editor to move the code you are customizing into the xxx.cs file?  That feature pack makes moving the code trivial: http://www.intertech.com/Blog/post/Modifying-Generated-Code-in-a-Coded-UI-Test.aspx

    In answer to your last question you cannot run the xx.uitest classes, as they are not decorated with the CodedUITest and TestMethod attributes (see first screen grab here: http://www.intertech.com/Blog/post/Coded-UIAssembling-the-test.aspx)

    I would design my test so that the UI Maps correspond to pages or controls, and the test classes correspond to scenarios

     


    Tim
    Monday, December 19, 2011 6:16 PM
  • Tim -

    Having Coded UI Test map for each scenario will be difficult for me as I have to create Custom class and need to assemble them together.

     I am planning to create SOME SMOKE TESTS scenarios in which I am planning to create coded UI Tests for each of my scenario 

    then I wanted to add wait time in the UIMap.uitest file  wherever appropriate and then in the UIMap.cs file I wanted add some custom logic . I also wanted to add some assertions in the UIMap.designer.cs file to validate some data for example , in Login Script , I want to add assertion for 'Logged in User Name'

    I have added so far below code in the uimap.cs file

    public partial class UIMap

    {

    public UIMap()

    {

    this.UIBreezeSuiteWebReviewWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);

    //this.UIConfirmApplicationReWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);

    }

    }

    For full regression testing , I might use the Coded UI Test map  frame work .

     

    Monday, December 19, 2011 7:47 PM
  • Sorry Srini, I misspoke.

    I would create a UI Map per page or complex control and I would create a coded UI test class per requirement (where a requirement has a handfull of scenarios)  I would NOT create a seperate class for every single scenario.  Alternatively you can group like requirements in the same class for example all login, logout, change password, and reset password tests might fit well in a class. 

     

    Consider using test categories and priorities to mark your various tests for inclusion in a smoke test, full regression test...

    http://www.edsquared.com/2009/09/25/Test+Categories+And+Running+A+Subset+Of+Tests+In+Team+Foundation+Server+2010.aspx


    Tim
    Monday, December 19, 2011 9:07 PM