Synchronization in LeanFT in C#.Net

We can add sync point in 2 ways.

  1. WaitUntil method
  2. Exists method
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 SyncTest : UnitTestClassBase<NotepadTest>
    {
        [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();

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

            //wait until notepad is displayed
            bool isNotepadDisplayed = notepadWindow.WaitUntil((notepad) => { return notepad.IsVisible; });

            if (isNotepadDisplayed)
            {
                Console.WriteLine("Notepad Window Exists");
            }
            else
            {
                Console.WriteLine("Notepad Window does not Exist");
            }

            //Another way to add sync point in LeanFT
            if (notepadWindow.Exists(2))
            {
                Console.WriteLine("Notepad Window Exists");
            }
            else {
                Console.WriteLine("Notepad Window does not Exist");
            }
     
        }

        [TestCleanup]
        public void TestCleanup()
        {
        }

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

You may also like...