Share this page

# Grid code samples (.NET SDK)

The following code samples show how to lock a 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.

    [TestMethod]
    public void Grid_LaunchBrowser_BrowserDescWithEnvDesc()
    {
           string nodeOsType = "Windows";                   // Set this to the node OS type
           string nodeOsVersion = "7";                      // Set this to the node OS version
           BrowserType browserType = BrowserType.Chrome;    // Set this to the requested browser type
           string browserVersion = ">57";                   // Set this to the requested browser version

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

           // Launch the browser (the required DesktopEnvironment is locked for you behind the scenes)
           var 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.

    [TestMethod]
    public void Grid_LaunchBrowser_OnSpecifiedEnv()
    {
           string nodeOsType = "Windows";               // Set this to the node OS type
           string nodeOsVersion = "7";                  // Set this to the node OS version
           BrowserType browserType = BrowserType.Chrome;    // Set this to the requested browser type
           string browserVersion = ">57";               // Set this to the requested browser version

           // Create an environment description object that includes required environment capabilities
           var envDesc = new EnvironmentDescription();
           envDesc.Set("ostype", nodeOsType);
           envDesc.Set("osversion", nodeOsVersion);

           // Lock a matching desktop environmentvar env = EnvironmentFactory.Get(envDesc);

           // Create a browser description object that includes only browser description
           var browserDesc = new BrowserDescription();
           browserDesc.Set("type", browserType);
           browserDesc.Set("version", browserVersion);

           // Launch the browser on the locked desktop environment
           var 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.

    [TestMethod]
    public void Grid_Describe_ClickOnDescribedObject()
    {
           string nodeOsType = "Windows";       // Set this to the node OS type
           string nodeOsVersion = "7";          // Set this to the node OS version

           // Create capabilities map, convert it to environment description and lock a matching desktop environment
           var capabilities = new Dictionary<string, object>();
           capabilities.Add("osType", nodeOsType);
           capabilities.Add("osversion ", nodeOsVersion);
           var env = EnvironmentFactory.Get(EnvironmentDescription.FromDictionary(capabilities));

           // Describe a window hierarchy under the desktop environment
           var calculator = env.Describe<IWindow>(new WindowDescription
    	      {
    	 	IsChildWindow = false,
    		IsOwnedWindow = false,
    		WindowClassRegExp = "CalcFrame",
    		WindowTitleRegExp = "Calculator"
    	      });

           // Your test code goes here.
           // e.g. this is how you click on a button in the desktop application:
           var btn = calculator.Describe<IButton>(new ButtonDescription
    	      {
    		  NativeClass = "Button",
    		  Text = "",
    	  	  WindowId = 135
    	      });

           // 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).

Use env.Mouse to gain access to the node's mouse and use it for operations.

    [TestMethod]
    public void Grid_DeviceReplay_Mouse()
    {
           string nodeOsType = "Windows";  // Set this to the node OS type
           string nodeOsVersion = "7";     // set this to the node OS version

           // Create capabilities map, convert it to environment description and lock a matching desktop environment
           var capabilities = new Dictionary<string, object>();
           capabilities.Add("osType", nodeOsType);
           capabilities.Add("osversion ", nodeOsVersion);
           var env = EnvironmentFactory.Get(EnvironmentDescription.FromDictionary(capabilities));

           // Get Mouse to perform low-level mouse actions
           var mouse = env.Mouse;

           // 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

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: