Skip to content

Commit

Permalink
Listbox tests (#13)
Browse files Browse the repository at this point in the history
* Listbox tests

* Added window close methods

* PR review comments update

* Rename variables

* Revert "Rename variables"

This reverts commit a22d961.

* Fix for PR comments

* Update source path in app.xaml

* Fix for PR comments
  • Loading branch information
vidya-mb authored May 8, 2024
1 parent 54cd23f commit c896e94
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 214 deletions.
1 change: 1 addition & 0 deletions TestingApplication/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/Fluent.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>

25 changes: 25 additions & 0 deletions TestingApplication/ListboxWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Window x:Class="TestingApplication.ListboxWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestingApplication"
mc:Ignorable="d"
Title="ListboxWindow" Height="450" Width="800">
<Grid Margin="10,10,0,0">
<ListBox Margin="68,45,463,177" Name="tstLstbox" SelectedIndex="0">
<ListBoxItem>Blue</ListBoxItem>
<ListBoxItem>Green</ListBoxItem>
<ListBoxItem>Red</ListBoxItem>
<ListBoxItem>Yellow</ListBoxItem>
</ListBox>
<ListBox Margin="395,98,83,162" Height="164" Name="tstlengthLstbox" SelectedIndex="2">
<ListBoxItem Content="Arial"/>
<ListBoxItem Content="Comic Sans MS"/>
<ListBoxItem Content="Courier New"/>
<ListBoxItem Content="Segoe UI"/>
<ListBoxItem Content="Times New Roman"/>
</ListBox>

</Grid>
</Window>
28 changes: 28 additions & 0 deletions TestingApplication/ListboxWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
{
/// <summary>
/// Interaction logic for ListboxWindow.xaml
/// </summary>
public partial class ListboxWindow : Window
{
public ListboxWindow()
{
InitializeComponent();
}

}
}
1 change: 1 addition & 0 deletions TestingApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Button Name="txtBoxButton" Content="TextBox Button" Width="129" Click="textBoxButton_Click" />
<Button Name="cmbBoxButton" Content="Combo Button" Width="200" Click="comboBoxButton_Click" />
<Button Name="testchkbtn" Content="Test Checkbox" Click="checkboxButton_Click"/>
<Button Name="listBoxtestbtn" Content="Test Listbox" RenderTransformOrigin="1.562,1.132" Width="104" Click="listboxButton_Click"/>
</StackPanel>
</Grid>
</Window>
9 changes: 9 additions & 0 deletions TestingApplication/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@ private void checkboxButton_Click(object sender, RoutedEventArgs e)
checkboxWindow.Owner = this;
checkboxWindow.Show();
}

