0

I'm building up a Fluentautomation script with a pathway to step through my application with testing. Is it possible to record timings between actions, rather than just getting the overall timing at the end? i.e.

    var TestChrome = Require<F14N>()
        .Init<FluentAutomation.SeleniumWebDriver>()
        .Bootstrap("Chrome")
        .Config(settings => {
            // Easy access to FluentAutomation.Settings values
            settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(1);
        });


    TestChrome.Run("Hello Google", I => {
        I.Open("http://master.neutrino.com");
        I.Enter("myUserName").In("#txtUsername");
        I.Enter("myPassword").In("#txtPassword");
        I.Click("#btnLogin");
    // want to log timing here 
        I.Enter("Fred Bloggs\r\n").In("#inputGlobalSearch");
       I.Wait(1);
    //log timing here also
    ...etc
    });
Tim
  • 7,401
  • 13
  • 61
  • 102

1 Answers1

1

Since you're not chaining the methods on I, you can simply inject stopwatch code:

var TestChrome = Require<F14N>()
    .Init<FluentAutomation.SeleniumWebDriver>()
    .Bootstrap("Chrome")
    .Config(settings => {
        // Easy access to FluentAutomation.Settings values
        settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(1);
    });


TestChrome.Run("Hello Google", I => {
    I.Open("http://master.neutrino.com");
    I.Enter("myUserName").In("#txtUsername");
    I.Enter("myPassword").In("#txtPassword");
    I.Click("#btnLogin");

    StopWatch sw = new StopWatch()
    sw.Start();

    I.Enter("Fred Bloggs\r\n").In("#inputGlobalSearch");

    sw.Stop();
    Debug.Write(sw.ElapsedMilliseconds);

    I.Wait(1);
});

Creating an extension method for I that starts and stops a timer should be doable as well.

using FluentAutomation.Interfaces;

public static class IExtension
{
    public static StopWatch sw = new StopWatch();

    public static IActionSyntaxProvider StartTimer(this IActionSyntaxProvider) { sw.Reset(); sw.Start();  }
    public static IActionSyntaxProvider StopTimer(this IActionSyntaxProvider) { sw.Stop(); Trace.Write(sw.ElapsedMilliseconds); }

}

So it becomes:

TestChrome.Run("Hello Google", I => {
    I.Open("http://master.neutrino.com");
    I.Enter("myUserName").In("#txtUsername");
    I.Enter("myPassword").In("#txtPassword");
    I.Click("#btnLogin");
    IExtension.StartTimer(I);
    I.Enter("Fred Bloggs\r\n").In("#inputGlobalSearch");
    IExtension.StopTimer(I);

    I.Wait(1);
});

Or fluently when Roslyn starts to support it:

TestChrome.Run("Hello Google", I => {
    I
       .Open("http://master.neutrino.com");
       .Enter("myUserName").In("#txtUsername");
       .Enter("myPassword").In("#txtPassword");
       .Click("#btnLogin");
       .StartTimer();
       .Enter("Fred Bloggs\r\n").In("#inputGlobalSearch");
       .StopTimer();
       .Wait(1);
});
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • thanks that looks great, although im having issues getting your example to work, what usings do i need to use IActionSyntaxProvider and BaseFluentTest? – Tim Oct 16 '14 at 10:46
  • Updated. Haven't actually tested the extension method yet. No VS available today so I did this in notepad :). – jessehouwing Oct 16 '14 at 10:56
  • thanks yes (have corrected) I need to look modify my syntax a bit to use the extensions as i get an error saying extension methods must be defined in a top level class, FluentAutomationExtensions is a nested class. – Tim Oct 16 '14 at 11:02
  • i've just found the root of my problem, you cannot use extension methods in Roslyn. http://stackoverflow.com/questions/16948562/how-to-define-an-extension-method-in-a-scriptcs-csx-script – Tim Oct 16 '14 at 13:37
  • That's too bad, so you can't use the Fluent syntax in that case. – jessehouwing Oct 16 '14 at 13:38