Keep WPF application open for the next test

8 posts, 0 answers
  1. Nathan
    Nathan avatar
    5 posts
    Member since:
    Aug 2012

    Posted 19 Sep 2012 Link to this post

    Hi,

    I am new to TestStudio and doing the evaluation for one of our WPF application.

    I have the following issue in Test Studio.

    Opening the application in Test 1, and keep that application open for Test 2 as well when run these tests from Test List sequentially. I don't know how to write the script for this. I am happy to hear if this functionality available in Test Studio

    Regards,
    Nathan
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 19 Sep 2012 Link to this post

    Hello Nathan,

    This ability is not currently available, however it is an existing feature request. You can vote for the PITS Issue here.

    In the meantime you can insert each test into a master test via the Test as Step feature.

    Regards,
    Plamen
    the Telerik team
    Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
    Vote now
  3. Nathan
    Nathan avatar
    5 posts
    Member since:
    Aug 2012

    Posted 19 Sep 2012 Link to this post

    Hi Plamen,

    Thanks for the information, Your work around helped me. Could you please tell me how to launch the application by using coding rather than launching the application from the Configure window. How to stop closing the application in end of the Test run?

    Regards
    Nathan
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 24 Sep 2012 Link to this post

    Hello Nathan,

    The problem here is that Test Studio internally calls the LaunchNewApplication() and ActiveApplication.Quit() methods automatically. If you really want to start the application with code instead of using the Configure window, you can use one of the following methods.
    1. Create a Unit test or convert your existing test to a Unit test using the "Convert All Steps To Code" feature. The disadvantages of this are that a unit test cannot be converted back to a Test Studio test and you have to do all the work using code.
    2. Create a mock application to feed to Test Studio. Then insert a coded step as the first step of the test. Use the following code which closes the mock application and launches the desired application.
    //Close the mock application
    ActiveApplication.Quit();
     
    //Launch an application of your choice
    Manager.LaunchNewApplication(@"C:\Release\PhotoDemo.exe");
     
    //Refresh Visual Tree
    Manager.ActiveApplication.MainWindow.RefreshVisualTrees();

    To stop the application from closing:
    1. Select the last step from a Test Studio test and set the Pause Test Step Property to After. This will pause the test after that step leaving the app opened. 
    2. If you are using a Unit test, simply don't use the ActiveApplication.Close() method at the end of the test.

     

    Just out of curiosity, why do you need this? How does it help your test automation?


    All the best,

    Plamen
    the Telerik team
    Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
    Vote now
  5. Abc
    Abc avatar
    5 posts
    Member since:
    Aug 2014

    Posted 29 Aug 2014 in reply to Plamen Link to this post

    Hi Plamen,

    I have a question related to active application open and close. The scenario is that I am creating two coded steps in a single WPF test file.
    In first coded step, I opened the application through manager.activeapplication , then a scenario in it and then close the app through  wpfApp.MainWindow.Window.Close();  
    Now in my next coded step , I again want to open this application for some different scenario but neither manager.activeapplication nor manager.launchnewapplication is working.

    Please suggest how to achieve that. Below is the code: 


    public class WpfTest1 : BaseWebAiiTest
        {
            #region [ Dynamic Applications Reference ]

            private Applications _applications;

            /// <summary>
            /// Gets the Applications object that has references
            /// to all the elements, windows or regions
            /// in this project.
            /// </summary>
            public Applications Applications
            {
                get
                {
                    if (_applications == null)
                    {
                        _applications = new Applications(Manager.Current);
                    }
                    return _applications;
                }
            }

            #endregion

            [CodedStep(@"Open a Station in a casino for a new game day")]
            public void WpfTest1_CodedStep()
            {

                WpfApplication wpfApp = Manager.ActiveApplication;
                Assert.IsTrue(wpfApp.GetWindow("Warnung") != null);

                Button Ok = (wpfApp.GetWindow("Warnung").Find.ByName<Button>("OK"));

                Ok.User.Click();
                Thread.Sleep(1000);

                Assert.IsTrue(wpfApp.MainWindow.Window.Caption != null);

                var row = wpfApp.MainWindow.Find.ByName<DataGrid>("Stations");
                var rows = row.RowElements;
                
                var availableRow = rows.FirstOrDefault(stationRow => stationRow.TextBlockContent.Contains("Offnen"));

                if (rows.Count > 0 && availableRow != null)
                {
                    availableRow.User.Click();
                    Thread.Sleep(1000);

                    wpfApp.MainWindow.Find.ByName<Button>("OpenStation").User.Click();
                }
                else
                {
                    wpfApp.MainWindow.Window.Close();

                    
                 
                }
                   
            }

            
            [CodedStep(@"Open an already opened station(samehostname) in a Casino")]
            public void WpfTest1_CodedStep1()
            {
                WpfApplication wpfApp = Manager.LaunchNewApplication(@"E:\Builds\Build_27August2014\Bin");
                  Assert.IsTrue(wpfApp.GetWindow("Warnung") != null);

                    Button Ok = (wpfApp.GetWindow("Warnung").Find.ByName<Button>("OK"));

                    Ok.User.Click();
                 Thread.Sleep(1000);

                    Assert.IsTrue(wpfApp.MainWindow.Window.Caption != null);

                    var row = wpfApp.MainWindow.Find.ByName<DataGrid>("Stations");
                    var rows = row.RowElements;

                    var availableRow = rows.FirstOrDefault(stationRow => stationRow.TextBlockContent.Contains(Environment.MachineName));
                    if (rows.Count > 0 && availableRow != null)
                    {
                       availableRow.User.Click();
                        Thread.Sleep(1000);

                        wpfApp.MainWindow.Find.ByName<Button>("OpenStation").User.Click();
                    }
                    else
                    {
                        wpfApp.MainWindow.Window.Close();
                    }
            }

        }

    }



  6. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 03 Sep 2014 Link to this post

    Hello,

    You are updating quite old post and the information in it may not be relevant. However using the latest Test Studio I have replicated your scenario but I am not able to reproduce the problem you are experiencing. Here is a short video demonstration (no audio) how this is working on my end.

    Please try updating to the latest version and give it a try.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  7. Chad
    Chad avatar
    2 posts
    Member since:
    Apr 2016

    Posted 06 Apr in reply to Ivaylo Link to this post

    Hello,

     

    I know this is old... but is it possible to run a test then a second test without application closing now?  If the feature exists... I have not come across it.

  8. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 11 Apr Link to this post

    Hello Chad,

    Unfortunately there is no such functionality to keep an WPF application open.

    Thank you for your understanding.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top