How to access MessageBox with white color?

I have a simple message box in a WPF application that launches as shown below:

private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Howdy", "Howdy"); } 

I can get white to click my button and start a message box.

UISpy shows it as a child of my window. I could not process the method to access it.

How do I access my MessageBox to check its contents?

+4
source share
5 answers

Found! The window class has a MessageBox method that does the trick:

  var app = Application.Launch(@"c:\ApplicationPath.exe"); var window = app.GetWindow("Window1"); var helloButton = window.Get<Button>("Hello"); Assert.IsNotNull(helloButton); helloButton.Click(); var messageBox = window.MessageBox("Howdy"); Assert.IsNotNull(messageBox); 
+3
source

Please, try

  Window messageBox = window.MessageBox(""); var label = messageBox.Get<Label>(SearchCriteria.Indexed(0)); Assert.AreEqual("Hello",label.Text); 
+3
source

How to get a message in a message box? I can't seem to find anything in White. I think it is very important to assert that the message is correct.

+1
source

The source code for white contains some test designs for the user interface (for checking the white itself).

One test includes MessageBox tests, which include a way to get the displayed message.

 [TestFixture, WinFormCategory, WPFCategory] public class MessageBoxTest : ControlsActionTest { [Test] public void CloseMessageBoxTest() { window.Get<Button>("buttonLaunchesMessageBox").Click(); Window messageBox = window.MessageBox("Close Me"); var label = window.Get<Label>("65535"); Assert.AreEqual("Close Me", label.Text); messageBox.Close(); } [Test] public void ClickButtonOnMessageBox() { window.Get<Button>("buttonLaunchesMessageBox").Click(); Window messageBox = window.MessageBox("Close Me"); messageBox.Get<Button>(SearchCriteria.ByText("OK")).Click(); } } 

Obviously, the label used to display the text message belongs to the window displaying the message window, and its primary identification is the maximum value of the word (65535).

+1
source

window.MessageBox () is a good solution!

But this method will be stuck for a long time if the message is not displayed . Sometimes I want to check " Not Appearance " in the message box (warning, error, etc.). Therefore, I am writing a method to set timeOut by streaming.

 [TestMethod] public void TestMethod() { // arrange var app = Application.Launch(@"c:\ApplicationPath.exe"); var targetWindow = app.GetWindow("Window1"); Button button = targetWindow.Get<Button>("Button"); // act button.Click(); var actual = GetMessageBox(targetWindow, "Application Error", 1000L); // assert Assert.IsNotNull(actual); // I want to see the messagebox appears. // Assert.IsNull(actual); // I don't want to see the messagebox apears. } private void GetMessageBox(Window targetWindow, string title, long timeOutInMillisecond) { Window window = null ; Thread t = new Thread(delegate() { window = targetWindow.MessageBox(title); }); t.Start(); long l = CurrentTimeMillis(); while (CurrentTimeMillis() - l <= timeOutInMillsecond) { } if (window == null) t.Abort(); return window; } public static class DateTimeUtil { private static DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); public static long currentTimeMillis() { return (long)((DateTime.UtcNow - Jan1st1970).TotalMilliseconds); } } 
+1
source

Source: https://habr.com/ru/post/1277250/


All Articles