Skip to content

Commit c7229cd

Browse files
authored
Merge pull request #94 from FlaUI/test-coding-guidelines
Add test coding guidelines
2 parents 814e059 + 598cb47 commit c7229cd

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Use `dotnet test` to run tests. At the moment the tests are end-to-end UI tests
1010

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

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

1518
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).

src/FlaUI.WebDriver.UITests/ActionsTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void PerformActions_KeyDownKeyUp_IsSupported()
3131
element.Click();
3232

3333
new Actions(_driver).KeyDown(Keys.Control).KeyDown(Keys.Backspace).KeyUp(Keys.Backspace).KeyUp(Keys.Control).Perform();
34+
3435
string activeElementText = _driver.SwitchTo().ActiveElement().Text;
3536
Assert.That(activeElementText, Is.EqualTo("Test "));
3637
}
@@ -39,8 +40,8 @@ public void PerformActions_KeyDownKeyUp_IsSupported()
3940
public void SendKeys_Default_IsSupported()
4041
{
4142
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));
42-
4343
element.Clear();
44+
4445
element.SendKeys("abc123");
4546

4647
Assert.That(element.Text, Is.EqualTo("abc123"));
@@ -50,8 +51,8 @@ public void SendKeys_Default_IsSupported()
5051
public void SendKeys_ShiftedCharacter_IsSupported()
5152
{
5253
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));
53-
5454
element.Clear();
55+
5556
element.SendKeys("@TEST");
5657

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

7980
new Actions(_driver).MoveToElement(element).Click().Perform();
81+
8082
string activeElementText = _driver.SwitchTo().ActiveElement().Text;
8183
Assert.That(activeElementText, Is.EqualTo("Test TextBox"));
8284
}
@@ -97,6 +99,7 @@ public void PerformActions_MoveToElementMoveByOffsetAndClick_SelectsElement()
9799
var element = _driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));
98100

99101
new Actions(_driver).MoveToElement(element).MoveByOffset(5, 0).Click().Perform();
102+
100103
string activeElementText = _driver.SwitchTo().ActiveElement().Text;
101104
Assert.That(activeElementText, Is.EqualTo("Test TextBox"));
102105
}

src/FlaUI.WebDriver.UITests/ElementTests.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ public class ElementTests
2323
[TestCase("InvokableButton", "Invoke me!")]
2424
[TestCase("PopupToggleButton1", "Popup Toggle 1")]
2525
[TestCase("Label", "Menu Item Checked")]
26-
public void GetText_Returns_Correct_Text(string elementAccessibilityId, string expectedValue)
26+
public void GetText_DifferentElements_ReturnsCorrectText(string elementAccessibilityId, string expectedValue)
2727
{
2828
var driverOptions = FlaUIDriverOptions.TestApp();
2929
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
3030
var element = driver.FindElement(ExtendedBy.AccessibilityId(elementAccessibilityId));
31+
3132
var text = element.Text;
3233

3334
Assert.That(text, Is.EqualTo(expectedValue));
@@ -59,12 +60,11 @@ public void Displayed_UsingAppiumWebDriverElementHidden_ReturnsFalse()
5960
}
6061

6162
[Test]
62-
public void GetText_Returns_Text_For_Multiple_Selection()
63+
public void GetText_ListMultipleSelection_ReturnsCombinedText()
6364
{
6465
var driverOptions = FlaUIDriverOptions.TestApp();
6566
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
6667
var element = driver.FindElement(ExtendedBy.AccessibilityId("ListBox"));
67-
6868
new Actions(driver)
6969
.MoveToElement(element)
7070
.Click()
@@ -81,13 +81,12 @@ public void GetText_Returns_Text_For_Multiple_Selection()
8181
}
8282

8383
[Test]
84-
public void GetText_Returns_Empty_String_For_No_Selection()
84+
public void GetText_ListNoSelection_ReturnsEmpty()
8585
{
8686
var driverOptions = FlaUIDriverOptions.TestApp();
8787
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
8888
var element = driver.FindElement(ExtendedBy.AccessibilityId("ListBox"));
8989
var item = driver.FindElement(ExtendedBy.Name("ListBox Item #1"));
90-
9190
new Actions(driver)
9291
.MoveToElement(item)
9392
.KeyDown(Keys.Control)
@@ -163,13 +162,13 @@ public void SendKeys_Default_IsSupported()
163162
}
164163

