由于您没有在 上链接方法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);
});