Skip to content

Commit

Permalink
Merge pull request #94 from FlaUI/test-coding-guidelines
Browse files Browse the repository at this point in the history
Add test coding guidelines
  • Loading branch information
aristotelos authored Sep 27, 2024
2 parents 814e059 + 598cb47 commit c7229cd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Use `dotnet test` to run tests. At the moment the tests are end-to-end UI tests

Add UI tests for every feature added and every bug fixed, and feel free to improve existing test coverage.

Follow the [naming convention `UnitOfWork_StateUnderTest_ExpectedBehavior`](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html) for test names.
Separate arrange/act/assert parts of the test by newlines.

## Submitting changes

Please send a [GitHub Pull Request](https://github.com/FlaUI/FlaUI.WebDriver/pulls) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Please follow our coding conventions (below) and make sure all of your commits are atomic (one feature per commit).
Expand Down
7 changes: 5 additions & 2 deletions src/FlaUI.WebDriver.UITests/ActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void PerformActions_KeyDownKeyUp_IsSupported()
element.Click();

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 "));
}
Expand All @@ -39,8 +40,8 @@ public void PerformActions_KeyDownKeyUp_IsSupported()
public void SendKeys_Default_IsSupported()
{
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

element.Clear();

element.SendKeys("abc123");

Assert.That(element.Text, Is.EqualTo("abc123"));
Expand All @@ -50,8 +51,8 @@ public void SendKeys_Default_IsSupported()
public void SendKeys_ShiftedCharacter_IsSupported()
{
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

element.Clear();

element.SendKeys("@TEST");

Assert.That(element.Text, Is.EqualTo("@TEST"));
Expand All @@ -77,6 +78,7 @@ public void PerformActions_MoveToElementAndClick_SelectsElement()
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

new Actions(_driver).MoveToElement(element).Click().Perform();

string activeElementText = _driver.SwitchTo().ActiveElement().Text;
Assert.That(activeElementText, Is.EqualTo("Test TextBox"));
}
Expand All @@ -97,6 +99,7 @@ public void PerformActions_MoveToElementMoveByOffsetAndClick_SelectsElement()
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

new Actions(_driver).MoveToElement(element).MoveByOffset(5, 0).Click().Perform();

string activeElementText = _driver.SwitchTo().ActiveElement().Text;
Assert.That(activeElementText, Is.EqualTo("Test TextBox"));
}
Expand Down
20 changes: 7 additions & 13 deletions src/FlaUI.WebDriver.UITests/ElementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public class ElementTests
[TestCase("InvokableButton", "Invoke me!")]
[TestCase("PopupToggleButton1", "Popup Toggle 1")]
[TestCase("Label", "Menu Item Checked")]
public void GetText_Returns_Correct_Text(string elementAccessibilityId, string expectedValue)
public void GetText_DifferentElements_ReturnsCorrectText(string elementAccessibilityId, string expectedValue)
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId(elementAccessibilityId));

var text = element.Text;

Assert.That(text, Is.EqualTo(expectedValue));
Expand Down Expand Up @@ -59,12 +60,11 @@ public void Displayed_UsingAppiumWebDriverElementHidden_ReturnsFalse()
}

[Test]
public void GetText_Returns_Text_For_Multiple_Selection()
public void GetText_ListMultipleSelection_ReturnsCombinedText()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("ListBox"));

new Actions(driver)
.MoveToElement(element)
.Click()
Expand All @@ -81,13 +81,12 @@ public void GetText_Returns_Text_For_Multiple_Selection()
}

[Test]
public void GetText_Returns_Empty_String_For_No_Selection()
public void GetText_ListNoSelection_ReturnsEmpty()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("ListBox"));
var item = driver.FindElement(ExtendedBy.Name("ListBox Item #1"));

new Actions(driver)
.MoveToElement(item)
.KeyDown(Keys.Control)
Expand Down Expand Up @@ -163,13 +162,13 @@ public void SendKeys_Default_IsSupported()
}

