Micro Focus Expert
Micro Focus Expert

Protecting your MC while working with Appium

Working wiht Appium can be challening: Mobile Center invoke web driver instance on the connector machine.

But what will happend if the test is not terminated as expected or aborted? MC have a capability to automatically terminate not used instances of web driver, however it is better to eliminate such situaiton from the beginnig (relevant not only for MC, but for any Appium driven framework). The solution: addShutdownHook.

Please see the code below: the run method will be executed anytime that JVM is going down - perfect place to have your driver.quit() method to keep it clean.

package com.mf.cfrd;

public class Test {
    public static void main(String[] args) {

        Test test = new Test();
        try {
            while (true) {
                System.out.println("Inside Main");
        } catch (InterruptedException e) {
        } finally {

    public void attachShutDownHook() {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                System.out.println("Inside Add Shutdown Hook");
        System.out.println("Shut Down Hook Attached.");



The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.