Integrating LeanFT with Visual Studio Unit testing framework

Here is the example that shows how to integrate LeanFT with Visual Studio Unit testing framework. Note that we have initialized the LeanFT SDK at the beginning of the code and cleaned it up at the end.

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

namespace LeanFtTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {

            SDK.Init(new SdkConfiguration
            {
                ServerAddress = new Uri("ws://localhost:5095")
            });
            Reporter.Init(new ReportConfiguration());

            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");


            Reporter.GenerateReport();
            SDK.Cleanup();
        }
    }
}

You may also like...