[Test]
public void SendKeys_ShiftedCharacter_ShiftIsReleased()
public void SendKeys_AfterShiftedCharacter_ShiftIsReleased()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));

element.SendKeys("!");

element.SendKeys("1");

Assert.That(element.Text, Is.EqualTo("!1Test TextBox"));
Expand All @@ -194,11 +193,8 @@ public void SendKeys_AltDownArrowEscape_IsSupported()
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("NonEditableCombo"));
var expandCollapseState = element.GetDomAttribute("ExpandCollapse.ExpandCollapseState");

Assert.That(expandCollapseState, Is.EqualTo("Collapsed"));

element.SendKeys(Keys.Alt + Keys.Down);

Assert.That(expandCollapseState, Is.EqualTo("Expanded"));

element.SendKeys(Keys.Escape);
Expand Down Expand Up @@ -236,8 +232,8 @@ public void GetElementRect_Default_IsSupported()
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var element = driver.FindElement(ExtendedBy.AccessibilityId("EditableCombo"));

var scaling = TestApplication.GetScaling(driver);

var location = element.Location;
var size = element.Size;

Expand Down Expand Up @@ -353,8 +349,6 @@ public void GetAttribute_PatternProperty_ReturnsValue()
value = element.GetDomAttribute("Toggle.ToggleState");

Assert.That(value, Is.EqualTo("On"));

element.Click();
}
}
}
19 changes: 19 additions & 0 deletions src/FlaUI.WebDriver.UITests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void NewSession_Timeouts_IsSupported()
driverOptions.ScriptTimeout = TimeSpan.FromSeconds(10);
driverOptions.PageLoadTimeout = TimeSpan.FromSeconds(50);
driverOptions.ImplicitWaitTimeout = TimeSpan.FromSeconds(3);

using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

Assert.That(driver.Manage().Timeouts().AsynchronousJavaScript, Is.EqualTo(TimeSpan.FromSeconds(10)));
Expand Down Expand Up @@ -125,6 +126,15 @@ public void NewSession_AppTopLevelWindow_IsSupported()
var title = driver.Title;

Assert.That(title, Is.EqualTo("FlaUI WPF Test App"));
}

[Test]
public void EndSession_AppTopLevelWindow_DoesNotKillApp()
{
using var testAppProcess = new TestAppProcess();
var windowHandle = string.Format("0x{0:x}", testAppProcess.Process.MainWindowHandle);
var driverOptions = FlaUIDriverOptions.AppTopLevelWindow(windowHandle);
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

driver.Quit();

Expand Down Expand Up @@ -166,6 +176,15 @@ public void NewSession_AppTopLevelWindowTitleMatch_IsSupported(string match)
var title = driver.Title;

Assert.That(title, Is.EqualTo("FlaUI WPF Test App"));
}

[Explicit("Sometimes multiple processes are left open")]
[Test]
public void EndSession_AppTopLevelWindowTitleMatch_DoesNotKillApp()
{
using var testAppProcess = new TestAppProcess();
var driverOptions = FlaUIDriverOptions.AppTopLevelWindowTitleMatch("FlaUI WPF Test App");
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

driver.Quit();

Expand Down
2 changes: 1 addition & 1 deletion src/FlaUI.WebDriver.UITests/WindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public void GetWindowRect_Default_IsSupported()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

var scaling = TestApplication.GetScaling(driver);

var position = driver.Manage().Window.Position;
var size = driver.Manage().Window.Size;

Expand Down
1 change: 1 addition & 0 deletions src/FlaUI.WebDriver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApplication", "TestAppli
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4F6F2546-27D9-468C-AD80-1629B54139DA}"
ProjectSection(SolutionItems) = preProject
..\CONTRIBUTING.md = ..\CONTRIBUTING.md
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down

0 comments on commit c7229cd

Please sign in to comment.