目前,openGoogle() 确实会为每个具有正确参数的测试用例调用。问题是 setBrowser 似乎无法正常工作。它确实设置了第一次并成功完成了测试。但是,当第二次调用 openGoogle() 时,它会继续使用第一个浏览器,而不是使用指定的新浏览器。
使用 NFramework = NUnit.Framework; ...
[NFramework.TestFixture] public class SampleTest : FluentAutomation.FluentTest { string path; private Action<TinyIoCContainer> currentRegistration; public TestContext TestContext { get; set; } [NFramework.SetUp] public void Init() { FluentAutomation.Settings.ScreenshotOnFailedExpect = true; FluentAutomation.Settings.ScreenshotOnFailedAction = true; FluentAutomation.Settings.DefaultWaitTimeout = TimeSpan.FromSeconds(1); FluentAutomation.Settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(30); FluentAutomation.Settings.MinimizeAllWindowsOnTestStart = false; FluentAutomation.Settings.ScreenshotPath = path = "C:\\ScreenShots"; } [NFramework.Test] [NFramework.TestCase(SeleniumWebDriver.Browser.Firefox)] [NFramework.TestCase(SeleniumWebDriver.Browser.InternetExplorer)] public void openGoogle(SeleniumWebDriver.Browser browser) { setBrowser(browser); I.Open("http://www.google.com/"); I.WaitUntil(() => I.Expect.Exists("body")); I.Enter("Unit Testing").In("input[name=q]"); I.TakeScreenshot(browser + "EnterText"); I.Click("button[name=btnG]"); I.WaitUntil(() => I.Expect.Exists(".mw")); I.TakeScreenshot(browser + "ClickSearch"); } public SampleTest() { currentRegistration = FluentAutomation.Settings.Registration; } private void setBrowser(SeleniumWebDriver.Browser browser) { switch (browser) { case SeleniumWebDriver.Browser.InternetExplorer: case SeleniumWebDriver.Browser.Firefox: FluentAutomation.SeleniumWebDriver.Bootstrap(browser); break; } } }
注意:在下面这样做可以正常工作 - 为每个测试打开一个单独的浏览器。
公共类 SampleTest : FluentAutomation.FluentTest { 字符串路径;私人动作当前注册;公共 TestContext TestContext { 获取;放; }
private void ie() { FluentAutomation.SeleniumWebDriver.Bootstrap(FluentAutomation.SeleniumWebDriver.Browser.InternetExplorer); } private void ff() { >FluentAutomation.SeleniumWebDriver.Bootstrap(FluentAutomation.SeleniumWebDriver.Browser.Firefox); } public SampleTest() { //ff FluentAutomation.SeleniumWebDriver.Bootstrap(); currentRegistration = FluentAutomation.Settings.Registration; } [TestInitialize] public void Initialize() { FluentAutomation.Settings.ScreenshotOnFailedExpect = true; FluentAutomation.Settings.ScreenshotOnFailedAction = true; FluentAutomation.Settings.DefaultWaitTimeout = TimeSpan.FromSeconds(1); FluentAutomation.Settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(30); FluentAutomation.Settings.MinimizeAllWindowsOnTestStart = false; path = TestContext.TestResultsDirectory; FluentAutomation.Settings.ScreenshotPath = path; } [TestMethod] public void OpenGoogleIE() { ie(); openGoogle("IE"); } [TestMethod] public void OpenGoogleFF() { ff(); openGoogle("FF"); } private void openGoogle(string browser) { I.Open("http://www.google.com/"); I.WaitUntil(() => I.Expect.Exists("body")); I.Enter("Unit Testing").In("input[name=q]"); I.TakeScreenshot(browser + "EnterText"); I.Click("button[name=btnG]"); I.WaitUntil(() => I.Expect.Exists(".mw")); I.TakeScreenshot(browser + "ClickSearch"); } }