diff --git a/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js b/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
index 9022592467ed29e739f60bd3051cfe16395242dd..67ec1e7b2d323d06321122a2ad883fe338afb2fa 100644
--- a/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
+++ b/core/tests/Drupal/Nightwatch/Commands/drupalInstall.js
@@ -33,7 +33,7 @@ exports.command = function drupalInstall(
     const langcodeOption = langcode ? `--langcode "${langcode}"` : '';
     const dbOption =
       process.env.DRUPAL_TEST_DB_URL.length > 0
-        ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}`
+        ? `--db-url "${process.env.DRUPAL_TEST_DB_URL}"`
         : '';
     const install = execSync(
       commandAsWebserver(
diff --git a/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js b/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js
index a832c977d47ce6cc0d2e98f9431d02610323ca87..bee0c5a6fc8ccf9a21f13f41e9f44d5a6d09408b 100644
--- a/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js
+++ b/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js
@@ -19,6 +19,9 @@ exports.command = function drupalLogin({ name, password }) {
       .setValue('input[name="name"]', name)
       .setValue('input[name="pass"]', password)
       .submitForm('#user-login-form');
+    // MongoDB needs a moment, because it is using a replica set and the
+    // members of the replica set need to synchronize.
+    this.pause(50);
     // Assert that a user is logged in.
     this.drupalUserIsLoggedIn((sessionExists) => {
       this.assert.equal(
diff --git a/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js b/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js
index a58d68efc9aad8d132b65a46bf3c86a23eaeed4e..94d2b6e461585aabcc9b300559be5e74a34592e7 100644
--- a/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js
+++ b/core/tests/Drupal/Nightwatch/Commands/drupalLogout.js
@@ -17,6 +17,10 @@ exports.command = function drupalLogout({ silent = false } = {}, callback) {
     '#user-logout-confirm',
   );
 
+  // MongoDB needs a moment, because it is using a replica set and the
+  // members of the replica set need to synchronize.
+  this.pause(50);
+
   this.drupalUserIsLoggedIn((sessionExists) => {
     if (silent) {
       if (sessionExists) {
diff --git a/core/tests/Drupal/Nightwatch/Commands/drupalUninstall.js b/core/tests/Drupal/Nightwatch/Commands/drupalUninstall.js
index 0ad21d00b9fe7c1357d0b188b3e4837f3aa24696..c582d04faa86acd60060c2583753f3ffc9d5b280 100644
--- a/core/tests/Drupal/Nightwatch/Commands/drupalUninstall.js
+++ b/core/tests/Drupal/Nightwatch/Commands/drupalUninstall.js
@@ -17,7 +17,7 @@ exports.command = function drupalUninstall(callback) {
   if (!this.currentTest.results.errors && !this.currentTest.results.failed) {
     const dbOption =
       process.env.DRUPAL_TEST_DB_URL.length > 0
-        ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}`
+        ? `--db-url "${process.env.DRUPAL_TEST_DB_URL}"`
         : '';
     try {
       if (!prefix || !prefix.length) {