Calculate time between steps in a recording

Ranorex Studio, Spy, Recorder, and Driver.
cdmartinus
Posts: 8
Joined: Wed Jul 03, 2013 11:21 am

Calculate time between steps in a recording

Post by cdmartinus » Tue Jan 28, 2014 12:43 pm

Hi all,

I am currently running some tests on a website and need to get the system to calculate the time taken between certain test steps and add them to an accumulating text file.

At the moment, I'm just waiting for the test to complete and then manually working out the differences using the report. Is there anyway I could do this using C#? I can already output data to a text file, it's just a matter of getting the figures I need first.

Thanks

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: Calculate time between steps in a recording

Post by Swisside » Tue Jan 28, 2014 2:51 pm

Hello !

I suggest you have a look at the thread : http://www.ranorex.com/forum/getting-th ... t4613.html


If you want to implement this in a recording module do as follow :
1)Add two module variables let's say starttime and endtime

2) Add a UserCode module where you want to start measuring let's call the method "getStartTime"

3) Add a UserCode module where you want to end measuring and call the methode "getEndTime"

4) Then go to the usercode (Right click => ViewCode )

5) Paste the following code for each method
public void getStartTime()
        	
        {   
        	Report.Log(ReportLevel.Info,"Start");
            System.DateTime start = System.DateTime.Now;              
            starttime = start.ToString();
           
        }

        public void getEndTime()
        {
        	System.DateTime end = System.DateTime.Now;  
        	
        	System.DateTime start = Convert.ToDateTime(starttime);
        	
        	TimeSpan duration = end - start;
        	string s = duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString();
        	Report.Log(ReportLevel.Info,duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString());
        	
        	System.IO.File.AppendAllText(@"C:\Users\x\Documents\test.txt","TestCase:"+TestCase.Current.Name+" | ModuleName: "+ TestReport.CurrentTestModuleActivity.TestModuleName+": Duration: "+s+ Environment.NewLine);
This code will write the testcase name, module name and the duration between the steps to a text file. You can of course adapt it to your needs.

If you need additional help do not hesitate :D

Regards

Swiss'
A simple thank you always does wonders !

cdmartinus
Posts: 8
Joined: Wed Jul 03, 2013 11:21 am

Re: Calculate time between steps in a recording

Post by cdmartinus » Wed Jan 29, 2014 11:30 am

I tried your solution and it worked perfectly. I've now got all the time taken values outputting neatly to a text file, which means a lot less work for me when I have to run it 6 times a day!

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: Calculate time between steps in a recording

Post by Swisside » Wed Jan 29, 2014 11:34 am

Glad I could help you :D


Take care
A simple thank you always does wonders !

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Wed Oct 28, 2015 10:50 am

Hi Swisside

Am testing a patient registration application. where i want to measure the time taken to open the patient panel after login in into system. can you please provide the infoemation for that

My Code:

Code: Select all

            var repo = TestRIS_iRepository.Instance;
            var username = repo.LogIn.Username;
            username.Click();
            username.PressKeys("tau1");
            
            var password = repo.LogIn.Password;
            password.Click();
            password.PressKeys("tau1");
            
            var logIn = repo.LogIn.LogIn;
            logIn.Click();
//want to check the how much time taken, after clicking the login button utill the patient panel opens
            var patient = repo.CentricityRISI50.Patient;
            patient.Click();
            var registration = repo.CentricityRISI50.Registration;
            registration.Click();

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calculate time between steps in a recording

Post by odklizec » Wed Oct 28, 2015 11:13 am

Hi,

All you need to achieve your goal seems to be nicely described in Swisside's post. You just have to combine the code from his post with your code. I would suggest to add WaitForExists method to make the code wait for the appearance of panel you want test. After this method, you should measure the end time. Here is the code snippet...

Code: Select all

            var logIn = repo.LogIn.LogIn;
            logIn.Click();
//--- added code --- start
            System.DateTime start = System.DateTime.Now; //start time               
            starttime = start.ToString(); 
            repo.CentricityRISI50.PatientInfo.WaitForExists(30000); //waits for existence of repo.CentricityRISI50.Patient
            System.DateTime end = System.DateTime.Now;  //end time   
            System.DateTime start = Convert.ToDateTime(starttime);  
            TimeSpan duration = end - start;  
            string s = duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString();  
            Report.Log(ReportLevel.Info,duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString());  
//--- added code --- end
            var patient = repo.CentricityRISI50.Patient;
            patient.Click();
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Wed Oct 28, 2015 2:19 pm

To get the report in a log file i tried like this but its not working for me. what is wrong in my code.

My Code:

Code: Select all

System.DateTime start = System.DateTime.Now; //start time
            Host.Local.RunApplication("C:\\medora\\bin\\CentricityRISi.exe", "", "C:\\medora\\bin", false);
            var repo = timeRepository.Instance;
            var nameField = repo.LogIn.NameField;
            nameField.Click();
            System.DateTime end = System.DateTime.Now;
TimeSpan duration = end - start;
            string s = duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString();
            Report.Log(ReportLevel.Info,duration.Minutes.ToString()+":"+duration.Seconds.ToString()+"."+duration.Milliseconds.ToString());
            System.IO.File.AppendAllText(@"C:\\measure\\test.txt","Test Case: "+TestCase.Current.Name+"Duration: "+s+Environment.NewLine);
Am getting the error message as:

at time.UserCodeModule1.Ranorex.Core.Testing.ITestModule.Run() in c:\Users\212453330\Documents\Ranorex\RanorexStudio Projects\time\time\UserCodeModule1.cs:line 71 at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext

line 71 is last line in the code

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calculate time between steps in a recording

Post by odklizec » Wed Oct 28, 2015 2:35 pm

I believe there is missing an important part of the error message? Could you please post the entire error message?

BTW, have you started entire Test Suite or just the code module?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Wed Oct 28, 2015 2:53 pm

Please find the attachmet of erropr report log file

I have started only the code module.
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calculate time between steps in a recording

Post by odklizec » Wed Oct 28, 2015 3:01 pm

ejji09 wrote:I have started only the code module.
This is what I've expected. The reason of the failure is this code...
TestCase.Current.Name
This code will work only if code/recording module is started from Test Case, which means you need to start the entire test suite.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Wed Oct 28, 2015 3:14 pm

yeah you are right! :)

