This is a migrated thread and some comments may be shown as answers.

Keep WPF application open for the next test

7 Answers 183 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 19 Sep 2012, 09:20 AM
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

7 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 19 Sep 2012, 11:14 AM
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
0
Nathan
Top achievements
Rank 1
answered on 19 Sep 2012, 03:05 PM
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
0
Plamen
Telerik team
answered on 24 Sep 2012, 03:22 PM
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
0
Abc
Top achievements
Rank 1
answered on 29 Aug 2014, 09:16 AM
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();
                }
        }

    }

}



0
Ivaylo
Telerik team
answered on 03 Sep 2014, 06:51 AM
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!
0
Chad
Top achievements
Rank 1
answered on 06 Apr 2016, 06:42 PM

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.

0
Ivaylo
Telerik team
answered on 11 Apr 2016, 08:55 AM
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!
Tags
General Discussions
Asked by
Nathan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Nathan
Top achievements
Rank 1
Abc
Top achievements
Rank 1
Ivaylo
Telerik team
Chad
Top achievements
Rank 1
Share this question
or