From 118ad8056dfe879a02745414fb9bf879698961a0 Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Sat, 30 Nov 2024 15:38:06 +0100 Subject: [PATCH] UITest/BookLib: adapt order of items --- .../BookLibrary.Test/Tests/AddressBookTest.cs | 8 ++-- .../BookLibrary.Test/Tests/BookLibraryTest.cs | 47 +++++++++---------- .../BookLibrary.Test/Views/PersonListView.cs | 2 + 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Samples.UITest/BookLibrary.Test/Tests/AddressBookTest.cs b/src/Samples.UITest/BookLibrary.Test/Tests/AddressBookTest.cs index 6a4779d8..5232198a 100644 --- a/src/Samples.UITest/BookLibrary.Test/Tests/AddressBookTest.cs +++ b/src/Samples.UITest/BookLibrary.Test/Tests/AddressBookTest.cs @@ -61,7 +61,7 @@ public void AddAndRemoveEntriesTest() => Run(() => personListView.AddButton.Click(); Assert.Equal(5, personListView.PersonDataGrid.RowCount); var newRow = personListView.PersonDataGrid.SelectedItem.As(); - Assert.Equal(personListView.PersonDataGrid.Rows[0], newRow); + Assert.Equal(personListView.PersonDataGrid.Rows[^1].As().ToTuple(), newRow.ToTuple()); // ItemStatus contains the validation error message or string.Empty if no error exists AssertEqual("", personView.FirstnameTextBox.Text, newRow.FirstnameCell.Label.Text); @@ -77,9 +77,9 @@ public void AddAndRemoveEntriesTest() => Run(() => Assert.Equal("ALastname", personView.LastnameTextBox.Text); AssertEqual("", personView.LastnameTextBox.ItemStatus, newRow.LastnameCell.Label.ItemStatus); - var lastRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 1).As(); - Assert.False(lastRow.IsOffscreen); - Assert.StartsWith("Ron", lastRow.FirstnameCell.Name); + var secondLastRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 2).As(); + Assert.False(secondLastRow.IsOffscreen); + Assert.StartsWith("Ron", secondLastRow.FirstnameCell.Name); var lastNotRemovedRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 3); personListView.PersonDataGrid.Select(personListView.PersonDataGrid.RowCount - 2); diff --git a/src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs b/src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs index 15dde968..6aed8e09 100644 --- a/src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs +++ b/src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs @@ -26,7 +26,6 @@ public void SearchBookListAndChangeEntriesTest() => Run(() => var firstBook = bookListView.BookDataGrid.GetRowByIndex(0).As(); var lastBook = bookListView.BookDataGrid.GetRowByIndex(rowCount - 1).As(); // GetRowByIndex scrolls to the item -> let's scroll back to the first book - Assert.True(firstBook.IsOffscreen); firstBook.ScrollIntoView(); Assert.False(firstBook.IsOffscreen); @@ -34,25 +33,25 @@ public void SearchBookListAndChangeEntriesTest() => Run(() => Assert.Equal(13, bookListView.BookDataGrid.RowCount); bookListView.SearchBox.Text = "Harr"; Assert.Equal(7, bookListView.BookDataGrid.RowCount); - var bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As(); - bookRow2.Select(); + var bookRow1 = bookListView.BookDataGrid.GetRowByIndex(0).As(); + bookRow1.Select(); - AssertEqual("Harry Potter and the Deathly Hallows", bookRow2.TitleCell.Name, bookView.TitleTextBox.Text); - AssertEqual("J.K. Rowling", bookRow2.AuthorCell.Name, bookView.AuthorTextBox.Text); + AssertEqual("Harry Potter and the Deathly Hallows", bookRow1.TitleCell.Name, bookView.TitleTextBox.Text); + AssertEqual("J.K. Rowling", bookRow1.AuthorCell.Name, bookView.AuthorTextBox.Text); Assert.Equal("Bloomsbury", bookView.PublisherTextBox.Text); - Assert.Equal("1/1/2007", bookRow2.PublishDateCell.Name); + Assert.Equal("1/1/2007", bookRow1.PublishDateCell.Name); Assert.Equal(new DateTime(2007, 1, 1), bookView.PublishDatePicker.SelectedDate); Assert.Equal("9780747591054", bookView.IsbnTextBox.Text); Assert.Equal("English", bookView.LanguageComboBox.SelectedItem.Text); Assert.Equal("607", bookView.PagesTextBox.Text); - AssertEqual("Ginny Weasley", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("Ginny Weasley", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); - bookRow2.TitleCell.Text = "Test Title"; + bookRow1.TitleCell.Text = "Test Title"; Assert.Equal("Test Title", bookView.TitleTextBox.Text); bookView.AuthorTextBox.Text = "TAuthor"; - Assert.Equal("TAuthor", bookRow2.AuthorCell.Name); + Assert.Equal("TAuthor", bookRow1.AuthorCell.Name); bookView.PublishDatePicker.SelectedDate = new DateTime(2024, 3, 2); - Assert.Equal("3/2/2024", bookRow2.PublishDateCell.Name); + Assert.Equal("3/2/2024", bookRow1.PublishDateCell.Name); Assert.Equal(["Undefined", "English", "German", "French", "Spanish", "Chinese", "Japanese"], bookView.LanguageComboBox.Items.Select(x => x.Name)); bookView.LanguageComboBox.Select(2); bookView.LanguageComboBox.Click(); // To close the combo box popup @@ -67,9 +66,9 @@ public void SearchBookListAndChangeEntriesTest() => Run(() => lendToWindow.WasReturnedRadioButton.Click(); Assert.False(lendToWindow.PersonListBox.IsEnabled); lendToWindow.OkButton.Click(); - AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); - bookRow2.LendToCell.LendToButton.Click(); + bookRow1.LendToCell.LendToButton.Click(); lendToWindow = window.FirstModalWindow().As(); Assert.True(lendToWindow.WasReturnedRadioButton.IsChecked); Assert.False(lendToWindow.LendToRadioButton.IsChecked); @@ -80,7 +79,7 @@ public void SearchBookListAndChangeEntriesTest() => Run(() => Assert.Equal(["Ginny", "Hermione", "Harry", "Ron"], lendToWindow.PersonListBox.Items.Select(x => x.Text)); lendToWindow.PersonListBox.Items[2].Select(); lendToWindow.OkButton.Click(); - AssertEqual("Harry Potter", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("Harry Potter", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); window.Close(); var messageBox = window.FirstModalWindow().As(); // MessageBox that asks user to save the changes @@ -99,7 +98,7 @@ public void AddAndRemoveEntriesTest() => Run(() => bookListView.AddButton.Click(); Assert.Equal(42, bookListView.BookDataGrid.RowCount); var newRow = bookListView.BookDataGrid.SelectedItem.As(); - Assert.Equal(bookListView.BookDataGrid.Rows[0], newRow); + Assert.Equal(bookListView.BookDataGrid.Rows[^1], newRow); // ItemStatus contains the validation error message or string.Empty if no error exists AssertEqual("", bookView.TitleTextBox.Text, newRow.TitleCell.Label.Text); @@ -115,9 +114,9 @@ public void AddAndRemoveEntriesTest() => Run(() => Assert.Equal("TAuthor", bookView.AuthorTextBox.Text); AssertEqual("", bookView.AuthorTextBox.ItemStatus, newRow.AuthorCell.Label.ItemStatus); - var lastRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 1).As(); - Assert.False(lastRow.IsOffscreen); - Assert.StartsWith("WPF", lastRow.TitleCell.Name); + var secondLastRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 2).As(); + Assert.False(secondLastRow.IsOffscreen); + Assert.StartsWith("WPF", secondLastRow.TitleCell.Name); var lastNotRemovedRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 3); bookListView.BookDataGrid.Select(bookListView.BookDataGrid.RowCount - 2); @@ -199,10 +198,10 @@ public void RemoveLendToPersonTest() => Run(() => var bookView = window.TabControl.BookLibraryTabItem.BookView; bookListView.SearchBox.Text = "Harr"; - var bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As(); - bookRow2.Select(); + var bookRow1 = bookListView.BookDataGrid.GetRowByIndex(0).As(); + bookRow1.Select(); - AssertEqual("Ginny Weasley", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("Ginny Weasley", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); window.TabControl.AddressBookTabItem.Select(); var personListView = window.TabControl.AddressBookTabItem.PersonListView; @@ -212,7 +211,7 @@ public void RemoveLendToPersonTest() => Run(() => personListView.RemoveButton.Click(); window.TabControl.BookLibraryTabItem.Select(); - AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); window.DataMenu.Click(); window.DataMenu.SaveMenuItem.Click(); @@ -225,11 +224,11 @@ public void RemoveLendToPersonTest() => Run(() => bookView = window.TabControl.BookLibraryTabItem.BookView; bookListView.SearchBox.Text = "Harr"; - bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As(); - bookRow2.Select(); + bookRow1 = bookListView.BookDataGrid.GetRowByIndex(1).As(); + bookRow1.Select(); window.TabControl.BookLibraryTabItem.Select(); - AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); + AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text); window.Close(); }); diff --git a/src/Samples.UITest/BookLibrary.Test/Views/PersonListView.cs b/src/Samples.UITest/BookLibrary.Test/Views/PersonListView.cs index b47b61a1..8a43b2f3 100644 --- a/src/Samples.UITest/BookLibrary.Test/Views/PersonListView.cs +++ b/src/Samples.UITest/BookLibrary.Test/Views/PersonListView.cs @@ -22,4 +22,6 @@ public class PersonGridRow(FrameworkAutomationElementBase element) : GridRow(ele public TextGridCell LastnameCell => Cells[1].As(); public HyperlinkGridCell EmailCell => Cells[2].As(); + + public (string firstname, string lastname, string email) ToTuple() => (FirstnameCell.Text, LastnameCell.Text, EmailCell.Name); }