From f47f3c01bf0cfd12d65bb0bcb39154d7cff551b1 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 17 Oct 2022 19:46:12 +0100
Subject: [PATCH] Issue #3315753 by alexpott: Random fail in
 Drupal\Tests\media_library\FunctionalJavascript\WidgetUploadTest

(cherry picked from commit dcc44243361b8b1b79cf45e0b639b81979e9eac2)
---
 .../tests/src/FunctionalJavascript/WidgetUploadTest.php   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
index bb12a63ef21b..74c51bc1e77f 100644
--- a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
@@ -136,8 +136,10 @@ public function testWidgetUpload() {
     $this->waitForText($png_image->filename);
 
     // Remove the item.
+    $assert_session->elementTextContains('css', '.field--name-field-twin-media', $png_image->filename);
     $assert_session->elementExists('css', '.field--name-field-twin-media')->pressButton('Remove');
-    $this->waitForNoText($png_image->filename);
+    $this->waitForElementTextContains('#drupal-live-announce', $png_image->filename . ' has been removed');
+    $assert_session->elementTextNotContains('css', '.field--name-field-twin-media', $png_image->filename);
 
     $this->openMediaLibraryForField('field_twin_media');
     $this->switchToMediaType('Three');
@@ -473,8 +475,10 @@ public function testWidgetUploadAdvancedUi() {
     $this->waitForText($png_image->filename);
 
     // Remove the item.
+    $assert_session->elementTextContains('css', '.field--name-field-twin-media', $png_image->filename);
     $assert_session->elementExists('css', '.field--name-field-twin-media')->pressButton('Remove');
-    $this->waitForNoText($png_image->filename);
+    $this->waitForElementTextContains('#drupal-live-announce', $png_image->filename . ' has been removed');
+    $assert_session->elementTextNotContains('css', '.field--name-field-twin-media', $png_image->filename);
 
     $this->openMediaLibraryForField('field_twin_media');
     $this->switchToMediaType('Three');
-- 
GitLab