Migrating your Selenium Tests to run on OpenFin Workplace Application

We took the exciting step forward of transitioning some of our internal web applications to run on OpenFin Workspace. This effort gave our developers at 28Stone additional experience on OpenFin Workspace as well as the opportunity to learn about the latest in desktop workflows and interoperability. We selected a diverse set of applications for this migration: a home-grown career management platform (React/Java/AWS), a cloud-native corporate bond continuous matching platform (React/.Net/Azure), and a candidate and skills directory application (Angular/.Net/AWS). Not only did we transition these apps to OpenFin Workspace, we also created a desktop experience unifying these applications in one cohesive experience.

A core tenet of 28Stone’s software delivery philosophy is that the prioritization of testing and QA at the onset of a project is crucial. Too often treating testing as an afterthought leads to under-performance or outright failures on projects. In line with this thinking, it’s no surprise that each of our migrated internal applications is also supported by a comprehensive suite of automated Selenium tests. In adopting OpenFin Workspace, the framework supporting these tests needed updating changes to work with counterpart OpenFin migrated applications. Recognizing that this might be a commonly encountered problem, we put together this clear step-by-step guide to walk you through the essential phases of migrating your test framework to successfully run withOpenFin Workspace applications.

So, let’s dive into these key steps and explore how to navigate this transition effectively.

The Approach

There are three key steps in the process that are required for migrating your tests:

  • Setup the environment
  • Connect the driver
  • Launch the application

You will notice that as part of this migration the test cases themselves need not be modified. Now, let’s delve into each step, complete with sample code and commands, to give you a head start on this process.

Set Up

To start our journey, the first step involves ensuring your environment is properly set up and the openfin-cli library is installed. For us this required the installation of node, npm and then using the following command to install the openfin-cli.

npm i -g openfin-cli

The openfin-cli library automatically uses the latest version of the Openfin Runtime Version Manager (RVM). However, if you need to test with a different RVM version, you can download and install that specific version directly from the RVM versions page.

Connect the Driver

With the environment ready, the next step is to write the code responsible for connecting the driver and launching the OpenFin container. The provided sample code is in Java because that is our framework of choice, but the outlined steps here are applicable across other Selenium language frameworks as well.

In the Selenium framework, update the setupWebDriver(String driverType) method in the SetupWebDriver.java to include support for OpenFin. Our test framework supports OpenFin, Chrome as well as IE. The following code block shows the code required for OpenFin:

