diff --git a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php
index fbf6485618b654b3535b48170afcc5c594042b09..ee8db8a93a1167f91c8657ae0ab17c8b55ba18df 100644
--- a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php
+++ b/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php
@@ -65,14 +65,10 @@ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, arr
   protected function assertBreadcrumbParts($trail) {
     // Compare paths with actual breadcrumb.
     $parts = $this->getBreadcrumbParts();
+    $found = $parts;
     $pass = TRUE;
-    // Fail if there is no breadcrumb and we have a trail.
-    if (!empty($trail) && empty($parts)) {
-      $pass = FALSE;
-    }
-    // There may be more than one breadcrumb on the page. If $trail is empty
-    // this test would go into an infinite loop, so we need to check that too.
-    while ($trail && !empty($parts)) {
+
+    if (!empty($trail) && !empty($parts)) {
       foreach ($trail as $path => $title) {
         // If the path is empty, generate the path from the <front> route.  If
         // the path does not start with a leading slash, then run it through
@@ -91,11 +87,20 @@ protected function assertBreadcrumbParts($trail) {
         $pass = ($pass && $part['href'] === $url && $part['text'] === Html::escape($title));
       }
     }
+    elseif (!empty($trail) && empty($parts) || empty($trail) && !empty($parts)) {
+      // Fail if there is no breadcrumb and we have a trail or breadcrumb
+      // exists but trail is empty.
+      $pass = FALSE;
+    }
+
     // No parts must be left, or an expected "Home" will always pass.
     $pass = ($pass && empty($parts));
 
-    $this->assertTrue($pass, new FormattableMarkup('Breadcrumb %parts found on @path.', [
+    $this->assertTrue($pass, new FormattableMarkup('Expected breadcrumb %parts on @path but found %found.', [
       '%parts' => implode(' » ', $trail),
+      '%found' => implode(' » ', array_map(function (array $item) {
+        return $item['text'];
+      }, $found)),
       '@path' => $this->getUrl(),
     ]));
   }