diff --git a/src/FlaUI.WebDriver.UITests/ActionsTest.cs b/src/FlaUI.WebDriver.UITests/ActionsTest.cs index 7eef541..ddcd386 100644 --- a/src/FlaUI.WebDriver.UITests/ActionsTest.cs +++ b/src/FlaUI.WebDriver.UITests/ActionsTest.cs @@ -9,32 +9,44 @@ namespace FlaUI.WebDriver.UITests [TestFixture] public class ActionsTests { + private RemoteWebDriver _driver; + + [SetUp] + public void Setup() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + _driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + } + + [TearDown] + public void Teardown() + { + _driver?.Dispose(); + } + [Test] public void PerformActions_KeyDownKeyUp_IsSupported() { - var driverOptions = FlaUIDriverOptions.TestApp(); - using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); - var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); + var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); element.Click(); - new Actions(driver).KeyDown(Keys.Control).KeyDown(Keys.Backspace).KeyUp(Keys.Backspace).KeyUp(Keys.Control).Perform(); - - Assert.That(driver.SwitchTo().ActiveElement().Text, Is.EqualTo("Test ")); + new Actions(_driver).KeyDown(Keys.Control).KeyDown(Keys.Backspace).KeyUp(Keys.Backspace).KeyUp(Keys.Control).Perform(); + string activeElementText = _driver.SwitchTo().ActiveElement().Text; + Assert.That(activeElementText, Is.EqualTo("Test ")); } [Test] public void ReleaseActions_Default_ReleasesKeys() { - var driverOptions = FlaUIDriverOptions.TestApp(); - using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); - var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); + var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); element.Click(); - new Actions(driver).KeyDown(Keys.Control).Perform(); + new Actions(_driver).KeyDown(Keys.Control).Perform(); - driver.ResetInputState(); + _driver.ResetInputState(); - new Actions(driver).KeyDown(Keys.Backspace).KeyUp(Keys.Backspace).Perform(); - Assert.That(driver.SwitchTo().ActiveElement().Text, Is.EqualTo("Test TextBo")); + new Actions(_driver).KeyDown(Keys.Backspace).KeyUp(Keys.Backspace).Perform(); + string activeElmentText = _driver.SwitchTo().ActiveElement().Text; + Assert.That(activeElmentText, Is.EqualTo("Test TextBo")); } } }