165164
[Test]
166-
public void SendKeys_ShiftedCharacter_ShiftIsReleased()
165+
public void SendKeys_AfterShiftedCharacter_ShiftIsReleased()
167166
{
168167
var driverOptions = FlaUIDriverOptions.TestApp();
169168
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
170169
var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox"));
171-
172170
element.SendKeys("!");
171+
173172
element.SendKeys("1");
174173

175174
Assert.That(element.Text, Is.EqualTo("!1Test TextBox"));
@@ -194,11 +193,8 @@ public void SendKeys_AltDownArrowEscape_IsSupported()
194193
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
195194
var element = driver.FindElement(ExtendedBy.AccessibilityId("NonEditableCombo"));
196195
var expandCollapseState = element.GetDomAttribute("ExpandCollapse.ExpandCollapseState");
197-
198196
Assert.That(expandCollapseState, Is.EqualTo("Collapsed"));
199-
200197
element.SendKeys(Keys.Alt + Keys.Down);
201-
202198
Assert.That(expandCollapseState, Is.EqualTo("Expanded"));
203199

204200
element.SendKeys(Keys.Escape);
@@ -236,8 +232,8 @@ public void GetElementRect_Default_IsSupported()
236232
var driverOptions = FlaUIDriverOptions.TestApp();
237233
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
238234
var element = driver.FindElement(ExtendedBy.AccessibilityId("EditableCombo"));
239-
240235
var scaling = TestApplication.GetScaling(driver);
236+
241237
var location = element.Location;
242238
var size = element.Size;
243239

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

355351
Assert.That(value, Is.EqualTo("On"));
356-
357-
element.Click();
358352
}
359353
}
360354
}

src/FlaUI.WebDriver.UITests/SessionTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void NewSession_Timeouts_IsSupported()
9797
driverOptions.ScriptTimeout = TimeSpan.FromSeconds(10);
9898
driverOptions.PageLoadTimeout = TimeSpan.FromSeconds(50);
9999
driverOptions.ImplicitWaitTimeout = TimeSpan.FromSeconds(3);
100+
100101
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
101102

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

127128
Assert.That(title, Is.EqualTo("FlaUI WPF Test App"));
129+
}
130+
131+
[Test]
132+
public void EndSession_AppTopLevelWindow_DoesNotKillApp()
133+
{
134+
using var testAppProcess = new TestAppProcess();
135+
var windowHandle = string.Format("0x{0:x}", testAppProcess.Process.MainWindowHandle);
136+
var driverOptions = FlaUIDriverOptions.AppTopLevelWindow(windowHandle);
137+
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
128138

129139
driver.Quit();
130140

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

168178
Assert.That(title, Is.EqualTo("FlaUI WPF Test App"));
179+
}
180+
181+
[Explicit("Sometimes multiple processes are left open")]
182+
[Test]
183+
public void EndSession_AppTopLevelWindowTitleMatch_DoesNotKillApp()
184+
{
185+
using var testAppProcess = new TestAppProcess();
186+
var driverOptions = FlaUIDriverOptions.AppTopLevelWindowTitleMatch("FlaUI WPF Test App");
187+
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
169188

170189
driver.Quit();
171190

src/FlaUI.WebDriver.UITests/WindowTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public void GetWindowRect_Default_IsSupported()
1414
{
1515
var driverOptions = FlaUIDriverOptions.TestApp();
1616
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
17-
1817
var scaling = TestApplication.GetScaling(driver);
18+
1919
var position = driver.Manage().Window.Position;
2020
var size = driver.Manage().Window.Size;
2121

src/FlaUI.WebDriver.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApplication", "TestAppli
1515
EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4F6F2546-27D9-468C-AD80-1629B54139DA}"
1717
ProjectSection(SolutionItems) = preProject
18+
..\CONTRIBUTING.md = ..\CONTRIBUTING.md
1819
..\README.md = ..\README.md
1920
EndProjectSection
2021
EndProject

0 commit comments

Comments
 (0)