public static RemoteWebDriver setupWebDriver(String driverType) throws MalformedURLException {
  RemoteWebDriver driver;
  switch (driverType) {
    case PropertyConfigs.OPENFIN:
      int seleniumDriverPort = startChromedriver();
      driver = new RemoteWebDriver(new URL("http://localhost:" + seleniumDriverPort, getOpenfinOptions());
      driver.manage().deleteAllCookies();
      driver.executeScript("window.localStorage.clear();");
      OpenFinUtil.deleteCache(driver);
      break;
    // rest of the case statement clipped for brevity
  }
  return driver;
}

It is important to note two key aspects here. First, the instantiation of the RemoteWebDriver class includes a call to the method getOpenfinOptions(). That method, which will be described in detail later, is responsible for launching the OpenFin container. The objective of the setupWebDriver(String driverType) method is to connect the launched OpenFin container to the instantiated RemoteWebDriver. Second, extra caution should be taken to delete cookies, clear local cache and local storage to ensure that the test run you are about to launch is not corrupted by existing local data.

In that same SetupWebDriver.java, we also define the getOpenfinOptions() method that plays a crucial role in integrating Selenium WebDriver with the OpenFin environment. Let’s examine how it’s structured and why each step matters.

private static ChromeOptions getOpenfinOptions() {
  ChromeOptions options = new ChromeOptions();
  options.setExperimentalOption("debuggerAddress","127.0.0.1:"+GlobalParams.OPEN_FIN_DEBUG_PORT);
  String startupURL = String.format("--config=%s", GlobalParams.OPEN_FIN_CONFIG_URL);

  OpenFinUtil.launchOpenFinApp(System.getProperty("user.dir") + "/RunOpenFin.bat",  startupURL);
  AwaitUtils.waitForActionTimeout(() - !ConnectionHelper.isTcpPortAvailable(GlobalParams.OPEN_FIN_DEBUG_PORT),"Waiting for open fin app to start failed");

  options.setCapability("browserName", PropertyConfigs.CHROME);

  return options;
}
  • The method begins by creating an instance of ChromeOptions. We then use options.setExperimentalOption(“debuggerAddress”, “127.0.0.1:” + GlobalParams.OPEN_FIN_DEBUG_PORT); to set a custom debugger address. This step is key for connecting the WebDriver to Chrome’s debugging protocol, allowing for detailed monitoring and control during test runs.
  • The next part of the method prepares and executes the OpenFin environment setup. We first define the startup URL which is loaded from a global setting and then passed to the launchOpenFinApp() method, which uses ProcessBuilder to execute the RunOpenFin.bat script. This script initiates the OpenFin container.
  • We use AwaitUtils.waitForActionTimeout() to verify that the OpenFin application has successfully started. Specifically, it checks if the specified TCP port is active, indicating that OpenFin is up and running.
  • Lastly, the method specifies that the browser to be used is Chrome with options.setCapability(“browserName”, PropertyConfigs.CHROME);. These configurations ensure that the WebDriver operates under test conditions and explicitly uses the Chrome browser, aligning with our testing requirements.

These steps collectively ensure that the WebDriver is appropriately configured for interacting with applications in the OpenFin environment.

Launch the application

Now, let’s turn our attention to the RunOpenFin.bat file that is used by the getOpenFinOptions() method to launch the application on OpenFin. It takes in the startupURL and passes it as a config to launch the application and ensures that auto-update is disabled.

openfin --launch --config=%startupURL% --disable-auto-updates --disable-init-reload --enable-chromium-window-alert

If you’ve successfully made it this far, you have set up the environment, installed the relevant libraries and implemented the code to invoke OpenFin connected to the driver for running your tests.

In our implementation we chose to launch the application directly from OpenFin Dock. The method openApplication() is represented by a step function, such as ‘Given I open the Career Path Application’, in cucumber tests. Therefore, none of the actual step functions in your test scripts need to be modified but only the method defining the step function needs to be updated as in the following code block.

public void openApplication() {
  OpenFinUtil.switchWindow("React App", Window.TITLE);
  new Button(By.xpath("//div//span")).click();
  AwaitUtils.waitForAction(() -> isWindowExists("Dock | Dock"));
  WebDriver driver = selectTab("Dock | Dock");
  driver.findElement(By.xpath("//button[@title='Career Path Tool']")).click();
  AwaitUtils.waitForAction(() -> isWindowExists("Log in to 28Stone-staging"));
}
Conclusion

By following these three simple steps of Setup, Connect and Launch you too can migrate your existing Selenium test scripts to work on OpenFin Workspace applications. We’ve aimed for broad applicability in outlining these steps but if you encounter any issues or have suggestions, we’d love to hear from you.

About 28Stone, OpenFin & our partnership

At 28Stone, we have a long track record of successfully designing and delivering user-centric software in the capital markets and financial services. Over the past decade, we’ve witnessed, and in some cases catalyzed, a transformative shift in trader desktop applications inspired by the efficiency and aesthetics of modern mobile devices. We are at a similar inflection point today as the workflow demands on a trader over the last decade have increased exponentially. This rise in complexity can in part be attributed to the proliferation of tools deployed on a trader’s desktop that are not naturally inter-operable.

As Certified Development Partners, we’re delighted to work with OpenFin, a long-time partner of 28Stone and a leader in delivering productivity-enhancing experiences. Our partnership focuses on providing complementary expertise in high-quality, cost-effective, front-office solution design and implementation. The potential for leveraging OpenFin for digital transformation use cases and to build intuitive applications are many. The operating environment for all companies are changing rapidly. We’ve been able to increase efficiencies, cut costs and deliver just-right solutions for our customers. Connect with us to learn more about how we can assist you as OpenFin experts.

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. OK