GuOrg / Gu.Wpf.UiAutomation

MIT License
96 stars 17 forks source link

Question: How to start the testable application? #80

Closed spogulis closed 5 years ago

spogulis commented 5 years ago

I might be missing something obvious but how to start testing the app? Here's what I have for opening Notepad++. I click to run the unit test named Login() in the Test Explorer but nothing happens.

using System;
using Gu.Wpf.UiAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace RichClientUnitTests_Gu
{

    public class UnitTest1
    {
        private const string ExeFileName = @"C:\Program Files (x86)\Notepad++\notepad++.exe";

        [SetUp]
        public void SetUp()
        {
            using (var app = Application.AttachOrLaunch(ExeFileName, "SomeWindowName"))
            {
                // restore state for the next test.
                Wait.UntilInputIsProcessed();
            }
        }

        [OneTimeSetUp]
        public void OneTimeSetUp()
        {
            using (var app = Application.AttachOrLaunch(ExeFileName))
            {
                var window = app.MainWindow;
            }
        }

        [OneTimeTearDown]
        public void OneTimeTearDown()
        {
            Application.KillLaunched(ExeFileName);
        }

        [Test]
        public void LogIn()
        {
            using (var app = Application.Launch(ExeFileName, "EmptyWindow"))
            {
                var window = app.MainWindow;
                app.GetMainWindow(TimeSpan.FromSeconds(10));

                Assert.AreEqual("Notepad++", window.Title);
            }
        }
    }
}
FoggyFinder commented 5 years ago

What do you mean by "nothing happens"? Test doesn't run?

spogulis commented 5 years ago

The app doesn't open, therefore no testing is done. Tried a bunch of apps. No breakpoint is hit either.

EDIT: Nevermind, it seems that the problem was with ReSharper. After clicking ReSharper/Unit Tests/Run Unit Test, it started to work.

JohanLarsson commented 5 years ago

Note: this library is primarily aimed at testing WPF applications. If it happens to work for other kinds it is by accident.

FoggyFinder commented 5 years ago

closed since it's not a problem from Gu.Wpf.UiAutomation side.