Share this page

# UFT Developer Grid code samples (Java SDK)

The following code samples show how to lock a UFT Developer grid node that provides the capabilities required for your test, and then perform operations on that node.

In this topic:

## Lock a node as part of the launch browser step

Call BrowserFactory.launch with a browser description that includes environment capabilities. This call locks a node with the described environment, launches the browser on the node, and returns a browser handle.

    @Test
    public void grid_LaunchBrowser_BrowserDescWithEnvDesc () throws GeneralLeanFtException {

        final String      nodeOsType = "Windows";		// set this to the node OS type
        final String      nodeOsVersion = "7";		        // set this to the node OS version
        final BrowserType browserType = BrowserType.CHROME;	// set this to the requested browser type
        final String      browserVersion = ">57";		// set this to the requested browser version

        // create a browser description object that includes also the required environment
        BrowserDescription browserDesc = new BrowserDescription.Builder().build();
        browserDesc.set("type", browserType);
        browserDesc.set("version", browserVersion);
        browserDesc.set("ostype", nodeOsType);
        browserDesc.set("osversion", nodeOsVersion);

        // launch the browser (the required DesktopEnvironment will be locked for you behind the scenes)
        Browser browser = BrowserFactory.launch(browserDesc);

        // your test code goes here

        browser.close();
    }

Back to top

## Lock a node and then launch a browser on that node

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle.

Call BrowserFactory.launch with a browser description and the environment handle to launch the browser on the locked node.

    @Test
    public void grid_LaunchBrowser_OnSpecifiedEnv() throws GeneralLeanFtException {

        final String      nodeOsType = "Windows";		// set this to the node OS type
        final String      nodeOsVersion = "7";		        // set this to the node OS version
        final BrowserType browserType = BrowserType.CHROME;	// set this to the requested browser type
        final String      browserVersion = ">57";              // set this to the requested browser version

        // create an environment description object that includes required environment capabilities
        EnvironmentDescription envDesc = new EnvironmentDescription.Builder().build();
        envDesc.set("ostype", nodeOsType);
        envDesc.set("osversion", nodeOsVersion);

        // lock a matching desktop environment
        DesktopEnvironment env = EnvironmentFactory.get(envDesc);

        // create a browser description object that includes only browser description
        BrowserDescription browserDesc = new BrowserDescription.Builder().build();
        browserDesc.set("type", browserType);
        browserDesc.set("version", browserName);

        // launch the browser on the locked desktop environment
        Browser browser = BrowserFactory.launch(browserDesc, env);

        // your test code goes here

        browser.close();
    }

Back to top

## Lock a node and perform operations on a desktop application

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle (env).

Call env.describe to specify the calculator application on the node, and then press its buttons.

    @Test
    public void grid_Describe_ClickOnDescribedObject() throws GeneralLeanFtException {

        final String nodeOsType = "Windows";		// set this to the node OS type
        final String nodeOsVersion = "7";		// set this to the node OS version

        // create capabilities map, convert it to environment description and lock a matching desktop environment
        Map<String,Object> capabilities = new HashMap<>();
        capabilities.put("osType", nodeOsType);
        capabilities.put("osversion ", nodeOsVersion);
        DesktopEnvironment env = EnvironmentFactory.get(EnvironmentDescription.fromMap(capabilities));

        // describe a window hierarchy under the desktop environment
        Window calculator = env.describe(Window.class, new WindowDescription.Builder()
            .childWindow(false)
            .ownedWindow(false)
            .windowClassRegExp("CalcFrame")
            .windowTitleRegExp("Calculator").build());

         // your test code goes here.

         // e.g. this is how you click on a button in the desktop application:
         Button btn = calculator.describe(Button.class, new ButtonDescription.Builder()
             .nativeClass("Button")
             .text("")
             .windowId(135).build());
         // click
         btn.click();
    }

Back to top

## Lock a node and perform operations using the node's mouse

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle (env).

Call env.getMouse to gain access to the node's mouse and use it for operations.

    @Test
    public void grid_DeviceReplay_Mouse () throws GeneralLeanFtException {

        final String nodeOsType = "Windows";		// set this to the node OS type
        final String nodeOsVersion = "7";		// set this to the node OS version

        // create capabilities map, convert it to environment description and lock a matching desktop environment
        Map<String,Object> capabilities = new HashMap<>();
        capabilities.put("osType", nodeOsType);
        capabilities.put("osversion ", nodeOsVersion);
        DesktopEnvironment env = EnvironmentFactory.get(EnvironmentDescription.fromMap(capabilities));

        // get Mouse to perform low-level mouse actions
        MouseDevice mouse = env.getMouse();

        // your test code goes here.

        // e.g. this is how you right-click on point:
        mouse.click(new Point(80,80), MouseButton.RIGHT);
    }

Back to top

Tips to improve your search results... UFT Developer Java SDK Reference Version 15.0-15.0.2 UFT Developer SDK Reference All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: