automated testing – unknown error: cannot create temp dir for unpacking extensions when trying to start Chrome from a LOCAL_SYSTEM service

We are trying to get our automated webtests working independently of what version of Chrome we’re using. These automated tests work as follows:

  1. We have a Karaf container agent running as a service;
  2. Karaf starts an ant script, which in turns starts another ant script. The first ant script is part of the automation tool we use (our own product) and the second ant script is the actual script that starts our testng webtests;
  3. TestNg, during the startup, starts the ChromeDriver in the following way using the bonigarcia Webdrivermanager library:

        // webDriver = new ChromeDriver();
        ChromeOptions options = new ChromeOptions();
        // ChromeDriver is just AWFUL because every version or two it breaks unless you pass cryptic arguments
        //AGRESSIVE: options.setPageLoadStrategy(PageLoadStrategy.NONE); //
        options.addArguments("--enable-automation"); //
        options.addArguments("--headless"); // only if you are ACTUALLY running headless
        options.addArguments("--no-sandbox"); //
        options.addArguments("--disable-infobars"); //
        options.addArguments("--disable-dev-shm-usage"); //
        options.addArguments("--disable-gpu"); //
        options.setExperimentalOption("useAutomationExtension", false);
        options.addArguments("--user-data-dir="+ System.getProperty("") +"/user-data-dir");
        options.addArguments("--disk-cache-dir="+ System.getProperty("") +"/disk-cache-dir");
        try {
            File logFile = new File(System.getProperty("").replace("", "\") + "\logs\chromedriver.log");
            boolean verbose = System.getProperty("test.web.webdriver.verbose").equals("true");
            ChromeDriverService driverService = new Builder().withVerbose(verbose).withLogFile(logFile).build();
            webDriver = new ChromeDriver(driverService, options);
        } catch (IOException e) {
            webDriver = new ChromeDriver(options);

The problem we have is that if the Karaf agent is running as the LOCAL_SYSTEM account (which is the default user when creating a new service), the Chromedriver can’t start Chrome with the error:

unknown error: cannot create temp dir for unpacking extensions

After some googling and testing, I’ve found this is because when starting the ChromeDriver, it tries to create a temporary folder for unpacking extensions in the user temp directory, which fails because the LOCAL_SYSTEM account doesn’t have a user directory.

I can work around the issue by making the service run as a LOCAL_SERVICE account, which does have a user directory, but we’ve found that some other scripts that run on this Karaf agent give problems when running as LOCAL_SERVICE (mainly older software integrations that we can’t easily upgrade), so ideally I’m hoping for a solution that makes LOCAL_SYSTEM work.

Is there a way to fix the temp dir problem that the Chromedriver has when attempting to start Chrome from a LOCAL_SYSTEM service?

Leave a Comment