private void listboxButton_Click(object sender, RoutedEventArgs e)
{
ListboxWindow lstbxwindow = new ListboxWindow();
lstbxwindow.Owner = this;
//Added for fixing blank window issue
Application.Current.MainWindow = lstbxwindow;
lstbxwindow.Show();
}
}
}
97 changes: 49 additions & 48 deletions Win11ThemeTest/ButtonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ namespace Win11ThemeTest
{
public class ButtonTest
{
private Application? app;
private Window? window;
private readonly Application? app;
private readonly Window? window;
public Window? btnWindow;
Button? testButton;
Button? button;
Button? disabledButton;
readonly Button? testButton;
readonly Button? button;
readonly Button? disabledButton;

public ButtonTest()
{
try
{
var appPath = ConfigurationManager.AppSettings["Testpath"];
app = Application.Launch(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();
}
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();
}
catch (Exception ex)
{
Expand All @@ -47,15 +45,13 @@ public ButtonTest()
{
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();
}
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
{
Expand All @@ -67,20 +63,24 @@ public ButtonTest()

//test if button is available in window
[Test]
public void button1_isButtonAvailable()
public void Button1_isButtonAvailable()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(button);
Assert.Multiple(() =>
{
Assert.That(btnWindow, Is.Not.Null);

Assert.That(button, Is.Not.Null);
});
}

//test if button is clicked
[Test]
public void button2_isClicked()
public void Button2_isClicked()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(button);
Assert.That(button, Is.Not.Null);
button.Click();
Wait.UntilInputIsProcessed();
Assert.That(btnWindow, Is.Not.Null);
var popup = btnWindow.FindFirstDescendant(cf => cf.ByName("Button Clicked")).AsWindow();
Assert.That(popup, Is.Not.Null);
Button pBtn = btnWindow.FindFirstDescendant(cf => cf.ByName("OK")).AsButton();
Expand All @@ -89,13 +89,13 @@ public void button2_isClicked()

//test if button clicked with enter key
[Test]
public void button3_isClickableWithEnterKey()
public void Button3_isClickableWithEnterKey()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(button);
Assert.That(button, Is.Not.Null);
button.Focus();
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.ENTER);
Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.ENTER);
Assert.That(btnWindow, Is.Not.Null);
var popup = btnWindow.FindFirstDescendant(cf => cf.ByName("Button Clicked")).AsWindow();
Assert.That(popup, Is.Not.Null);
Button pBtn = btnWindow.FindFirstDescendant(cf => cf.ByName("OK")).AsButton();
Expand All @@ -104,14 +104,14 @@ public void button3_isClickableWithEnterKey()

//test if button clicked with space key
[Test]
public void button4_isClickableWithSpaceKey()
public void Button4_isClickableWithSpaceKey()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(button);
Assert.That(button, Is.Not.Null);
button.Focus();
Keyboard.Press(FlaUI.Core.WindowsAPI.VirtualKeyShort.SPACE);
Keyboard.Release(FlaUI.Core.WindowsAPI.VirtualKeyShort.SPACE);
Wait.UntilInputIsProcessed();
Assert.That(btnWindow, Is.Not.Null);
var popup = btnWindow.FindFirstDescendant(cf => cf.ByName("Button Clicked")).AsWindow();
Assert.That(popup, Is.Not.Null);
Button pBtn = btnWindow.FindFirstDescendant(cf => cf.ByName("OK")).AsButton();
Expand All @@ -120,28 +120,28 @@ public void button4_isClickableWithSpaceKey()

//test no action on mouse right click on button
[Test]
public void button5_onMouseRightClick()
public void Button5_onMouseRightClick()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(button);
Assert.That(button, Is.Not.Null);
button.RightClick();
Assert.That(btnWindow, Is.Not.Null);
var popup = btnWindow.FindFirstDescendant(cf => cf.ByName("Button Clicked")).AsWindow();
Assert.That(popup, Is.Null);
}

//Test disabled button
[Test]
public void button6_isDisabled()
public void Button6_isDisabled()
{
Assert.IsNotNull(disabledButton);
Assert.That(disabledButton, Is.Not.Null);
Assert.That(disabledButton.IsEnabled, Is.False);
}

//Test disabled button
[Test]
public void button7_isDisabledClick()
public void Button7_isDisabledClick()
{
Assert.IsNotNull(disabledButton);
Assert.That(disabledButton, Is.Not.Null);
Assert.That(disabledButton.IsEnabled, Is.False);
disabledButton.Click();
var popup = disabledButton.FindFirstDescendant(cf => cf.ByName("Button Clicked")).AsWindow();
Expand All @@ -150,15 +150,16 @@ public void button7_isDisabledClick()

//close windows
[Test]
public void button8_closeWindows()
public void Button8_closeWindows()
{
Assert.IsNotNull(btnWindow);
Assert.IsNotNull(window);
Assert.That(btnWindow, Is.Not.Null);
btnWindow.Close();
Wait.UntilInputIsProcessed();
Assert.IsTrue(btnWindow.IsOffscreen);
Assert.That(btnWindow.IsOffscreen);
Wait.UntilInputIsProcessed();
Assert.That(window, Is.Not.Null);
window.Close();
Assert.IsTrue(window.IsOffscreen);
Assert.That(window.IsOffscreen);
}

}
Expand Down
Loading

0 comments on commit c896e94

Please sign in to comment.