从Fluent中检索时间

时间:2014-10-16 08:30:27

标签: c# selenium-webdriver roslyn fluentautomation

我正在构建一个Fluentautomation脚本,其中包含通过测试逐步执行我的应用程序的途径。是否有可能记录动作之间的时间,而不仅仅是在最后得到整体时间? 即。

    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
    });

1 个答案:

答案 0 :(得分:1)

由于您未在I上链接方法,因此您只需注入秒表代码:

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);
});

为I创建一个启动和停止计时器的扩展方法也应该是可行的。

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); }

}

所以它变成了:

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);
});

当Roslyn开始支持它时,或者流利地说:

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);
});