diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
index 092d0cd..d905654 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
@@ -23,7 +23,7 @@
    */
   protected function initMink() {
     // Set up the template cache used by the PhantomJS mink driver.
-    $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache';
+    $path = DRUPAL_ROOT . '/' . $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache';
     $this->minkDefaultDriverArgs = [
       'http://127.0.0.1:8510',
       $path,
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index e91c346..8211d30 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -15,6 +15,7 @@
 use Drupal\Core\Config\Testing\ConfigSchemaChecker;
 use Drupal\Core\Database\Database;
 use Drupal\Core\DrupalKernel;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Serialization\Yaml;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Session\AnonymousUserSession;
@@ -48,26 +49,57 @@
 abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
   use AssertHelperTrait;
   use BlockCreationTrait {
-    placeBlock as drupalPlaceBlock;
+    placeBlock as drupalPlaceBlockParent;
   }
   use AssertLegacyTrait;
   use RandomGeneratorTrait;
   use SessionTestTrait;
   use NodeCreationTrait {
     getNodeByTitle as drupalGetNodeByTitle;
-    createNode as drupalCreateNode;
+    createNode as drupalCreateNodeParent;
   }
   use ContentTypeCreationTrait {
-    createContentType as drupalCreateContentType;
+    createContentType as drupalCreateContentTypeParent;
   }
   use ConfigTestTrait;
   use UserCreationTrait {
-    createRole as drupalCreateRole;
-    createUser as drupalCreateUser;
+    createRole as drupalCreateRoleParent;
+    createUser as drupalCreateUserParent;
   }
   use XdebugRequestTrait;
 
   /**
+   * Entities to clean up.
+   *
+   * @var \Drupal\Core\Entity\EntityInterface[]
+   */
+  protected $cleanupEntities = [];
+
+  /**
+   * Config to reset.
+   *
+   * @var array
+   */
+  protected $resetConfig = [];
+
+  /**
+   * Set this to TRUE to run the tests against the installed site.
+   *
+   * There are scenarios when building sites with Drupal where you may want to
+   * run functional tests against the installed site, instead of setting up a
+   * new site for each test method (the default behavior).
+   *
+   * Note that you must take care to cleanup entities created and reset any
+   * configuration changes.
+   *
+   * @see ::markEntityForCleanup
+   * @see ::setConfigValues
+   *
+   * @var bool
+   */
+  protected $runAgainstInstalledSite = FALSE;
+
+  /**
    * Class loader.
    *
    * @var object
@@ -515,7 +547,9 @@ protected function setUp() {
 
     // Install Drupal test site.
     $this->prepareEnvironment();
-    $this->installDrupal();
+    if (!$this->runAgainstInstalledSite) {
+      $this->installDrupal();
+    }
 
     // Setup Mink.
     $session = $this->initMink();
@@ -539,7 +573,7 @@ protected function setUp() {
         file_put_contents($this->htmlOutputDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n");
       }
       $this->htmlOutputCounterStorage = $this->htmlOutputDirectory . '/' . $this->htmlOutputClassName . '.counter';
-      $this->htmlOutputTestId = str_replace('sites/simpletest/', '', $this->siteDirectory);
+      $this->htmlOutputTestId = $this->databasePrefix;
       if (is_file($this->htmlOutputCounterStorage)) {
         $this->htmlOutputCounter = max(1, (int) file_get_contents($this->htmlOutputCounterStorage)) + 1;
       }
@@ -592,9 +626,19 @@ protected function cleanupEnvironment() {
   protected function tearDown() {
     parent::tearDown();
 
+    if ($this->runAgainstInstalledSite) {
+      $this->setConfigValues($this->resetConfig, FALSE);
+      foreach ($this->cleanupEntities as $entity) {
+        if ($entity instanceof EntityInterface) {
+          $entity->delete();
+        }
+      }
+    }
     // Destroy the testing kernel.
     if (isset($this->kernel)) {
-      $this->cleanupEnvironment();
+      if (!$this->runAgainstInstalledSite) {
+        $this->cleanupEnvironment();
+      }
       $this->kernel->shutdown();
     }
 
@@ -607,8 +651,14 @@ protected function tearDown() {
 
     // Restore original shutdown callbacks.
     if (function_exists('drupal_register_shutdown_function')) {
-      $callbacks = &drupal_register_shutdown_function();
-      $callbacks = $this->originalShutdownCallbacks;
+      if (!$this->runAgainstInstalledSite) {
+        $callbacks = &drupal_register_shutdown_function();
+        $callbacks = $this->originalShutdownCallbacks;
+      }
+      else {
+        $f = &drupal_register_shutdown_function();
+        $f = [];
+      }
     }
   }
 
@@ -811,7 +861,7 @@ protected function drupalLogin(AccountInterface $account) {
     ), t('Log in'));
 
     // @see BrowserTestBase::drupalUserIsLoggedIn()
-    $account->sessionId = $this->getSession()->getCookie($this->getSessionName());
+    $account->sessionId = $this->getSession()->getCookie(\Drupal::service('session_configuration')->getOptions(\Drupal::request())['name']);
     $this->assertTrue($this->drupalUserIsLoggedIn($account), SafeMarkup::format('User %name successfully logged in.', array('name' => $account->getUsername())));
 
     $this->loggedInUser = $account;
@@ -1310,71 +1360,106 @@ protected function prepareEnvironment() {
     // Bootstrap Drupal so we can use Drupal's built in functions.
     $this->classLoader = require __DIR__ . '/../../../../autoload.php';
     $request = Request::createFromGlobals();
-    $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
-    // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
-    chdir(DRUPAL_ROOT);
-    $kernel->prepareLegacyRequest($request);
-    $this->prepareDatabasePrefix();
-
-    $this->originalSiteDirectory = $kernel->findSitePath($request);
-
-    // Create test directory ahead of installation so fatal errors and debug
-    // information can be logged during installation process.
-    file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
-
-    // Prepare filesystem directory paths.
-    $this->publicFilesDirectory = $this->siteDirectory . '/files';
-    $this->privateFilesDirectory = $this->siteDirectory . '/private';
-    $this->tempFilesDirectory = $this->siteDirectory . '/temp';
-    $this->translationFilesDirectory = $this->siteDirectory . '/translations';
-
-    // Ensure the configImporter is refreshed for each test.
-    $this->configImporter = NULL;
-
-    // Unregister all custom stream wrappers of the parent site.
-    $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL);
-    foreach ($wrappers as $scheme => $info) {
-      stream_wrapper_unregister($scheme);
-    }
 
-    // Reset statics.
-    drupal_static_reset();
+    if (!$this->runAgainstInstalledSite) {
+      $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
+      // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
+      chdir(DRUPAL_ROOT);
+      $kernel->prepareLegacyRequest($request);
 
-    // Ensure there is no service container.
-    $this->container = NULL;
-    \Drupal::unsetContainer();
+      $this->prepareDatabasePrefix();
+      $this->originalSiteDirectory = $kernel->findSitePath($request);
+
+      // Create test directory ahead of installation so fatal errors and debug
+      // information can be logged during installation process.
+      file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+
+      // Prepare filesystem directory paths.
+      $this->publicFilesDirectory = $this->siteDirectory . '/files';
+      $this->privateFilesDirectory = $this->siteDirectory . '/private';
+      $this->tempFilesDirectory = $this->siteDirectory . '/temp';
+      $this->translationFilesDirectory = $this->siteDirectory . '/translations';
+
+      // Ensure the configImporter is refreshed for each test.
+      $this->configImporter = NULL;
+
+      // Unregister all custom stream wrappers of the parent site.
+      $wrappers = \Drupal::service('stream_wrapper_manager')
+        ->getWrappers(StreamWrapperInterface::ALL);
+      foreach ($wrappers as $scheme => $info) {
+        stream_wrapper_unregister($scheme);
+      }
 
-    // Unset globals.
-    unset($GLOBALS['config_directories']);
-    unset($GLOBALS['config']);
-    unset($GLOBALS['conf']);
+      // Reset statics.
+      drupal_static_reset();
 
-    // Log fatal errors.
-    ini_set('log_errors', 1);
-    ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
+      // Ensure there is no service container.
+      $this->container = NULL;
+      \Drupal::unsetContainer();
 
-    // Change the database prefix.
-    $this->changeDatabasePrefix();
+      // Unset globals.
+      unset($GLOBALS['config_directories']);
+      unset($GLOBALS['config']);
+      unset($GLOBALS['conf']);
 
-    // After preparing the environment and changing the database prefix, we are
-    // in a valid test environment.
-    drupal_valid_test_ua($this->databasePrefix);
+      // Log fatal errors.
+      ini_set('log_errors', 1);
+      ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
 
-    // Reset settings.
-    new Settings(array(
-      // For performance, simply use the database prefix as hash salt.
-      'hash_salt' => $this->databasePrefix,
-    ));
+      // Change the database prefix.
+      $this->changeDatabasePrefix();
 
-    drupal_set_time_limit($this->timeLimit);
+      // After preparing the environment and changing the database prefix, we
+      // are in a valid test environment.
+      drupal_valid_test_ua($this->databasePrefix);
 
-    // Save and clean the shutdown callbacks array because it is static cached
-    // and will be changed by the test run. Otherwise it will contain callbacks
-    // from both environments and the testing environment will try to call the
-    // handlers defined by the original one.
-    $callbacks = &drupal_register_shutdown_function();
-    $this->originalShutdownCallbacks = $callbacks;
-    $callbacks = [];
+      // Reset settings.
+      new Settings(array(
+        // For performance, simply use the database prefix as hash salt.
+        'hash_salt' => $this->databasePrefix,
+      ));
+
+      drupal_set_time_limit($this->timeLimit);
+
+      // Save and clean the shutdown callbacks array because it is static cached
+      // and will be changed by the test run. Otherwise it will contain
+      // callbacks from both environments and the testing environment will try
+      // to call the handlers defined by the original one.
+      $callbacks = &drupal_register_shutdown_function();
+      $this->originalShutdownCallbacks = $callbacks;
+      $callbacks = [];
+    }
+    else {
+      $kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'testing');
+      chdir(DRUPAL_ROOT);
+      $kernel->prepareLegacyRequest($request);
+      $this->container = $kernel->getContainer();
+
+      // Set some debugging defaults.
+      $config_values = [
+        'system.mail' => [
+          'interface.default' => 'test_mail_collector',
+        ],
+        'system.logging' => [
+          'error_level' => 'verbose',
+        ],
+        'system.performance' => [
+          'css.preprocess' => FALSE,
+          'js.preprocess' => FALSE,
+        ],
+      ];
+      $this->setConfigValues($config_values);
+
+      chdir(DRUPAL_ROOT);
+      $this->originalSiteDirectory = 'sites/default';
+      $this->siteDirectory = 'sites/default';
+      file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+      $this->publicFilesDirectory = $this->siteDirectory . '/files';
+      $this->privateFilesDirectory = $this->siteDirectory . '/private';
+      $this->tempFilesDirectory = $this->siteDirectory . '/temp';
+      $this->translationFilesDirectory = $this->siteDirectory . '/translations';
+      file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+    }
   }
 
   /**
@@ -1853,4 +1938,88 @@ protected function getTestMethodCaller() {
     return Error::getLastCaller($backtrace);
   }
 
+  /**
+   * Set config values noting future values if required.
+   *
+   * @param array[] $config_values
+   *   Array of array values keyed by config object key.
+   * @param bool $mark
+   *   TRUE to record value for resetting later.
+   */
+  protected function setConfigValues($config_values, $mark = TRUE) {
+    $config = $this->container->get('config.factory');
+    foreach ($config_values as $key => $values) {
+      /** @var \Drupal\Core\Config\ImmutableConfig $entry */
+      $entry = $config->getEditable($key);
+      if ($mark && !isset($this->resetConfig[$key])) {
+        $this->resetConfig[$key] = [];
+      }
+      foreach ($values as $value_key => $value) {
+        if ($mark) {
+          $this->resetConfig[$key][$value_key] = $entry->get($value_key);
+        }
+        $entry->set($value_key, $value);
+      }
+      $entry->save();
+    }
+  }
+
+  /**
+   * When running against an installed site, mark an entity for deletion.
+   *
+   * Any entities you create when running against an installed site should be
+   * flagged for deletion to ensure isolation between tests.
+   *
+   * @param \Drupal\Core\Entity\EntityInterface $entity
+   *   Entity to delete.
+   */
+  protected function markEntityForCleanup(EntityInterface $entity) {
+    $this->cleanupEntities[] = $entity;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function drupalPlaceBlock($plugin_id, array $settings = array()) {
+    $block = $this->drupalPlaceBlockParent($plugin_id, $settings);
+    $this->markEntityForCleanup($block);
+    return $block;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function drupalCreateContentType(array $values = array()) {
+    $type = $this->drupalCreateContentTypeParent($values);
+    $this->markEntityForCleanup($type);
+    return $type;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function drupalCreateNode(array $settings = array()) {
+    $node = $this->drupalCreateNodeParent($settings);
+    $this->markEntityForCleanup($node);
+    return $node;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function drupalCreateUser(array $permissions = array(), $name = NULL, $admin = FALSE) {
+    $user = $this->drupalCreateUserParent($permissions, $name, $admin);
+    $this->markEntityForCleanup($user);
+    return $user;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) {
+    $role = $this->drupalCreateRoleParent($permissions, $rid, $name, $weight);
+    $this->markEntityForCleanup($role);
+    return $role;
+  }
+
 }
