Notepad Automation using LeanFT

Here is the example that illustrates how to automate Notepad application.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.Verifications;
using System.Diagnostics;
using System.Threading;
using HP.LFT.SDK.StdWin;

namespace LeanFtTestProject1
{
    [TestClass]
    public class LeanFtTest : UnitTestClassBase<LeanFtTest>
    {
        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {
            GlobalSetup(context);
        }

        [TestInitialize]
        public void TestInitialize()
        {

        }

        [TestMethod]
        public void TestMethod1()
        {
            Process appProcess = new Process { StartInfo = { FileName = @"C:\Windows\System32\notepad.exe" } };
            appProcess.Start();

            Thread.Sleep(3000);

            IWindow notepadWindow = Desktop.Describe<IWindow>(new WindowDescription
            {
                WindowClassRegExp = "Notepad",
                WindowTitleRegExp = " Notepad"
            });


            IEditor editor = notepadWindow.Describe<IEditor>(new EditorDescription
            {
                WindowClassRegExp = "Edit",
                NativeClass = "Edit"
            });
            
            editor.SendKeys("This is automated text");

            Thread.Sleep(3000);
            notepadWindow.Close();

           IButton button = Desktop.Describe<IWindow>(new WindowDescription
            {
                IsOwnedWindow = false,
                IsChildWindow = false,
                WindowClassRegExp = @"Notepad",
                WindowTitleRegExp = @" Notepad"
            }).Describe<IDialog>(new DialogDescription
            {
                IsOwnedWindow = true,
                IsChildWindow = false,
                Text = @"Notepad",
                NativeClass = @"#32770"
            }).Describe<IButton>(new ButtonDescription
            {
                Text = @"Do&n't Save",
                NativeClass = @"Button"
            });

            button.Click();
        }

        [TestCleanup]
        public void TestCleanup()
        {
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            GlobalTearDown();
        }
    }
}

You may also like...