diff --git a/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js b/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
index 67ec1e7b2d323d06321122a2ad883fe338afb2fa..f685be6ca76f5137199cfb745704bc5d6a47ff87 100644
--- a/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
+++ b/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
@@ -50,6 +50,9 @@ exports.command = function drupalInstall(
       value: encodeURIComponent(installData.user_agent),
       path: url.pathname,
     });
+    // Set the HTTP_USER_AGENT environment variable to detect the test
+    // environment in the command line.
+    process.env.HTTP_USER_AGENT = installData.user_agent;
   } catch (error) {
     this.assert.fail(error);
   }