1

I have the following Selenium test:

[TestMethod]
public void Edit()
{
    Driver.GoToAdministrera();

    Driver.ClickLink(strings.ActorSettings);

    Driver.SendKeysToId(text, "Attributes");

    Driver.Navigate().Refresh();

    Driver.AssertTextInId(string.Empty, "Attributes");

    Driver.SendKeysToId(text, "Attributes");

    Driver.ClickClass("submitbutton");

    Thread.Sleep(3000);

    Driver.Navigate().Refresh();

    Driver.AssertTextInId(text, "Attributes");
}

It is slow and I want to analyze where the bottleneck is. I know I could profile the test, but that will give me some long stack-trace and hotspots. I just want to know how long the execution time is for each row.

I know I can use the StopWatch class. I can even do something like a help method for this:

protected static void Time(Action action)
{
    var sw = new Stopwatch();
    sw.Reset();
    sw.Start();

    action();

    sw.Stop();
    Console.WriteLine(sw.Elapsed + " " + action.Method.Name);
}

But this requires me to modify my test.

Does anyone know of a method to get the timings for each row in a piece of code executed?

magnusarinell
  • 1,127
  • 14
  • 22
  • If you use Visual Studio 2012 or newer for development, why don't you use inbuilt tools for analyzing code and profiling the app? – Alex Mar 03 '16 at 11:40
  • That will give me some long stack-trace and hotspots. I just want to know how long the execution time is for each row. – magnusarinell Mar 03 '16 at 12:08
  • 1
    If you use that profiler, just look for the inclusive percents of each of your routines above. That profiler has a downside - it discards samples during I/O or other blockage, so if that's the reason for slowness, it won't show it. Instrumentation mode might be good enough for you, though it loses line-level information. A method that always works is [*this one*](http://stackoverflow.com/a/378024/23771). – Mike Dunlavey Mar 05 '16 at 14:28

2 Answers2

1
DateTime start = DateTime.Now;
// Do Processing
Driver.GoToAdministrera();
DateTime end = DateTime.Now;
Console.WriteLine("Time taken : " + (end - start));
Kamran Qadir
  • 466
  • 10
  • 20
1

If you use Visual Studio 2015 or later you can run the test under debugger and look for PerfTips values. Stepping from line to line you will get estimated value of elapsed time for each line of the test which is probably what you need.

Andrey Kriachko
  • 689
  • 4
  • 13