0

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

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

1 回答 1

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);
});
于 2014-10-16T09:00:27.423 回答