locked
Multiple Coded UI Test Methods in one .CS? RRS feed

  • Question

  • So far, I've created a singular .cs file for every test and then grouped them into ordered tests to test 1 piece of functionality as a whole. I know I can stop recording and generate code for each step and have it in one .cs file. Once I've done that though, is there anyway to use those individual recordings in another test?

     

     

    public class OpenIE
    {

     

     

    public OpenIE()
    {}

    [

     

    TestMethod]
    public void OpenBrowser()
    {
    this.UIMap.OpenIE8();
    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
    }

     

     

    For Example...
    I have the test above working perfectly, if I wanted to add the existing recording named this.UIMap.NavtoRiverURL(); in the class NavToRiver how would access the other test method and run them together out of 1 .cs file?

     

    Monday, May 24, 2010 4:45 PM

All replies

  • You are using ordered test, so you just need to add this method in place you want.

    Actually, I don't understand your question. Pls make it clear.

    Tuesday, May 25, 2010 3:06 AM
  • Let me try again....

    I have 1 recording in all of my .cs files. I have over 30 files.  Each of the .cs files is using a different Test Method and Class. How can I access Test Method's and Classes from other .cs files without creating a massive ordered lists? I'm a beginner when it comes to C#.net

    Tuesday, May 25, 2010 9:04 PM
  • <form id="aspnetForm" action="edit" enctype="application/x-www-form-urlencoded" method="post">
    <input id="__EVENTTARGET" name="__EVENTTARGET" type="hidden" /> <input id="__EVENTARGUMENT" name="__EVENTARGUMENT" type="hidden" /> <input id="__VIEWSTATE" name="__VIEWSTATE" type="hidden" value="/wEPDwULLTEzNzk0MzkwMDlkZEMpty7R2lukRYyoGDAFiw9m2frw" />
    <script type="text/javascript"></script> <script type="text/javascript"></script> </form>
    <form action="/Forums/en-IE/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit" enctype="application/x-www-form-urlencoded" method="post">

    Edit Message

    <textarea cols="100" rows="20" name="body">&lt;form id=&quot;aspnetForm&quot; action=&quot;edit&quot; enctype=&quot;application/x-www-form-urlencoded&quot; method=&quot;post&quot;&gt; <div>&lt;input id=&quot;__EVENTTARGET&quot; name=&quot;__EVENTTARGET&quot; type=&quot;hidden&quot; /&gt; &lt;input id=&quot;__EVENTARGUMENT&quot; name=&quot;__EVENTARGUMENT&quot; type=&quot;hidden&quot; /&gt; &lt;input id=&quot;__VIEWSTATE&quot; name=&quot;__VIEWSTATE&quot; type=&quot;hidden&quot; value=&quot;/wEPDwULLTEzNzk0MzkwMDlkZEMpty7R2lukRYyoGDAFiw9m2frw&quot; /&gt;</div> &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;/form&gt; <div id="x_BodyBackground"> <div id="x_JelloSizer"> <div id="x_JelloExpander"> <div id="x_JelloWrapper"> <div><a href="http://msdn.microsoft.com/en-us/ms348103.aspx"> <div id="x_BrandLogo"><span id="x_BrandDisplayText">Microsoft Developer Network</span></div> </a> <div> <div id="x_SearchBox">&lt;input id=&quot;SearchTextBox&quot; class=&quot;TextBoxSearch TextBoxSearchIE7&quot; name=&quot;SearchTextBox&quot; type=&quot;text&quot; /&gt;<span>&nbsp;</span>&lt;input id=&quot;SearchButton&quot; class=&quot;SearchButton&quot; name=&quot;SearchButton&quot; src=&quot;http://i1.social.microsoft.com/globalresources/Images/trans.gif&quot; type=&quot;image&quot; /&gt;</div> </div> <div> <div><a id="x_idPPScarab" href="http://login.live.com/logout.srf?ct=1274832812&rver=6.0.5276.0&lc=1033&id=254354&ru=http:%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fen-IE%2Fvsautotest%2Fthread%2F289f2f12-82ec-41d3-831b-7a4ca155eaca%2F05c98259-849b-4d76-a555-f37026713257%2Fedit"><span id="x_idSOT">Sign out</span></a></div> <div id="x_LocaleFlyout"> <div id="x_LocaleSelector"> <div id="x_TargetPanel"><a>United States (English)</a><img src="http://i2.social.microsoft.com/globalresources/Images/trans.gif" alt=""></div> <div id="x_PopupPanel"><a href="/Forums/en-AU/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Australia (English)</a><a href="/Forums/pt-BR/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Brasil (Portugu&ecirc;s)</a><a href="/Forums/cs-CZ/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Česk&aacute;&nbsp;republika (Če&scaron;tina)</a><a href="/Forums/da-DK/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Danmark (Dansk)</a><a href="/Forums/de-DE/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Deutschland (Deutsch)</a><a href="/Forums/es-ES/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Espa&ntilde;a (Espa&ntilde;ol)</a><a href="/Forums/fr-FR/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">France (Fran&ccedil;ais)</a><a href="/Forums/id-ID/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Indonesia (Bahasa)</a><a href="/Forums/it-IT/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Italia (Italiano)</a><a href="/Forums/ro-RO/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Rom&acirc;nia (Rom&acirc;nă)</a><a href="/Forums/ru-RU/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">Россия (Русский)</a><a href="/Forums/ko-KR/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">대한민국 (한국어)</a><a href="/Forums/zh-CN/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">中华人民共和国 (中文)</a><a href="/Forums/zh-TW/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">台灣 (中文)</a><a href="/Forums/ja-JP/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">日本 (日本語)</a><a href="/Forums/zh-HK/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit?persist=True">香港特別行政區 (中文)</a></div> </div> </div> <div id="x_UserName"><a id="x_ctl00_ctl00_ctl01_UserNameLink" title="Starting0ver" href="http://social.msdn.microsoft.com/Profile/en-US/?user=Starting0ver&referrer=http%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fen-IE%2fvsautotest%2fthread%2f289f2f12-82ec-41d3-831b-7a4ca155eaca%2f05c98259-849b-4d76-a555-f37026713257%2fedit&rh=Wl6TNiv1KT6NbuFljlY%2fUDsCWdaOiS23MMUPiAnKCX8%3d">Starting0ver</a></div> </div> <div id="x_NetworkTagLineArea"><a id="x_NetworkLink" href="http://Msdn.microsoft.com/en-US"><img id="x_NetworkTaglineLogo" src="http://i1.social.microsoft.com/Forums/GlobalResources/Images/Msdn/networklogo_Msdn.png" alt=""> </a></div> <div>&nbsp;</div> <div><a href="http://msdn.microsoft.com/en-us/ms348103.aspx">Home</a><a href="http://msdn.microsoft.com/en-us/library/default.aspx">Library</a><a href="http://msdn.microsoft.com/en-us/bb188199.aspx">Learn</a><a href="http://msdn.microsoft.com/en-us/aa570309.aspx">Downloads</a><a href="http://msdn.microsoft.com/en-us/aa570318.aspx">Support</a><a href="http://msdn.microsoft.com/en-us/aa497440.aspx">Community</a><a href="http://social.msdn.microsoft.com/Forums/en-US/categories">Forums</a></div> </div> <div> <div> <div> <div id="x_MainContent"> <div id="x_contentWrapper"> <div id="x_content"> <div><a href="http://msdn.microsoft.com/en-us/ms348103.aspx">Microsoft Developer Network</a><span> &gt; </span><a title="Forums Home" href="/Forums/en-IE/categories">Forums Home</a> <span> &gt;</span> <a title="Visual Studio Team System Forums" href="/Forums/en-IE/category/vsts"> Visual Studio Team System Forums</a> <span>&gt;</span> <a title="Visual Studio UI Automation Testing (includes CodedUI)" href="/Forums/en-IE/vsautotest/threads"> Visual Studio UI Automation Testing (includes CodedUI)</a> <span>&gt;</span> <a title="Multiple Coded UI Test Methods in one .CS?" href="/Forums/en-IE/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca"> Multiple Coded UI Test Methods in one .CS?</a> <span>&gt;</span> <span>05c98259-849b-4d76-a555-f37026713257</span></div> &lt;form action=&quot;/Forums/en-IE/vsautotest/thread/289f2f12-82ec-41d3-831b-7a4ca155eaca/05c98259-849b-4d76-a555-f37026713257/edit&quot; enctype=&quot;application/x-www-form-urlencoded&quot; method=&quot;post&quot;&gt; <div> <h4>Edit Message</h4> <div>&lt;textarea cols=&quot;100&quot; rows=&quot;20&quot; name=&quot;body&quot;&gt;&lt;p&gt;If I'm interpreting this correctly, you mean you have 1 recording in EACH .cs file?&lt;/p&gt; &lt;p&gt;It isn't necessary to create a separate CodedUITest.cs file for each recording. You can put them all in under &lt;span style=&quot;text-decoration:underline&quot;&gt;one&lt;/span&gt; class (&amp;quot;group&amp;quot; them if you will) in &lt;strong&gt;one &lt;/strong&gt;.cs file. Of course, this is dependent on the size of your application under test, but right now I have a fairly large test set (54 tests so far) running from one file and it works fine.&lt;/p&gt; &lt;p&gt;The [TestMethod] designator will display each test method separately when viewed in the Test View tab.&lt;/p&gt; &lt;p&gt;Depending on what you're testing, and how you want to structure your test files, you can still create ordered tests using the test methods from a single .cs file. However, if you have multiple UIMap.uitest files as well, that's another issue.&lt;/p&gt; &lt;p&gt;EX:&lt;/p&gt; &lt;pre lang=&quot;x-c#&quot;&gt;namespace AutomatedTests { [CodedUITest] public class MyTests { public MyTests() { } [TestMethod] public void Test1() { } [TestMethod] public void Test2() { } [TestMethod] public void Test3() { } &lt;/pre&gt; &lt;p&gt;And so on. Then you can create your ordered test by pulling in the test methods in the order you want them to run.&lt;/p&gt; &lt;p&gt;I'm no expert, and as I mentioned it depends on how you're structuring your test project, but hopefully this answers your question. &amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/textarea&gt; <br/> &lt;label for=&quot;hasCode&quot;&gt;Resource.HasCodeLabel&lt;/label&gt;&lt;input checked=&quot;checked&quot; name=&quot;hasCode&quot; type=&quot;checkbox&quot; value=&quot;true&quot; /&gt; &lt;label for=&quot;reason&quot;&gt;Reason&lt;/label&gt;&lt;input name=&quot;reason&quot; type=&quot;text&quot; /&gt;</div> <div>&lt;input title=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;</div> </div> &lt;/form&gt;</div> </div> <div id="x_rail"><a rel="Help" href="/Forums/en-US/help">Need Help with Forums? (FAQ)</a></div> </div> </div> </div> </div> <div id="x_Footer"> <div><a href="http://www.microsoft.com "> <div title="Microsoft Corporation">&nbsp;</div> </a></div> <div> <div id="x_FooterCopyright">&copy; 2010 Microsoft Corporation. All rights reserved.</div> <a href="http://msdn.microsoft.com/cc300389.aspx">Terms of Use</a><span>|</span><a href="http://www.microsoft.com/library/toolbar/3.0/trademarks/en-us.mspx">Trademarks</a><span>|</span><a href="http://www.microsoft.com/info/privacy.mspx">Privacy Statement</a><span>|</span><a href="http://go.microsoft.com/?linkid=8103551">Contact Us</a><span>|</span><a href="http://go.microsoft.com/?linkid=8786242&amp;lcid=1033">Manage Your Profile</a></div> </div> </div> </div> </div> </div> &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;noscript&gt;&lt;/noscript&gt; &lt;noscript&gt;&lt;/noscript&gt;</textarea>
    <label for="hasCode">Resource.HasCodeLabel</label><input name="hasCode" type="checkbox" value="true" /> <label for="reason">Reason</label><input name="reason" type="text" />
    <input title="Submit" type="submit" value="Submit" />
    </form>
    <script type="text/javascript"></script> <script type="text/javascript"></script> <script type="text/javascript"></script> <noscript></noscript> <noscript></noscript>
    • Proposed as answer by Starting0ver Wednesday, May 26, 2010 12:15 AM
    • Edited by Starting0ver Wednesday, July 7, 2010 12:38 AM trying to delete mess
    Wednesday, May 26, 2010 12:11 AM
  • Wow, Microsoft's editor for this forum just blew my post away. Jeez. Will attempt to repost it in some semblance of normal. See above, horrible mess.

    Wednesday, May 26, 2010 12:18 AM
  • If I'm interpreting this correctly, you mean you have 1 recording in EACH .cs file? It isn't necessary to create a separate CodedUITest.cs file for each recording. You can put them all in under ONE class (group them if you will) in ONE.cs file. Of course, this is dependent on the size of your application under test, but right now I have a fairly large test set (54 tests so far) running from one file and it works fine. The [TestMethod] designator will display each test method separately when viewed in the Test View tab.

    Depending on what you're testing, and how you want to structure your test files, you can still create ordered tests using the test methods from a single .cs file. However, if you have multiple UIMap.uitest files as well, that's another issue.

    namespace AutomatedTests 
     { 
      [CodedUITest] 
      public class MyTests
      { 
       public MyTests()
       {
       } 
        [TestMethod]
        public void Test1()
          {
          } 
        [TestMethod]
        public void Test2()
         { 
          } 
        [TestMethod]
        public void Test3()
         {
          } 
     
    And so on. Then you can create your ordered test by pulling in the test methods in the order you want them to run. I'm no expert, and as I mentioned it depends on how you're structuring your test project, but hopefully this answers your question.
    • Proposed as answer by Starting0ver Wednesday, May 26, 2010 12:30 AM
    Wednesday, May 26, 2010 12:30 AM
  • Hi,

     I have done in the same manner and created multiple test cases in 1 cs file.  I have used the code

    using (BrowserWindow win = BrowserWindow.Launch())
                {
                    var url = "http://www.google.com/";

                    win.NavigateToUrl(new Uri(url)); }

    in the first method to open the required URL in the browser.But i itried to run the application ,it only runs the first method and stops saying the test is pass.

    How to run all the methods

    Note:I have followed the exact steps

    Friday, August 3, 2012 5:40 PM
  • Hi TesterVicky,

    So I guess I had the same problem with the test editor as StartingOver. Here's what I was trying to say:

    Adding to what StartingOver suggested, you should call your recorded methods in the order you want them to be executed within your test methods like so:

    namespace AutomatedTests

    {

    [CodedUITest]

    public class MyTests

    {

    [TestMethod]
    public void Test1()

    {
    this.UIMap.OpenIE();
    this.UIMap.Step2();
    this.UIMap.Step3();
    ...so on
    }

    [TestMethod]
    public void Test2()
    {
    this.UIMap.Step1();
    this.UIMap.Step2();
    ...
    }
    }
    }

    Hope this helps,

    Nat



    Monday, August 6, 2012 5:05 PM