Automation of Java Applications in LeanFT in C#.Net

We can automate the Java applications developed in AWK and Swing. You need to ensure 2 things before you start the automation of Java based applications.

  1. Load the Java add-in
  2. Ensure that you use the using HP.LFT.SDK.Java namespace in your test

 

Automation of Java Applications using LeanFT

Automation of Java Applications using LeanFT

Here is the sample example that illustrates how to click on the checkbox in a Java app. Below code will start the Java App, then find the window with title  – Bus App and then select the checkbox with attached text as C1.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using System.Diagnostics;
using HP.LFT.SDK.Java;

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

        [TestInitialize]
        public void TestInitialize()
        {

        }

        [TestMethod]
        public void TestMethod1()
        {

            // Launch Java Application
            var javaAppProcess = new Process { StartInfo = { FileName = "java", Arguments = "-jar myJavaApp.jar" } };
            javaAppProcess.Start();

            // Find main Java Window
            var window = Desktop.Describe<IWindow>(new WindowDescription
            {
                Title = "Bus App",
                Index = 0
            });

            //Find the checkbox of in the Java Window
            var checkBox = window.Describe<ICheckBox>(new CheckBoxDescription
            {
                AttachedText="C1"
            });

            checkBox.SetState(CheckedState.Checked);

        }

        [TestCleanup]
        public void TestCleanup()
        {
        }

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

You may also like...