diff --git a/TestingApplication/App.xaml b/TestingApplication/App.xaml
index 1a11a4c..448f064 100644
--- a/TestingApplication/App.xaml
+++ b/TestingApplication/App.xaml
@@ -9,7 +9,6 @@
-
\ No newline at end of file
diff --git a/TestingApplication/MainWindow.xaml b/TestingApplication/MainWindow.xaml
index a403835..3763131 100644
--- a/TestingApplication/MainWindow.xaml
+++ b/TestingApplication/MainWindow.xaml
@@ -8,16 +8,18 @@
Title="MainWindow" Height="450" Width="800" Left="0" Top="0" WindowStartupLocation="CenterScreen">
-
+
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/TestingApplication/MainWindow.xaml.cs b/TestingApplication/MainWindow.xaml.cs
index b381365..a865830 100644
--- a/TestingApplication/MainWindow.xaml.cs
+++ b/TestingApplication/MainWindow.xaml.cs
@@ -23,62 +23,92 @@ public MainWindow()
InitializeComponent();
}
- private void clickEvent(object sender, RoutedEventArgs e)
+ private void ClickEvent(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button Clicked");
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// this.NavigationService.Navigate(new Uri("Page3.xaml", UriKind.Relative));
- ButtonWindow btnwindow = new ButtonWindow();
- btnwindow.Owner = this;
+ ButtonWindow btnwindow = new()
+ {
+ Owner = this
+ };
//Added for fixing blank window issue
Application.Current.MainWindow = btnwindow;
btnwindow.Show();
}
- private void calendarButton_Click(object sender, RoutedEventArgs e)
- {
- CalendarWindow clndrwindow = new CalendarWindow();
- clndrwindow.Owner = this;
+ private void CalendarButton_Click(object sender, RoutedEventArgs e)
+ {
+ CalendarWindow clndrwindow = new()
+ {
+ Owner = this
+ };
//Added for fixing blank window issue
Application.Current.MainWindow = clndrwindow;
clndrwindow.Show();
}
- private void textBoxButton_Click(object sender, RoutedEventArgs e)
+ private void TextBoxButton_Click(object sender, RoutedEventArgs e)
{
- TextWindow tw = new TextWindow();
- tw.Owner = this;
+ TextWindow tw = new()
+ {
+ Owner = this
+ };
Application.Current.MainWindow = tw;
tw.Show();
}
- private void comboBoxButton_Click(object sender, RoutedEventArgs e)
+ private void ComboBoxButton_Click(object sender, RoutedEventArgs e)
{
- ComboBoxViewModel vm = new ComboBoxViewModel();
- ComboBoxWindow cbw = new ComboBoxWindow(vm);
- cbw.Owner = this;
+ ComboBoxViewModel vm = new();
+ ComboBoxWindow cbw = new(vm)
+ {
+ Owner = this
+ };
+ Application.Current.MainWindow = cbw;
cbw.Show();
}
- private void checkboxButton_Click(object sender, RoutedEventArgs e)
+ private void CheckboxButton_Click(object sender, RoutedEventArgs e)
{
- CheckBoxViewModel viewModel=new CheckBoxViewModel();
- CheckboxWindow checkboxWindow = new CheckboxWindow(viewModel);
+ CheckBoxViewModel viewModel = new();
+ CheckboxWindow checkboxWindow = new(viewModel);
//Added for fixing blank window issue
Application.Current.MainWindow = checkboxWindow;
checkboxWindow.Owner = this;
checkboxWindow.Show();
}
- private void listboxButton_Click(object sender, RoutedEventArgs e)
+ private void ListboxButton_Click(object sender, RoutedEventArgs e)
+ {
+ ListboxWindow lstboxwindow = new()
+ {
+ Owner = this
+ };
+ //Added for fixing blank window issue
+ Application.Current.MainWindow = lstboxwindow;
+ lstboxwindow.Show();
+ }
+ private void SliderButton_Click(object sender, RoutedEventArgs e)
+ {
+ SliderWindow sliderWindow = new()
+ {
+ Owner = this
+ };
+ Application.Current.MainWindow = sliderWindow;
+ sliderWindow.Show();
+ }
+ private void RadioButton_Click(object sender, RoutedEventArgs e)
{
- ListboxWindow lstbxwindow = new ListboxWindow();
- lstbxwindow.Owner = this;
+ RadioButtonWindow radioButtonWindow = new()
+ {
+ Owner = this
+ };
//Added for fixing blank window issue
- Application.Current.MainWindow = lstbxwindow;
- lstbxwindow.Show();
+ Application.Current.MainWindow = radioButtonWindow;
+ radioButtonWindow.Show();
}
}
}
\ No newline at end of file
diff --git a/TestingApplication/RadioButtonWindow.xaml b/TestingApplication/RadioButtonWindow.xaml
new file mode 100644
index 0000000..f1dbd48
--- /dev/null
+++ b/TestingApplication/RadioButtonWindow.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TestingApplication/RadioButtonWindow.xaml.cs b/TestingApplication/RadioButtonWindow.xaml.cs
new file mode 100644
index 0000000..8a799be
--- /dev/null
+++ b/TestingApplication/RadioButtonWindow.xaml.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace TestingApplication
+{
+ ///
+ /// Interaction logic for RadioButtonWindow.xaml
+ ///
+ public partial class RadioButtonWindow : Window
+ {
+ public RadioButtonWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/TestingApplication/SliderWindow.xaml b/TestingApplication/SliderWindow.xaml
new file mode 100644
index 0000000..ad15cfd
--- /dev/null
+++ b/TestingApplication/SliderWindow.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/TestingApplication/SliderWindow.xaml.cs b/TestingApplication/SliderWindow.xaml.cs
new file mode 100644
index 0000000..c15e9e5
--- /dev/null
+++ b/TestingApplication/SliderWindow.xaml.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace TestingApplication
+{
+ ///
+ /// Interaction logic for SliderWindow.xaml
+ ///
+ public partial class SliderWindow : Window
+ {
+ public SliderWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Win11ThemeTest/ButtonTest.cs b/Win11ThemeTest/ButtonTest.cs
index 7d5dce2..d024bd4 100644
--- a/Win11ThemeTest/ButtonTest.cs
+++ b/Win11ThemeTest/ButtonTest.cs
@@ -18,52 +18,60 @@ public class ButtonTest
public ButtonTest()
{
- try
- {
var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
+ app = LaunchApplication(appPath);
using var automation = new UIA3Automation();
- window = app.GetMainWindow(automation);
- testButton = window.FindFirstDescendant(cf => cf.ByAutomationId("testbtn")).AsButton();
- Mouse.Click(testButton.GetClickablePoint());
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(2000));
- btnWindow = window.FindFirstDescendant(cf => cf.ByName("ButtonWindow")).AsWindow();
- button = btnWindow.FindFirstDescendant(cf => cf.ByAutomationId("btn")).AsButton();
- disabledButton = btnWindow.FindFirstDescendant(cf => cf.ByAutomationId("disbtn")).AsButton();
+ window = app?.GetMainWindow(automation);
+ testButton = window?.FindFirstDescendant(cf => cf.ByAutomationId("testbtn")).AsButton();
+ ClickButton(testButton);
+
+ btnWindow = window?.FindFirstDescendant(cf => cf.ByName("ButtonWindow")).AsWindow();
+ button = btnWindow?.FindFirstDescendant(cf => cf.ByAutomationId("btn")).AsButton();
+ disabledButton = btnWindow?.FindFirstDescendant(cf => cf.ByAutomationId("disbtn")).AsButton();
+
+ }
+
+
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using StreamWriter sw = File.AppendText(filePath);
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- else
- {
- throw new ArgumentNullException();
- }
-
+ LogException(ex);
+ throw;
}
}
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
//test if button is available in window
[Test]
- public void Button1_isButtonAvailable()
+ public void Button1_IsButtonAvailable()
{
Assert.Multiple(() =>
{
@@ -75,7 +83,7 @@ public void Button1_isButtonAvailable()
//test if button is clicked
[Test]
- public void Button2_isClicked()
+ public void Button2_IsClicked()
{
Assert.That(button, Is.Not.Null);
button.Click();
@@ -89,7 +97,7 @@ public void Button2_isClicked()
//test if button clicked with enter key
[Test]
- public void Button3_isClickableWithEnterKey()
+ public void Button3_IsClickableWithEnterKey()
{
Assert.That(button, Is.Not.Null);
button.Focus();
@@ -104,7 +112,7 @@ public void Button3_isClickableWithEnterKey()
//test if button clicked with space key
[Test]
- public void Button4_isClickableWithSpaceKey()
+ public void Button4_IsClickableWithSpaceKey()
{
Assert.That(button, Is.Not.Null);
button.Focus();
@@ -120,7 +128,7 @@ public void Button4_isClickableWithSpaceKey()
//test no action on mouse right click on button
[Test]
- public void Button5_onMouseRightClick()
+ public void Button5_OnMouseRightClick()
{
Assert.That(button, Is.Not.Null);
button.RightClick();
@@ -131,7 +139,7 @@ public void Button5_onMouseRightClick()
//Test disabled button
[Test]
- public void Button6_isDisabled()
+ public void Button6_IsDisabled()
{
Assert.That(disabledButton, Is.Not.Null);
Assert.That(disabledButton.IsEnabled, Is.False);
@@ -139,7 +147,7 @@ public void Button6_isDisabled()
//Test disabled button
[Test]
- public void Button7_isDisabledClick()
+ public void Button7_IsDisabledClick()
{
Assert.That(disabledButton, Is.Not.Null);
Assert.That(disabledButton.IsEnabled, Is.False);
@@ -150,16 +158,19 @@ public void Button7_isDisabledClick()
//close windows
[Test]
- public void Button8_closeWindows()
+ public void Button8_CloseWindows()
{
- Assert.That(btnWindow, Is.Not.Null);
- btnWindow.Close();
- Wait.UntilInputIsProcessed();
- Assert.That(btnWindow.IsOffscreen);
- Wait.UntilInputIsProcessed();
- Assert.That(window, Is.Not.Null);
- window.Close();
- Assert.That(window.IsOffscreen);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
}
diff --git a/Win11ThemeTest/CalendarTest.cs b/Win11ThemeTest/CalendarTest.cs
index efb7e18..0ea672b 100644
--- a/Win11ThemeTest/CalendarTest.cs
+++ b/Win11ThemeTest/CalendarTest.cs
@@ -23,52 +23,58 @@ public class CalendarTest
public CalendarTest()
{
- try
- {
var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
+ app = LaunchApplication(appPath);
using var automation = new UIA3Automation();
- window = app.GetMainWindow(automation);
- testButton = window.FindFirstDescendant(cf => cf.ByAutomationId("calendartestbtn")).AsButton();
- Mouse.Click(testButton.GetClickablePoint());
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(2000));
- calWindow = window.FindFirstDescendant(cf => cf.ByName("CalendarWindow")).AsWindow();
- calendar = calWindow.FindFirstDescendant(cf => cf.ByAutomationId("tstCal")).AsCalendar();
- multiSelectCalendar = calWindow.FindFirstDescendant(cf => cf.ByAutomationId("tstCal_multiSelect")).AsCalendar();
+ window = app?.GetMainWindow(automation);
+ testButton = window?.FindFirstDescendant(cf => cf.ByAutomationId("calendartestbtn")).AsButton();
+ ClickButton(testButton);
+ calWindow = window?.FindFirstDescendant(cf => cf.ByName("CalendarWindow")).AsWindow();
+ calendar = calWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tstCal")).AsCalendar();
+ multiSelectCalendar = calWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tstCal_multiSelect")).AsCalendar();
+ }
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using StreamWriter sw = File.AppendText(filePath);
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- else
- {
- throw new ArgumentNullException();
- }
+ LogException(ex);
+ throw;
}
}
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
+
//test if calendar is available in window
[Test]
- public void Calendar1_isCalendarAvailable()
+ public void Calendar1_IsCalendarAvailable()
{
Assert.Multiple(() =>
{
@@ -79,7 +85,7 @@ public void Calendar1_isCalendarAvailable()
//test if selected date is today's date
[Test]
- public void Calendar2_isCalendarTodayDate()
+ public void Calendar2_IsCalendarTodayDate()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -91,7 +97,7 @@ public void Calendar2_isCalendarTodayDate()
//test for click previous month button
[Test]
- public void Calendar3_isCalendarClickPrevMonth()
+ public void Calendar3_IsCalendarClickPrevMonth()
{
Assert.That(calendar, Is.Not.Null);
headerBtn = calendar.FindFirstChild(cf => cf.ByAutomationId("PART_HeaderButton"));
@@ -113,7 +119,7 @@ public void Calendar3_isCalendarClickPrevMonth()
//test for click next month button
[Test]
- public void Calendar4_isCalendarClickNextMonth()
+ public void Calendar4_IsCalendarClickNextMonth()
{
Assert.That(calendar, Is.Not.Null);
headerBtn = calendar.FindFirstChild(cf => cf.ByAutomationId("PART_HeaderButton"));
@@ -138,7 +144,7 @@ public void Calendar4_isCalendarClickNextMonth()
//test for click Month year button
[Test]
- public void Calendar5_isCalendarClickMonthYear()
+ public void Calendar5_IsCalendarClickMonthYear()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -170,7 +176,7 @@ public void Calendar5_isCalendarClickMonthYear()
//test for click prev year button
[Test]
- public void Calendar6_isCalendarClickPrevYear()
+ public void Calendar6_IsCalendarClickPrevYear()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -209,7 +215,7 @@ public void Calendar6_isCalendarClickPrevYear()
//test for click next year button
[Test]
- public void Calendar7_isCalendarClickNextYear()
+ public void Calendar7_IsCalendarClickNextYear()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -248,7 +254,7 @@ public void Calendar7_isCalendarClickNextYear()
//test for click year button
[Test]
- public void Calendar8_isCalendarClickYear()
+ public void Calendar8_IsCalendarClickYear()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -303,7 +309,7 @@ public void Calendar8_isCalendarClickYear()
//test for click previous year range button
[Test]
- public void Calendar9_isCalendarClickPrevYearRange()
+ public void Calendar9_IsCalendarClickPrevYearRange()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -373,7 +379,7 @@ public void Calendar9_isCalendarClickPrevYearRange()
//test for click next year range button
[Test]
- public void Calendars1_isCalendarClickPrevYearRange()
+ public void Calendars1_IsCalendarClickPrevYearRange()
{
Assert.That(calendar, Is.Not.Null);
DateTime thisDay = DateTime.Today;
@@ -495,16 +501,19 @@ public void Calendars3_AddRangeToSelectionTest()
}
[Test]
- public void Calendars4_closeWindows()
+ public void Calendars4_CloseWindows()
{
- Assert.That(calWindow, Is.Not.Null);
- calWindow.Focus();
- calWindow.Close();
- Assert.That(calWindow.IsOffscreen, Is.True);
- Wait.UntilInputIsProcessed();
- Assert.That(window, Is.Not.Null);
- window.Close();
- Assert.That(window.IsOffscreen, Is.True);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
}
}
diff --git a/Win11ThemeTest/CheckBoxTest.cs b/Win11ThemeTest/CheckBoxTest.cs
deleted file mode 100644
index 83e4b3a..0000000
--- a/Win11ThemeTest/CheckBoxTest.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using FlaUI.Core;
-using FlaUI.Core.AutomationElements;
-using FlaUI.Core.Definitions;
-using FlaUI.UIA3;
-
-namespace Win11ThemeTest
-{
- public class cbTests
- {
- [SetUp]
- public void Setup()
- {
- }
-
- [Test]
- public void CheckBoxCheckedTest()
- {
- var app = FlaUI.Core.Application.Launch(@"..\\..\\..\\..\\Win11ThemeSampleApp\\bin\\x64\\Debug\\net9.0-windows\\win-x64\\Win11ThemeSampleApp.exe");
- using (var automation = new UIA3Automation())
- {
- var window = app.GetMainWindow(automation);
- var checkBox = window.FindFirstDescendant(cf => cf.ByName("Test Checkbox")).AsCheckBox();
- Assert.That(checkBox.ToggleState, Is.EqualTo(ToggleState.Off));
- checkBox.Toggle();
- Assert.That(checkBox.ToggleState, Is.EqualTo(ToggleState.On));
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Win11ThemeTest/CheckBoxTests.cs b/Win11ThemeTest/CheckBoxTests.cs
index e0384db..303347c 100644
--- a/Win11ThemeTest/CheckBoxTests.cs
+++ b/Win11ThemeTest/CheckBoxTests.cs
@@ -22,52 +22,61 @@ public class CheckBoxTests
public CheckBoxTests()
{
- try
- {
+
var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
+ app = LaunchApplication(appPath);
using var automation = new UIA3Automation();
- window = app.GetMainWindow(automation);
- testButton = window.FindFirstDescendant(cf => cf.ByAutomationId("testchkbtn")).AsButton();
- Mouse.Click(testButton.GetClickablePoint());
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(2000));
- checkboxWindow = window.FindFirstDescendant(cf => cf.ByName("CheckboxWindow")).AsWindow();
- checkBox = checkboxWindow.FindFirstDescendant(cf => cf.ByAutomationId("tstCheckbox")).AsCheckBox();
- threeStateCheckBox = checkboxWindow.FindFirstDescendant(cf => cf.ByAutomationId("threestateCheckbox")).AsCheckBox();
- selectCheckBox = checkboxWindow.FindFirstDescendant(cf => cf.ByName("Select all")).AsCheckBox();
+ window = app?.GetMainWindow(automation);
+ testButton = window?.FindFirstDescendant(cf => cf.ByAutomationId("testchkbtn")).AsButton();
+ ClickButton(testButton);
+ checkboxWindow = window?.FindFirstDescendant(cf => cf.ByName("CheckboxWindow")).AsWindow();
+ checkBox = checkboxWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tstCheckbox")).AsCheckBox();
+ threeStateCheckBox = checkboxWindow?.FindFirstDescendant(cf => cf.ByAutomationId("threestateCheckbox")).AsCheckBox();
+ selectCheckBox = checkboxWindow?.FindFirstDescendant(cf => cf.ByName("Select all")).AsCheckBox();
+ }
+
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using StreamWriter sw = File.AppendText(filePath);
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- else
- {
- throw new ArgumentNullException();
- }
+ LogException(ex);
+ throw;
}
}
+
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
+
#region simplecheckbox
//test if checkbox is available in window
[Test]
- public void Checkbox1_isCheckboxAvailable()
+ public void Checkbox1_IsCheckboxAvailable()
{
Assert.Multiple(() =>
{
@@ -78,7 +87,7 @@ public void Checkbox1_isCheckboxAvailable()
//test if checkbox is not checked by default
[Test]
- public void Checkbox2_isNotChecked()
+ public void Checkbox2_IsNotChecked()
{
Assert.That(checkBox, Is.Not.Null);
Assert.That(checkBox.IsChecked, Is.False);
@@ -86,7 +95,7 @@ public void Checkbox2_isNotChecked()
//test if checkbox is checked on toggle
[Test]
- public void Checkbox3_isChecked()
+ public void Checkbox3_IsChecked()
{
Assert.That(checkBox, Is.Not.Null);
Assert.That(checkBox.IsChecked, Is.False);
@@ -97,7 +106,7 @@ public void Checkbox3_isChecked()
//test if checkbox is checked with space key
[Test]
- public void Checkbox4_isCheckedWithSpaceKey()
+ public void Checkbox4_IsCheckedWithSpaceKey()
{
Assert.That(checkBox, Is.Not.Null);
checkBox.Focus();
@@ -109,7 +118,7 @@ public void Checkbox4_isCheckedWithSpaceKey()
//test if checkbox is checked with mouseclick
[Test]
- public void Checkbox5_isCheckedOnMouseClick()
+ public void Checkbox5_IsCheckedOnMouseClick()
{
Assert.That(checkBox, Is.Not.Null);
Mouse.MoveTo(checkBox.GetClickablePoint());
@@ -126,7 +135,7 @@ public void Checkbox5_isCheckedOnMouseClick()
//test if three state checkbox is available in window
[Test]
- public void CheckboxThreeState1_is3StateCheckboxAvailable()
+ public void CheckboxThreeState1_Is3StateCheckboxAvailable()
{
Assert.Multiple(() =>
{
@@ -137,7 +146,7 @@ public void CheckboxThreeState1_is3StateCheckboxAvailable()
//test if the state is ON with single togle
[Test]
- public void CheckboxThreeState2_is3StateCheckboxToggleOn()
+ public void CheckboxThreeState2_Is3StateCheckboxToggleOn()
{
Assert.That(threeStateCheckBox, Is.Not.Null);
threeStateCheckBox.Toggle();
@@ -148,7 +157,7 @@ public void CheckboxThreeState2_is3StateCheckboxToggleOn()
//test for intermediate toggle state
[Test]
- public void CheckboxThreeState3_is3StateCheckboxToggleIntermediate()
+ public void CheckboxThreeState3_Is3StateCheckboxToggleIntermediate()
{
Assert.That(threeStateCheckBox, Is.Not.Null);
threeStateCheckBox.Toggle();
@@ -159,7 +168,7 @@ public void CheckboxThreeState3_is3StateCheckboxToggleIntermediate()
//test for OFF state
[Test]
- public void CheckboxThreeState4_is3StateCheckboxToggleOff()
+ public void CheckboxThreeState4_Is3StateCheckboxToggleOff()
{
Assert.That(threeStateCheckBox, Is.Not.Null);
threeStateCheckBox.Toggle();
@@ -170,7 +179,7 @@ public void CheckboxThreeState4_is3StateCheckboxToggleOff()
//test for toggle on mouse click
[Test]
- public void CheckboxThreeState5_is3StateCheckboxToggleMouseClick()
+ public void CheckboxThreeState5_Is3StateCheckboxToggleMouseClick()
{
Assert.That(threeStateCheckBox, Is.Not.Null);
threeStateCheckBox.Click();
@@ -181,7 +190,7 @@ public void CheckboxThreeState5_is3StateCheckboxToggleMouseClick()
//test for toggle on Space key
[Test]
- public void CheckboxThreeState6_is3StateCheckboxToggleSpaceKey()
+ public void CheckboxThreeState6_Is3StateCheckboxToggleSpaceKey()
{
Assert.That(threeStateCheckBox, Is.Not.Null);
threeStateCheckBox.Focus();
@@ -194,7 +203,7 @@ public void CheckboxThreeState6_is3StateCheckboxToggleSpaceKey()
//test select all checkbox in 3 state scenario
[Test]
- public void CheckboxThreeState7_is3stateCheckboxSelectAll()
+ public void CheckboxThreeState7_Is3stateCheckboxSelectAll()
{
Assert.That(checkboxWindow, Is.Not.Null);
selectCheckBox = checkboxWindow.FindFirstDescendant(cf => cf.ByName("Select all")).AsCheckBox();
@@ -216,7 +225,7 @@ public void CheckboxThreeState7_is3stateCheckboxSelectAll()
//test deselect all checkbox in 3 state scenario
[Test]
- public void CheckboxThreeState8_is3stateCheckboxDeselectAll()
+ public void CheckboxThreeState8_Is3stateCheckboxDeselectAll()
{
Assert.That(selectCheckBox, Is.Not.Null);
selectCheckBox.Focus();
@@ -238,7 +247,7 @@ public void CheckboxThreeState8_is3stateCheckboxDeselectAll()
//test intermediate state checkbox in 3 state scenario
[Test]
- public void CheckboxThreeState9_is3stateCheckboxSelectOneOption()
+ public void CheckboxThreeState9_Is3stateCheckboxSelectOneOption()
{
Assert.That(checkboxWindow, Is.Not.Null);
option1 = checkboxWindow.FindFirstDescendant(cf => cf.ByName("Option 1")).AsCheckBox();
@@ -262,14 +271,17 @@ public void CheckboxThreeState9_is3stateCheckboxSelectOneOption()
[Test]
public void CloseWindows()
{
- Assert.That(checkboxWindow, Is.Not.Null);
- checkboxWindow.Close();
- Wait.UntilInputIsProcessed();
- Assert.That(checkboxWindow.IsOffscreen, Is.True);
- Wait.UntilInputIsProcessed();
- Assert.That(window, Is.Not.Null);
- window.Close();
- Assert.That(window.IsOffscreen, Is.True);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
#endregion
}
diff --git a/Win11ThemeTest/ComboBoxTest.cs b/Win11ThemeTest/ComboBoxTest.cs
index 51d4d35..64c9508 100644
--- a/Win11ThemeTest/ComboBoxTest.cs
+++ b/Win11ThemeTest/ComboBoxTest.cs
@@ -7,157 +7,169 @@
namespace Win11ThemeTest
{
- public class comboBoxTests
+ public class ComboBoxTests
{
- private Application? app;
- private Window? mainWindow;
- public Window? comboWindow;
- Button? comboBoxButton;
- ComboBox? comboBox;
- ComboBox? comboBoxEditable;
- ComboBox? comboBoxBind;
- public comboBoxTests()
+ private readonly Application? app;
+ private readonly Window? mainWindow;
+ private readonly Window? comboWindow;
+ private readonly Button? comboBoxButton;
+ private readonly ComboBox? comboBox;
+ private readonly ComboBox? comboBoxEditable;
+ private readonly ComboBox? comboBoxBind;
+
+ public ComboBoxTests()
+ {
+ var appPath = ConfigurationManager.AppSettings["Testpath"];
+ app = LaunchApplication(appPath);
+ using var automation = new UIA3Automation();
+ mainWindow = app?.GetMainWindow(automation);
+
+ comboBoxButton = mainWindow?.FindFirstDescendant(cf => cf.ByAutomationId("cmbBoxButton")).AsButton();
+ ClickButton(comboBoxButton);
+
+ comboWindow = mainWindow?.FindFirstDescendant(cf => cf.ByName("ComboBoxWindow")).AsWindow();
+ comboBox = comboWindow?.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxList")).AsComboBox();
+ comboBoxEditable = comboWindow?.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxEditable")).AsComboBox();
+ comboBoxBind = comboWindow?.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxBind")).AsComboBox();
+ }
+
+ private static Application? LaunchApplication(string? appPath)
{
try
{
- var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
- using (var automation = new UIA3Automation())
- {
- mainWindow = app.GetMainWindow(automation);
- comboBoxButton = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("cmbBoxButton")).AsButton();
- Mouse.Click(comboBoxButton.GetClickablePoint());
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
- comboWindow = mainWindow.FindFirstDescendant(cf => cf.ByName("ComboBoxWindow")).AsWindow();
- comboBox = comboWindow.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxList")).AsComboBox();
- comboBoxEditable = comboWindow.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxEditable")).AsComboBox();
- comboBoxBind = comboWindow.FindFirstDescendant(cf => cf.ByAutomationId("comboBoxBind")).AsComboBox();
- }
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using (StreamWriter sw = File.AppendText(filePath))
- {
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- }
- else
- {
- throw new ArgumentNullException();
- }
+ LogException(ex);
+ throw;
}
}
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
+
[Test]
- public void comboBox_isAvailable()
+ public void ComboBox_IsAvailable()
{
- Assert.IsNotNull(comboWindow);
- Assert.IsNotNull(comboBox);
- Assert.IsNotNull(comboBoxEditable);
- Assert.IsNotNull(comboBoxBind);
+ Assert.Multiple(() =>
+ {
+ Assert.That(comboWindow, Is.Not.Null);
+ Assert.That(comboBox, Is.Not.Null);
+ Assert.That(comboBoxEditable, Is.Not.Null);
+ Assert.That(comboBoxBind, Is.Not.Null);
+ });
}
[Test]
- public void comboBox_selectedDefaultItem()
+ public void ComboBox_SelectedDefaultItem()
{
- Assert.IsNotNull(comboBox);
- Assert.That(comboBox.SelectedItem, Is.Not.Null);
+ Assert.That(comboBox, Is.Not.Null);
+ Assert.That(comboBox?.SelectedItem, Is.Not.Null);
}
[Test]
- public void comboBox_isNull()
+ public void ComboBox_IsNotNull()
{
- Assert.That(comboBox, Is.Not.Null);
+ Assert.That(comboBox, Is.Not.Null);
}
[Test]
- public void comboBox_isReadableEditable()
+ public void ComboBox_IsReadableEditable()
{
- Assert.IsNotNull(comboBox);
- Assert.That(comboBox.IsReadOnly, Is.False);
- Assert.That(comboBox.IsEditable, Is.False);
- Assert.IsNotNull(comboBoxEditable);
- Assert.That(comboBoxEditable.IsEditable, Is.True);
+ Assert.That(comboBox, Is.Not.Null);
+ Assert.Multiple(() =>
+ {
+ Assert.That(comboBox?.IsReadOnly, Is.False);
+ Assert.That(comboBox?.IsEditable, Is.False);
+ });
+ Assert.That(comboBoxEditable, Is.Not.Null);
+ Assert.That(comboBoxEditable?.IsEditable, Is.True);
}
-
+
[Test]
- public void comboBox1_selectItem()
+ public void ComboBox1_SelectItem()
{
- Assert.IsNotNull(comboBox);
- comboBox.Select("Red");
- Assert.That(comboBox.SelectedItem.Name, Is.EqualTo("Red"));
+ Assert.That(comboBox, Is.Not.Null);
+ comboBox?.Select("Red");
+ Assert.That(comboBox?.SelectedItem.Name, Is.EqualTo("Red"));
}
- //Check if the drop-down is open by clicking on both the drop-down & the drop-down Arrow.
- [Test]
- public void comboBox1_expandCollapse()
+ [Test]
+ public void ComboBox1_ExpandCollapse()
{
- Assert.IsNotNull(comboBox);
- comboBox.Expand();
- Assert.That(comboBox.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Expanded));
- comboBox.Collapse();
- Assert.That(comboBox.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Collapsed));
- }
+ Assert.That(comboBox, Is.Not.Null);
+ comboBox?.Expand();
+ Assert.That(comboBox?.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Expanded));
+ comboBox?.Collapse();
+ Assert.That(comboBox?.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Collapsed));
+ }
[Test]
- public void comboBox2_editableText()
- {
+ public void ComboBox2_EditableText()
+ {
Assert.That(comboBoxEditable, Is.Not.Null);
- Assert.That(comboBoxEditable.IsEditable, Is.True);
comboBoxEditable.EditableText = "10";
- Assert.That(comboBoxEditable.SelectedItem, Is.Not.Null);
- Assert.That(comboBoxEditable.SelectedItem.Text, Is.EqualTo("10"));
+ Assert.That(comboBoxEditable?.SelectedItem, Is.Not.Null);
+ Assert.That(comboBoxEditable?.SelectedItem.Text, Is.EqualTo("10"));
}
- //Check whether the dropdown is clickable or not.
[Test]
- public void comboBox3_mouseClick()
+ public void ComboBox3_MouseClick()
{
- Assert.IsNotNull(comboBox);
- Mouse.MoveTo(comboBox.GetClickablePoint());
- Mouse.Click();
- Assert.That(comboBox.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Expanded));
- comboBox.Collapse();
+ Assert.That(comboBox, Is.Not.Null);
+ comboBox?.Click();
+ Assert.That(comboBox?.ExpandCollapseState, Is.EqualTo(ExpandCollapseState.Expanded));
+ comboBox?.Collapse();
}
[Test]
- public void comboBox4_mouseSelectClick()
+ public void ComboBox4_MouseSelectClick()
{
- Assert.IsNotNull(comboBox);
+ Assert.That(comboBox, Is.Not.Null);
Mouse.MoveTo(comboBox.GetClickablePoint());
- Mouse.Click();
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
- comboBox.Items[3].Click();
- Assert.That(comboBox.SelectedItem.Name, Is.EqualTo("Yellow"));
+ Mouse.Click();
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ comboBox?.Items[3].Click();
+ Assert.That(comboBox?.SelectedItem.Name, Is.EqualTo("Yellow"));
}
[Test]
- public void comboBox5_cleanUp()
+ public void ComboBox5_CleanUp()
{
- Assert.IsNotNull(comboWindow);
- comboWindow.Close();
- Wait.UntilInputIsProcessed();
- Assert.IsTrue(comboWindow.IsOffscreen);
- Assert.IsNotNull(mainWindow);
- mainWindow.Close();
- Assert.IsTrue(mainWindow.IsOffscreen);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
}
}
diff --git a/Win11ThemeTest/ListBoxTest.cs b/Win11ThemeTest/ListBoxTest.cs
index 4f67179..bbccd1d 100644
--- a/Win11ThemeTest/ListBoxTest.cs
+++ b/Win11ThemeTest/ListBoxTest.cs
@@ -18,51 +18,58 @@ public class ListBoxTest
readonly ListBox? listBoxLength;
public ListBoxTest()
{
- try
- {
+
var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
+ app = LaunchApplication(appPath);
using var automation = new UIA3Automation();
- window = app.GetMainWindow(automation);
- testButton = window.FindFirstDescendant(cf => cf.ByAutomationId("listBoxtestbtn")).AsButton();
- Mouse.Click(testButton.GetClickablePoint());
- Wait.UntilInputIsProcessed();
- listBoxWindow = window.FindFirstDescendant(cf => cf.ByName("ListboxWindow")).AsWindow();
- listBox = listBoxWindow.FindFirstDescendant(cf => cf.ByAutomationId("tstLstbox")).AsListBox();
- listBoxLength = listBoxWindow.FindFirstDescendant(cf => cf.ByAutomationId("tstlengthLstbox")).AsListBox();
+ window = app?.GetMainWindow(automation);
+ testButton = window?.FindFirstDescendant(cf => cf.ByAutomationId("listBoxtestbtn")).AsButton();
+ ClickButton(testButton);
+ listBoxWindow = window?.FindFirstDescendant(cf => cf.ByName("ListboxWindow")).AsWindow();
+ listBox = listBoxWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tstLstbox")).AsListBox();
+ listBoxLength = listBoxWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tstlengthLstbox")).AsListBox();
+ }
+
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using StreamWriter sw = File.AppendText(filePath);
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- else
- {
- throw new ArgumentNullException();
- }
+ LogException(ex);
+ throw;
}
}
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
//test if listBox is available in window
[Test]
- public void ListBox1_isListBoxAvailable()
+ public void ListBox1_IsListBoxAvailable()
{
Assert.Multiple(() =>
{
@@ -73,7 +80,7 @@ public void ListBox1_isListBoxAvailable()
//test if listBox is empty or populated with default values
[Test]
- public void ListBox2_isListBoxEmpty()
+ public void ListBox2_IsListBoxEmpty()
{
Assert.That(listBox, Is.Not.Null);
var selectListItems = listBox.Items;
@@ -82,7 +89,7 @@ public void ListBox2_isListBoxEmpty()
//test if listBox return default selected item
[Test]
- public void ListBox3_defaultSelectedItem()
+ public void ListBox3_DefaultSelectedItem()
{
Assert.That(listBox, Is.Not.Null);
var selectList = listBox.SelectedItem;
@@ -92,7 +99,7 @@ public void ListBox3_defaultSelectedItem()
//test selecting listBox item on mouse click
[Test]
- public void ListBox4_selectItemMouseClick()
+ public void ListBox4_SelectItemMouseClick()
{
Assert.That(listBox, Is.Not.Null);
var selectList = listBox.SelectedItem;
@@ -104,7 +111,7 @@ public void ListBox4_selectItemMouseClick()
//test if listBox return selected item
[Test]
- public void ListBox5_isSelectedItemByIndex()
+ public void ListBox5_IsSelectedItemByIndex()
{
Assert.That(listBox, Is.Not.Null);
var selectList = listBox.Select(2);
@@ -114,7 +121,7 @@ public void ListBox5_isSelectedItemByIndex()
//test list item by text
[Test]
- public void ListBox6_isSelectedByItemText()
+ public void ListBox6_IsSelectedByItemText()
{
Assert.That(listBox, Is.Not.Null);
var selectList = listBox.Select("Red");
@@ -124,7 +131,7 @@ public void ListBox6_isSelectedByItemText()
//test scrollbar for fixed length of listBox
[Test]
- public void ListBox7_verticalScrollBarForFixedLength()
+ public void ListBox7_VerticalScrollBarForFixedLength()
{
Assert.That(listBox, Is.Not.Null);
Assert.That(listBox.Patterns.Scroll.Pattern.VerticallyScrollable.Value, Is.False);
@@ -134,7 +141,7 @@ public void ListBox7_verticalScrollBarForFixedLength()
//test keyboard navigate with down arrow
[Test]
- public void ListBox8_keyBoardNavigateDown()
+ public void ListBox8_KeyBoardNavigateDown()
{
Assert.That(listBox, Is.Not.Null);
var selectList = listBox.SelectedItem;
@@ -146,7 +153,7 @@ public void ListBox8_keyBoardNavigateDown()
//test keyboard navigate with up arrow
[Test]
- public void ListBox9_keyBoardNavigateUp()
+ public void ListBox9_KeyBoardNavigateUp()
{
Assert.That(listBox, Is.Not.Null);
listBox.Select(2);
@@ -159,7 +166,7 @@ public void ListBox9_keyBoardNavigateUp()
//Test vertical scrolling for listBox with fixed length
[Test]
- public void ListBoxs1_verticalScroll()
+ public void ListBoxs1_VerticalScroll()
{
Assert.That(listBoxLength, Is.Not.Null);
double defaultScroll = 0;
@@ -169,17 +176,19 @@ public void ListBoxs1_verticalScroll()
}
[Test]
- public void ListBoxs2_closeWindows()
+ public void ListBoxs2_CloseWindows()
{
- Assert.That(listBoxWindow, Is.Not.Null);
- listBoxWindow.Close();
- Wait.UntilInputIsProcessed();
- Assert.That(window, Is.Not.Null);
- Wait.UntilInputIsProcessed();
- Assert.That(listBoxWindow.IsOffscreen, Is.True);
- window.Close();
- Assert.That(window.IsOffscreen, Is.True);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
-
}
}
diff --git a/Win11ThemeTest/RadioButtonTest.cs b/Win11ThemeTest/RadioButtonTest.cs
index a54116e..3567d23 100644
--- a/Win11ThemeTest/RadioButtonTest.cs
+++ b/Win11ThemeTest/RadioButtonTest.cs
@@ -7,97 +7,219 @@
using System.Windows.Input;
using System.Xml.Linq;
using System.Text;
+using System.Configuration;
namespace Win11ThemeTest
{
[TestFixture]
- public class rbTests
+ public class RadioButtonTests
{
- private Application app;
- private Window window;
- RadioButton radioButton1;
- RadioButton radioButton2;
- RadioButton radioButton3;
- RadioButton radioButton4;
- RadioButton radioButton5;
- RadioButton radioButton6;
-
- public rbTests()
+ private readonly Application? app;
+ private readonly Window? window;
+ public Button? testButton;
+ public Window? radioBtnWindow;
+ readonly RadioButton? optionA;
+ readonly RadioButton? optionB;
+ readonly RadioButton? optionC;
+ readonly RadioButton? optionD;
+
+ readonly RadioButton? radioButton1;
+ readonly RadioButton? radioButton2;
+ readonly RadioButton? radioButton3;
+ readonly RadioButton? radioButton4;
+ readonly RadioButton? radioButton5;
+ readonly RadioButton? radioButton6;
+
+ public RadioButtonTests()
+ {
+ var appPath = ConfigurationManager.AppSettings["Testpath"];
+ app = LaunchApplication(appPath);
+ using var automation = new UIA3Automation();
+ window = app?.GetMainWindow(automation);
+ testButton = window?.FindFirstDescendant(cf => cf.ByAutomationId("radioButton")).AsButton();
+ ClickButton(testButton);
+ radioBtnWindow = window?.FindFirstDescendant(cf => cf.ByName("RadioButtonWindow")).AsWindow();
+ optionA = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("Option A")).AsRadioButton();
+ optionB = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("Option B")).AsRadioButton();
+ optionC = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("Option C")).AsRadioButton();
+ optionD = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("Option D")).AsRadioButton();
+
+ radioButton1 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton1")).AsRadioButton();
+ radioButton2 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton2")).AsRadioButton();
+ radioButton3 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton3")).AsRadioButton();
+ radioButton4 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton4")).AsRadioButton();
+ radioButton5 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton5")).AsRadioButton();
+ radioButton6 = radioBtnWindow?.FindFirstDescendant(cf => cf.ByName("RadioButton6")).AsRadioButton();
+ }
+
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
+ }
+ catch (Exception ex)
+ {
+ LogException(ex);
+ throw;
+ }
+ }
+
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
{
- app = Application.Launch(@"..\\..\\..\\..\\Win11ThemeSampleApp\\bin\\x64\\Debug\\net9.0-windows\\win-x64\\Win11ThemeSampleApp.exe");
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
- using (var automation = new UIA3Automation())
+ if (!Directory.Exists(filePath))
{
- window = app.GetMainWindow(automation);
+ Directory.CreateDirectory(filePath);
}
- radioButton1 = window.FindFirstDescendant(cf => cf.ByName("RadioButton1")).AsRadioButton();
- radioButton2 = window.FindFirstDescendant(cf => cf.ByName("RadioButton2")).AsRadioButton();
- radioButton3 = window.FindFirstDescendant(cf => cf.ByName("RadioButton3")).AsRadioButton();
- radioButton4 = window.FindFirstDescendant(cf => cf.ByName("RadioButton4")).AsRadioButton();
- radioButton5 = window.FindFirstDescendant(cf => cf.ByName("RadioButton5")).AsRadioButton();
- radioButton6 = window.FindFirstDescendant(cf => cf.ByName("RadioButton6")).AsRadioButton();
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
}
[Test]
- public void RadioButtonTest_1()
+ public void RadioButton1_IsUncheck()
{
- // Checking if a radio button in both the groups are clickable
- Assert.That(radioButton1.IsChecked, Is.False);
- Assert.That(radioButton2.IsChecked, Is.False);
- Assert.That(radioButton3.IsChecked, Is.False);
- Assert.That(radioButton4.IsChecked, Is.False);
- Assert.That(radioButton5.IsChecked, Is.False);
- Assert.That(radioButton6.IsChecked, Is.False);
+ Assert.That(optionA, Is.Not.Null);
+ Assert.That(optionA.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionB, Is.Not.Null);
+ Assert.That(optionB.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionC, Is.Not.Null);
+ Assert.That(optionC.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionD, Is.Not.Null);
+ Assert.That(optionD.IsChecked, Is.False);
+ }
- Mouse.Click(radioButton1.GetClickablePoint());
- Mouse.Click(radioButton5.GetClickablePoint());
+ //Validate that clicking on the label associated with a radio button selects the button.
+ [Test]
+ public void RadioButton2_LabelCheck()
+ {
+ Assert.That(optionA, Is.Not.Null);
+ Mouse.Click(optionA.GetClickablePoint());
+ Assert.That(optionA.IsChecked, Is.True);
+ }
- Assert.That(radioButton1.IsChecked, Is.True);
- Assert.That(radioButton2.IsChecked, Is.False);
- Assert.That(radioButton3.IsChecked, Is.False);
- Assert.That(radioButton4.IsChecked, Is.False);
- Assert.That(radioButton5.IsChecked, Is.True);
- Assert.That(radioButton6.IsChecked, Is.False);
+ // Re-checking on a checked radio button does not affect it's checked state
+ [Test]
+ public void RadioButton3_state()
+ {
+ Assert.That(optionA, Is.Not.Null);
+ Assert.That(optionA.IsChecked, Is.True);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionB, Is.Not.Null);
+ Assert.That(optionB.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionC, Is.Not.Null);
+ Assert.That(optionC.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionD, Is.Not.Null);
+ Assert.That(optionD.IsChecked, Is.False);
+
+ optionD.Click();
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(optionA.IsChecked, Is.False);
+ Assert.That(optionB.IsChecked, Is.False);
+ Assert.That(optionC.IsChecked, Is.False);
+ Assert.That(optionD.IsChecked, Is.True);
+ });
}
+ //Verify that only one radio button can be selected at a time.
+ //Confirm that selecting one radio button deselects any previously selected option.
[Test]
- public void RadioButtonTest_2()
+ public void RadioButton4_selection()
{
- // Re-checking on a checked radio button does not affect it's checked state
- Assert.That(radioButton1.IsChecked, Is.True);
- Assert.That(radioButton5.IsChecked, Is.True);
+ Assert.That(optionA, Is.Not.Null);
+ Mouse.Click(optionA.GetClickablePoint());
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionA.IsChecked, Is.True);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionB, Is.Not.Null);
+ Assert.That(optionB.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionC, Is.Not.Null);
+ Assert.That(optionC.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(optionD, Is.Not.Null);
+ Assert.That(optionD.IsChecked, Is.False);
- Mouse.Click(radioButton1.GetClickablePoint());
- Mouse.Click(radioButton5.GetClickablePoint());
-
- Assert.That(radioButton1.IsChecked, Is.True);
- Assert.That(radioButton5.IsChecked, Is.True);
+ //select option B and make sure option A gets deselected
+ Mouse.Click(optionB.GetClickablePoint());
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(optionA.IsChecked, Is.False);
+ Assert.That(optionB.IsChecked, Is.True);
+ Assert.That(optionC.IsChecked, Is.False);
+ Assert.That(optionD.IsChecked, Is.False);
+ });
}
+ // Checking if a radio button in both the groups are clickable
[Test]
- public void RadioButtonTest_3()
+ public void RadioButton5_groupCheck()
{
- // Checking a different radio button
- Assert.That(radioButton1.IsChecked, Is.True);
+ Assert.That(radioButton1, Is.Not.Null);
+ Assert.That(radioButton1.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton2, Is.Not.Null);
Assert.That(radioButton2.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton3, Is.Not.Null);
Assert.That(radioButton3.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton4, Is.Not.Null);
+ Assert.That(radioButton4.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton5, Is.Not.Null);
+ Assert.That(radioButton5.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton6, Is.Not.Null);
+ Assert.That(radioButton6.IsChecked, Is.False);
- Mouse.Click(radioButton2.GetClickablePoint());
- Assert.That(radioButton1.IsChecked, Is.False);
- Assert.That(radioButton2.IsChecked, Is.True);
- Assert.That(radioButton3.IsChecked, Is.False);
+ radioButton1.Click();
+ radioButton5.Click();
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(radioButton1.IsChecked, Is.True);
+ Assert.That(radioButton2.IsChecked, Is.False);
+ Assert.That(radioButton3.IsChecked, Is.False);
+ Assert.That(radioButton4.IsChecked, Is.False);
+ Assert.That(radioButton5.IsChecked, Is.True);
+ Assert.That(radioButton6.IsChecked, Is.False);
+ });
}
+ // Checking or Selecting a disabled radio button
[Test]
- public void RadioButtonTest_4()
+ public void RadioButtonTest6_KeyboardSelect()
{
- // Checking or Selecting a disabled radio button
+ Assert.That(radioButton3, Is.Not.Null);
Assert.That(radioButton3.IsChecked, Is.False);
Mouse.Click(radioButton3.GetClickablePoint());
Assert.That(radioButton3.IsChecked, Is.False);
-
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton1, Is.Not.Null);
radioButton1.Focus();
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.TAB);
@@ -105,58 +227,115 @@ public void RadioButtonTest_4()
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.TAB);
Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.TAB);
+ // Get the current mouse position
+ //var mousePosition = Mouse.Position;
+
+ // Output the mouse position
+ // Console.WriteLine($"Mouse Position: X = {mousePosition.X}, Y = {mousePosition.Y}");
+
+ // Get the element at the mouse position
+ using var automation2 = new UIA3Automation();
+
+ //var automation = new FlaUI.UIA3.Core.AutomationElement.Automation();
+ //var element = automation2.FromPoint(mousePosition);
+ var element = automation2.FocusedElement();
+ // Check if an element is found at the mouse position
+ if (element != null)
+ {
+ // Get the element's name (or any other property) to identify the focused element
+ var elementName = element.Name;
+
+ // Output the focused element's name
+ Console.WriteLine($"Focused Element: {elementName}");
+ Assert.That(radioButton4, Is.Not.Null);
+ Assert.That(radioButton4.Name, Is.EqualTo(elementName));
- /**
- *
- *
- * TODO: Implement Focus Testing
- * Verify that the currently focused radiobutton is not radiobutton3
- *
- */
-
+ }
}
+ // Test to confirm click in one group does not affect checked radio button in another group
[Test]
- public void RadioButtonTest_5()
+ public void RadioButtonTest7_ClickGroupButton()
{
- // Test to confirm click in one group does not affect checked radio button in another group
+ //Group 1 radio button
+ Assert.That(radioButton2, Is.Not.Null);
+ radioButton2.Click();
Assert.That(radioButton2.IsChecked, Is.True);
- Mouse.Click(radioButton4.GetClickablePoint());
- Mouse.Click(radioButton5.GetClickablePoint());
- Mouse.Click(radioButton6.GetClickablePoint());
+ //Group 2 radio button
+ Assert.That(radioButton5, Is.Not.Null);
+ radioButton5.Click();
+ Assert.That(radioButton5.IsChecked, Is.True);
+ Assert.That(radioButton1, Is.Not.Null);
+ Assert.That(radioButton1.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
Assert.That(radioButton2.IsChecked, Is.True);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton3, Is.Not.Null);
+ Assert.That(radioButton3.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton4, Is.Not.Null);
+ Assert.That(radioButton4.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton5.IsChecked, Is.True);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton6, Is.Not.Null);
+ Assert.That(radioButton6.IsChecked, Is.False);
+
}
+ // Test to confirm radio buttons can be checked using space bar
[Test]
- public void RadioButtonTest_6()
+ public void RadioButtonTest8_SelectWithSapceKey()
{
- // Test to confirm radio buttons can be checked using space bar
- Assert.That(radioButton1.IsChecked, Is.False);
- Assert.That(radioButton2.IsChecked, Is.True);
-
+ Assert.That(radioButton2, Is.Not.Null);
+ radioButton2.Click();
+ Assert.That(radioButton1, Is.Not.Null);
+ Assert.Multiple(() =>
+ {
+ Assert.That(radioButton1.IsChecked, Is.False);
+ Assert.That(radioButton2.IsChecked, Is.True);
+ });
radioButton2.Focus();
Keyboard.TypeSimultaneously(FlaUI.Core.WindowsAPI.VirtualKeyShort.SHIFT, FlaUI.Core.WindowsAPI.VirtualKeyShort.TAB);
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.SPACE);
Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.SPACE);
-
- Assert.That(radioButton1.IsChecked, Is.True);
- Assert.That(radioButton2.IsChecked, Is.False);
+ Wait.UntilInputIsProcessed();
+ Assert.Multiple(() =>
+ {
+ Assert.That(radioButton1.IsChecked, Is.True);
+ Assert.That(radioButton2.IsChecked, Is.False);
+ });
}
+ // Test to confirm correct initialization from code behind
[Test]
- public void RadioButtonTest_7()
+ public void RadioButtonTest9_testInitialization()
{
- // Test to confirm correct initialization from code behind
+ Assert.That(radioButton4, Is.Not.Null);
Assert.That(radioButton4.IsEnabled, Is.True);
+ Wait.UntilInputIsProcessed();
+ Assert.That(radioButton5, Is.Not.Null);
Assert.That(radioButton5.IsEnabled, Is.True);
- Assert.That(radioButton6.IsEnabled, Is.False);
+ }
- // Close the window
- window.Close();
+ [Test]
+ public void RadioButtonTest91_cleanUp()
+ {
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
}
}
diff --git a/Win11ThemeTest/SliderTest.cs b/Win11ThemeTest/SliderTest.cs
new file mode 100644
index 0000000..6142203
--- /dev/null
+++ b/Win11ThemeTest/SliderTest.cs
@@ -0,0 +1,161 @@
+using FlaUI.Core;
+using FlaUI.Core.AutomationElements;
+using FlaUI.Core.Input;
+using FlaUI.Core.WindowsAPI;
+using FlaUI.UIA3;
+using NUnit.Framework.Internal;
+using System.Configuration;
+
+namespace Win11ThemeTest
+{
+ public class SliderTest
+ {
+ private readonly Application? app;
+ private readonly Window? window;
+ public Window? sliderWindow;
+ readonly Button? testSlider;
+ readonly Slider? slider;
+
+ public SliderTest()
+ {
+ var appPath = ConfigurationManager.AppSettings["Testpath"];
+ app = LaunchApplication(appPath);
+ using var automation = new UIA3Automation();
+ window = app?.GetMainWindow(automation);
+ testSlider = window?.FindFirstDescendant(cf => cf.ByAutomationId("sliderButton")).AsButton();
+ ClickButton(testSlider);
+ sliderWindow = window?.FindFirstDescendant(cf => cf.ByName("SliderWindow")).AsWindow();
+ slider = sliderWindow?.FindFirstDescendant(cf => cf.ByAutomationId("slider")).AsSlider();
+ }
+ private static Application? LaunchApplication(string? appPath)
+ {
+ try
+ {
+ return Application.Launch(appPath);
+ }
+ catch (Exception ex)
+ {
+ LogException(ex);
+ throw;
+ }
+ }
+
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
+ }
+
+ //test if slider is available
+ [Test]
+ public void Slider1_IsSliderAvailable()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(sliderWindow, Is.Not.Null);
+ Assert.That(slider, Is.Not.Null);
+ });
+ }
+
+ [Test]
+ public void Slider2_MinMaxOfSlider()
+ {
+ Assert.That(slider, Is.Not.Null);
+ Assert.That(slider.Minimum, Is.EqualTo(0));
+ Wait.UntilInputIsProcessed();
+ Assert.That(slider.Maximum, Is.EqualTo(10));
+ }
+
+ [Test]
+ public void Slider3_LargeIncrement()
+ {
+ Assert.That(slider, Is.Not.Null);
+ slider.LargeIncrement();
+ Wait.UntilInputIsProcessed();
+ Assert.That(slider.Value, Is.Not.EqualTo(0));
+ slider.Value = 0;
+ }
+
+ [Test]
+ public void Slider4_ThumbSlide()
+ {
+ Assert.That(slider, Is.Not.Null);
+ var thumb = slider.Thumb;
+ thumb.SlideHorizontally(50);
+ Wait.UntilInputIsProcessed();
+ Assert.That(slider.Value, Is.EqualTo(5));
+ slider.Value = 0;
+ }
+
+ [Test]
+ public void Slider5_LargeDecrement()
+ {
+ Assert.That(slider, Is.Not.Null);
+ slider.LargeIncrement();
+ Assert.That(slider.Value, Is.Not.EqualTo(0));
+ slider.LargeDecrement();
+ Assert.That(slider.Value, Is.EqualTo(0));
+ }
+
+ [Test]
+ public void Slider6_SmallDecrement()
+ {
+ Assert.That(slider, Is.Not.Null);
+ var btn = slider.FindFirstChild(cf => cf.ByAutomationId("IncreaseLarge")).AsButton();
+ btn.Click();
+ var increasedValue = slider.Value;
+ var smallChangeValue = slider.SmallChange;
+ Keyboard.Press(VirtualKeyShort.LEFT);
+ Wait.UntilInputIsProcessed();
+ Assert.That(slider.Value, Is.EqualTo(increasedValue - smallChangeValue));
+ }
+
+ [Test]
+ public void Slider7_SmallIncrement()
+ {
+ Assert.That(slider, Is.Not.Null);
+ var btn = slider.FindFirstChild(cf => cf.ByAutomationId("IncreaseLarge")).AsButton();
+ btn.Click();
+ var increasedValue = slider.Value;
+ var smallChangeValue = slider.SmallChange;
+ Keyboard.Press(VirtualKeyShort.RIGHT);
+ Wait.UntilInputIsProcessed();
+ Assert.That(slider.Value, Is.EqualTo(increasedValue + smallChangeValue));
+ }
+
+ [Test]
+ public void Slider8_CloseWindows()
+ {
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
+ }
+ }
+}
diff --git a/Win11ThemeTest/TextBoxTest.cs b/Win11ThemeTest/TextBoxTest.cs
index 1da790d..8547a4b 100644
--- a/Win11ThemeTest/TextBoxTest.cs
+++ b/Win11ThemeTest/TextBoxTest.cs
@@ -9,88 +9,95 @@
namespace Win11ThemeTest
{
[TestFixture]
- public class textBoxTests
+ public class TextBoxTests
{
- private Application? app;
- private Window? mainWindow;
+ private readonly Application? app;
+ private readonly Window? mainWindow;
public Window? textWindow;
- TextBox? textBox;
- TextBox? disabledTextBox;
- TextBox? multiLineTextBox;
- Button? txtButton;
- UIA3Automation automation = new UIA3Automation();
-
- public textBoxTests()
+ readonly TextBox? textBox;
+ readonly TextBox? disabledTextBox;
+ readonly TextBox? multiLineTextBox;
+ readonly Button? txtButton;
+ readonly UIA3Automation automation = new();
+
+ public TextBoxTests()
+ {
+ var appPath = ConfigurationManager.AppSettings["Testpath"];
+ app = LaunchApplication(appPath);
+ mainWindow = app?.GetMainWindow(automation);
+ txtButton = mainWindow?.FindFirstDescendant(cf => cf.ByAutomationId("txtBoxButton")).AsButton();
+ ClickButton(txtButton);
+ textWindow = mainWindow?.FindFirstDescendant(cf => cf.ByName("TextWindow")).AsWindow();
+ textBox = textWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt")).AsTextBox();
+ disabledTextBox = textWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt_disabled")).AsTextBox();
+ multiLineTextBox = textWindow?.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt_multiline")).AsTextBox();
+ }
+ private static Application? LaunchApplication(string? appPath)
{
try
{
- var appPath = ConfigurationManager.AppSettings["Testpath"];
- app = Application.Launch(appPath);
- mainWindow = app.GetMainWindow(automation);
- txtButton = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("txtBoxButton")).AsButton();
- Mouse.Click(txtButton.GetClickablePoint());
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
- textWindow = mainWindow.FindFirstDescendant(cf => cf.ByName("TextWindow")).AsWindow();
- textBox = textWindow.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt")).AsTextBox();
- disabledTextBox = textWindow.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt_disabled")).AsTextBox();
- multiLineTextBox = textWindow.FindFirstDescendant(cf => cf.ByAutomationId("tbTxt_multiline")).AsTextBox();
+ return Application.Launch(appPath);
}
catch (Exception ex)
{
- var filePath = ConfigurationManager.AppSettings["logpath"];
- if (filePath != null)
- {
- if (!Directory.Exists(filePath))
- {
- Directory.CreateDirectory(filePath);
- }
- filePath = filePath + "log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; //Text File Name
- if (!File.Exists(filePath))
- {
- File.Create(filePath).Dispose();
- }
- using (StreamWriter sw = File.AppendText(filePath))
- {
- string error = "Log Written Date:" + " " + DateTime.Now.ToString() + "\nError Message:" + " " + ex.Message.ToString();
- sw.WriteLine("-----------Exception Details on " + " " + DateTime.Now.ToString() + "-----------------");
- sw.WriteLine("-------------------------------------------------------------------------------------");
- sw.WriteLine(error);
- sw.Flush();
- sw.Close();
- }
- }
- else
- {
- throw new ArgumentNullException();
- }
- }
+ LogException(ex);
+ throw;
+ }
+ }
+
+ private static void ClickButton(Button? button)
+ {
+ if (button == null) throw new ArgumentNullException(nameof(button));
+
+ Mouse.Click(button.GetClickablePoint());
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ }
+
+ private static void LogException(Exception ex)
+ {
+ var filePath = ConfigurationManager.AppSettings["logpath"];
+ if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath));
+
+ if (!Directory.Exists(filePath))
+ {
+ Directory.CreateDirectory(filePath);
+ }
+
+ var logFilePath = Path.Combine(filePath, $"log_{DateTime.Now:yyyyMMddHHmmss}.txt");
+ using StreamWriter sw = new(logFilePath, append: true);
+ sw.WriteLine("-----------Exception Details on " + DateTime.Now + "-----------------");
+ sw.WriteLine("-------------------------------------------------------------------------------------");
+ sw.WriteLine($"Log Written Date: {DateTime.Now}\nError Message: {ex.Message}");
}
[Test]
- public void textbox_findTextBox()
+ public void Textbox_FindTextBox()
{
- Assert.IsNotNull(textWindow);
- Assert.IsNotNull(textBox);
+ Assert.Multiple(() =>
+ {
+ Assert.That(textWindow, Is.Not.Null);
+ Assert.That(textBox, Is.Not.Null);
+ });
}
#region FunctionalTests
[Test]
- public void textBox_enterText()
+ public void TextBox_EnterText()
{
- Assert.IsNotNull(textBox);
- textBox.Enter("Hello World!");
+ Assert.That(textBox, Is.Not.Null);
+ textBox.Enter("Hello World!");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
Assert.That(textBox.Text, Is.EqualTo("Hello World!"));
- }
+ }
//Verify that the text box accepts alphanumeric characters.
[Test]
- public void textBox_enterAlphaNumericText()
+ public void TextBox_EnterAlphaNumericText()
{
var expectedText = "/\\d.*[a-zA-Z]|[a-zA-Z].*\\d/";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("/\\d.*[a-zA-Z]|[a-zA-Z].*\\d/");
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
if (textBox.Text != expectedText)
{
Assert.Fail("Result : {0} and Expected {1} ", textBox.Text, expectedText);
@@ -103,12 +110,12 @@ public void textBox_enterAlphaNumericText()
//Verify that the text box accepts special characters.
[Test]
- public void textBox_enterSpecialCharText()
+ public void TextBox_EnterSpecialCharText()
{
var expectedText = "@#$%^&*";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("@#$%^&*");
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
if (textBox.Text != "@#$%^&*")
{
Assert.Fail("Result : {0} and Expected {1} ", textBox.Text, expectedText);
@@ -121,12 +128,12 @@ public void textBox_enterSpecialCharText()
//Check if the text box can handle empty input.
[Test]
- public void textBox_enterEmptyText()
+ public void TextBox_EnterEmptyText()
{
var emptyText = string.Empty;
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter(emptyText);
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
if (textBox.Text != string.Empty)
{
Assert.Fail("Result : {0} and Expected {1} ", textBox.Text, string.Empty);
@@ -135,16 +142,16 @@ public void textBox_enterEmptyText()
{
Assert.Pass("Result : {0} and Expected {1} ", textBox.Text, string.Empty);
}
- }
+ }
//Test input validation for correct data formats (e.g., email validation).
[Test]
- public void textBox_enterEmailIdText()
+ public void TextBox_EnterEmailIdText()
{
var expectedText = "ram.shyam1234@yahoo.com";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("ram.shyam1234@yahoo.com");
- Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
+ Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
if (textBox.Text != expectedText)
{
Assert.Fail("Result : {0} and Expected {1} ", textBox.Text, expectedText);
@@ -156,23 +163,23 @@ public void textBox_enterEmailIdText()
}
[Test]
- public void textBox_multiLineTextbox()
+ public void TextBox_MultiLineTextbox()
{
- string testDescription = "New line text.\n Line1\nLine2 \nLine3";
- Assert.IsNotNull(multiLineTextBox);
- multiLineTextBox.Enter(testDescription);
+ string testDescription = "New line text.\nLine1\nLine2 \nLine3";
+ Assert.That(multiLineTextBox, Is.Not.Null);
+ multiLineTextBox.Text = testDescription;
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(800));
- string expectedText = "New line text. Line1Line2 Line3";
+ string expectedText = "New line text." + "\n" + "Line1" + "\n" + "Line2 " + "\n" + "Line3";
// Get text from the textbox and verify
Assert.That(expectedText, Is.EqualTo(multiLineTextBox.Text));
}
//Test the undo and redo functionality within the text box.
[Test]
- public void textBox1_UndoText()
+ public void TextBox1_UndoText()
{
var expectedText = "";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("This is a textbox. Trying to perform Functionality test for Undo");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL);
@@ -191,10 +198,10 @@ public void textBox1_UndoText()
}
[Test]
- public void textBox12_RedoText()
- {
+ public void TextBox12_RedoText()
+ {
var expectedText = "This is a textbox. Trying to perform Redo";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("This is a textbox. Trying to perform Redo");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
//Undo
@@ -221,9 +228,9 @@ public void textBox12_RedoText()
//Verify that users can copy and paste text from and to the text box.
[Test]
- public void textBox2_rightClickTestCut()
+ public void TextBox2_RightClickTestCut()
{
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("Hello World!Hello World!Hello World!Hello World!Hello World!Hell World!Hello World!Hello World!Hello World!");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL);
@@ -233,52 +240,52 @@ public void textBox2_rightClickTestCut()
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
textBox.RightClick();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(1000));
- Assert.IsNotNull(textWindow);
+ Assert.That(textWindow, Is.Not.Null);
var cutText = textWindow.FindFirstDescendant(cf => cf.ByName("Cut")).AsMenuItem();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
- Assert.IsNotNull(cutText);
- Assert.IsTrue(cutText.IsEnabled);
+ Assert.That(cutText, Is.Not.Null);
+ Assert.That(cutText.IsEnabled, Is.True);
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
cutText.Click();
- Wait.UntilInputIsProcessed();
+ Wait.UntilInputIsProcessed();
}
[Test]
- public void textBox21_rightClickTestCopy()
+ public void TextBox21_RightClickTestCopy()
{
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("Hello World!Hello World!Hello World!Hello World!Hello World!Hell World!Hello World!Hello World!Hello World!");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL);
- Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.KEY_A);
+ Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.KEY_A);
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(1000));
Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.KEY_A);
- Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL);
+ Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL);
textBox.RightClick();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(1000));
- Assert.IsNotNull(textWindow);
+ Assert.That(textWindow, Is.Not.Null);
var pasteText = textWindow.FindFirstDescendant(cf => cf.ByName("Copy")).AsMenuItem();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(1000));
pasteText.GetClickablePoint();
- Assert.IsNotNull(pasteText);
+ Assert.That(pasteText, Is.Not.Null);
pasteText.Click();
- Wait.UntilInputIsProcessed();
+ Wait.UntilInputIsProcessed();
}
[Test]
- public void textBox212_rightClickTest_Paste()
+ public void TextBox212_RightClickTest_Paste()
{
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("Hello World!Hello World!Hello World!Hello World!Hello World!Hell World!Hello World!Hello World!Hello World!");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
textBox.RightClick();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(1000));
- Assert.IsNotNull(textWindow);
+ Assert.That(textWindow, Is.Not.Null);
var pasteText = textWindow.FindFirstDescendant(cf => cf.ByName("Paste")).AsMenuItem();
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
- Assert.IsNotNull(pasteText);
+ Assert.That(pasteText, Is.Not.Null);
pasteText.Click();
- }
+ }
#endregion
@@ -286,68 +293,73 @@ public void textBox212_rightClickTest_Paste()
/* Negative Test Scenarios */
//Attempt to enter code snippets or HTML code into the input box to see if the same is rejected.
[Test]
- public void textBox3_htmlTextBox()
+ public void TextBox3_HtmlTextBox()
{
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Text = string.Empty;
textBox.Enter("");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(800));
Assert.That(textBox.Text, Is.EqualTo(""));
- }
+ }
/* Test Cases For Disabled TextBox
*/
[Test]
- public void textBox3_disabledTextBoxAvailability()
+ public void TextBox3_DisabledTextBoxAvailability()
{
- Assert.IsNotNull(textWindow);
- Assert.IsNotNull(disabledTextBox);
+ Assert.Multiple(() =>
+ {
+ Assert.That(textWindow, Is.Not.Null);
+ Assert.That(disabledTextBox, Is.Not.Null);
+ });
}
//Check if any pre-populated value should be displayed as per requirement.
[Test]
- public void textBox3_disabledTextBox()
+ public void TextBox3_DisabledTextBox()
{
- Assert.IsNotNull(textWindow);
- Assert.IsNotNull(disabledTextBox);
+ Assert.That(textWindow, Is.Not.Null);
+ Wait.UntilInputIsProcessed();
+ Assert.That(disabledTextBox, Is.Not.Null);
Assert.That(disabledTextBox.Text, Is.EqualTo("TextBox Disabled"));
}
//Check if you cannot edit disabled TextBox.
[Test]
- public void textBox_disabledEditTextBox()
+ public void TextBox_DisabledEditTextBox()
{
- Assert.IsNotNull(textWindow);
- Assert.IsNotNull(disabledTextBox);
- Assert.That(disabledTextBox.IsEnabled, Is.False);
+ Assert.That(textWindow, Is.Not.Null);
+ Wait.UntilInputIsProcessed();
+ Assert.That(disabledTextBox, Is.Not.Null);
+ Assert.That(disabledTextBox.IsEnabled, Is.False);
}
#endregion
#region UITests
[Test]
- public void textBox_clickOnTextbox()
+ public void TextBox_ClickOnTextbox()
{
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
Mouse.Click(textBox.GetClickablePoint());
Assert.That(textBox.IsEnabled, Is.True);
- }
+ }
[Test]
- public void textBox_fontFamily()
+ public void TextBox_FontFamily()
{
string expected_FontFamily = "Segoe UI";
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("Hello World!");
var colorRange = textBox.Patterns.Text.Pattern;
var textFont = (string)colorRange.DocumentRange.GetAttributeValue(automation.TextAttributeLibrary.FontName);
Assert.That(textFont, Is.EqualTo(expected_FontFamily));
}
-
+
[Test]
- public void textBox_textForegroundColor()
+ public void TextBox_TextForegroundColor()
{
// var automation = new UIA3Automation();
- Assert.IsNotNull(textBox);
+ Assert.That(textBox, Is.Not.Null);
textBox.Enter("Hello World!");
Wait.UntilInputIsProcessed(TimeSpan.FromMilliseconds(500));
var expectedColor = ColorTranslator.FromHtml("#E4000000");
@@ -356,9 +368,9 @@ public void textBox_textForegroundColor()
var actualColor = Color.FromArgb(foreColorInt);
Console.WriteLine("actualColor........{0}", actualColor);
AssertColorEquality(actualColor, Color.FromArgb(0, expectedColor));
- }
+ }
- private void AssertColorEquality(Color actual, Color expected)
+ private static void AssertColorEquality(Color actual, Color expected)
{
if (actual.ToArgb() != expected.ToArgb())
{
@@ -376,15 +388,19 @@ private void AssertColorEquality(Color actual, Color expected)
#endregion
[Test]
- public void textBox4_Cleanup()
+ public void TextBox4_Cleanup()
{
- Assert.IsNotNull(textWindow);
- textWindow.Close();
- Wait.UntilInputIsProcessed();
- Assert.IsTrue(textWindow.IsOffscreen);
- Assert.IsNotNull(mainWindow);
- mainWindow.Close();
- Assert.IsTrue(mainWindow.IsOffscreen);
+ if (app != null)
+ {
+ app.Close();
+ Assert.That(app.Close(), Is.True);
+ Console.WriteLine("Application closed successfully.");
+ }
+ else
+ {
+ Console.WriteLine("Application not found.");
+ Assert.Fail("Application not found.");
+ }
}
}
}