when I run the entire test case then its working fine. Is there a way where i can run only the module and get the report in .txt file by changing something at TestCase.Current.Name, I tried a bit i was unable to get the name of the module in the .txt file.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calculate time between steps in a recording

Post by odklizec » Wed Oct 28, 2015 3:42 pm

The name of actual module could be obtained by this code:
Ranorex.Core.Reporting.TestReport.CurrentTestModuleActivity.TestModuleName
But I'm not sure if it would work if the module is started outside the test suite?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Calculate time between steps in a recording

Post by krstcs » Wed Oct 28, 2015 3:49 pm

You can also get the recording module's class name (which is the same as the module name) by using this:

Code: Select all

string moduleName = this.GetType().Name;

edit: Should have been GetType, not GetClass...
Shortcuts usually aren't...

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Fri Oct 30, 2015 5:10 pm

Hi.

How to save the file name with time stamp?

Code: Select all

System.IO.File.AppendAllText(@"C:\\izaz\\test.txt"+"DateTime: "+dt+Environment.NewLine+"TestCase: "+TestCase.Current.Name+Environment.NewLine+"Duration: "+s+Environment.NewLine);
Thanks.

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: Calculate time between steps in a recording

Post by ejji09 » Mon Nov 02, 2015 11:54 am

:idea:
Solved:

Code: Select all

String filename = System.DateTime.Now.ToString("ddMMyyyyhhmmss");

System.IO.File.AppendAllText(@"C:\\save\\"+filename+.txt"+"DateTime: ",dt+Environment.NewLine+"TestCase: "+TestCase.Current.Name+Environment.NewLine+"Duration: "+s+Environment.NewLine);
or

Code: Select all

System.IO.File.AppendAllText(@"C:\\save\\"+System.DateTime.Now.ToString("ddMMyyyyhhmmss")+".txt", Envireonment.NewLine + "Duration: " + s + Environment.NewLine);
:D :D :D :D