Calculate time between steps in a recording
-
- Posts: 8
- Joined: Wed Jul 03, 2013 11:21 am
Calculate time between steps in a recording
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
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
Re: Calculate time between steps in a recording
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
If you need additional help do not hesitate
Regards
Swiss'
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
Regards
Swiss'
A simple thank you always does wonders !
-
- Posts: 8
- Joined: Wed Jul 03, 2013 11:21 am
Re: Calculate time between steps in a recording
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!
Re: Calculate time between steps in a recording
Glad I could help you
Take care
Take care
A simple thank you always does wonders !
Re: Calculate time between steps in a recording
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:
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();
Re: Calculate time between steps in a recording
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...
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 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
Re: Calculate time between steps in a recording
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:
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
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);
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
Re: Calculate time between steps in a recording
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?
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 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
Re: Calculate time between steps in a recording
Please find the attachmet of erropr report log file
I have started only the code module.
I have started only the code module.
You do not have the required permissions to view the files attached to this post.
Re: Calculate time between steps in a recording
This is what I've expected. The reason of the failure is this code...ejji09 wrote:I have started only the code module.
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 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
Re: Calculate time between steps in a recording
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.
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.
Re: Calculate time between steps in a recording
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?
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 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
Re: Calculate time between steps in a recording
You can also get the recording module's class name (which is the same as the module name) by using this:
edit: Should have been GetType, not GetClass...
Code: Select all
string moduleName = this.GetType().Name;
edit: Should have been GetType, not GetClass...
Shortcuts usually aren't...
Re: Calculate time between steps in a recording
Hi.
How to save the file name with time stamp?
Thanks.
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);
Re: Calculate time between steps in a recording
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);
Code: Select all
System.IO.File.AppendAllText(@"C:\\save\\"+System.DateTime.Now.ToString("ddMMyyyyhhmmss")+".txt", Envireonment.NewLine + "Duration: " + s + Environment.NewLine);