D
D
Dommager2017-11-30 21:45:29
Software testing
Dommager, 2017-11-30 21:45:29

How to test application interface in C#?

Good evening.
I can't test my application's interface in VS using C#.
Tried through the standard package of coded tests. While recording, I can’t simply open the application, an already open application also reacts badly to the response. For example, you click the mouse, the whole system freezes for 2-3 seconds and then reacts as if the mouse button was simply pressed 1 time and held, no matter how many clicks there were.
I gave up on this, downloaded Teststack.White. Swears at the line where the main window is defined (Unlited -Notepad). How to define the main window at all? I used the Visual UI Automation and UISpy programs, but I didn’t understand how to determine the main window.
In debugging, it gives the following error
5a20516945cf9026446982.jpeg
. Here is the full code of the program

using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestStack.White;
using System.IO;
using TestStack.White.UIItems;
using TestStack.White.UIItems.WindowItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.MenuItems;
using TestStack.White.UIItems.WindowStripControls;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestCalk()
        {
            var application2 = Application.Launch("notepad");
           var window2 = application2.GetWindow("Untitled - Notepad");

            //  Thread.Sleep(1000);
            //window2.Get<Button>(SearchCriteria.ByAutomationId("num1Button")).Click();
            var textArea = window2.Get<TextBox>(SearchCriteria.ByAutomationId("15"));
            textArea.Text = "Hello, world!";
           // Assert.AreEqual(window2.Get<Label>(SearchCriteria.ByAutomationId("CalculatorResults")).Text.ToString(), "6");
                application2.Kill();
        }
    }
}

A notepad opens, but nothing is written in it, of course. Also tried with calculator, same problem with main window detection.
For a week now I can’t find a way to test the interface (you need to go to the university at the lab), please help with any information - I will be very grateful to you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2017-12-01
@Dommager

1. Are you sure that your notebook has the title "Untitled - Notepad" and not "Untitled - Notepad"?
2. After starting the process and before displaying the window, it takes some time. It makes sense to make a delay after the application starts and before accessing its window

var application2 = Application.Launch("notepad");
Thread.Sleep(500);
var window2 = application2.GetWindow("Untitled - Notepad");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question