From 910386bee94580769eef02071c05ecaf4db49e40 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Mon, 4 Dec 2023 10:07:26 +0100 Subject: [PATCH] [FIX] website_slides: fix a tour that fails randomly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In v17.0, the test TestUiPublisher.test_course_publisher_elearning_manager of website_slides fails randomly at the step: "eLearning: check uploaded pdf presence and perform comparison" with the error: "Cannot read properties of null (reading 'getAttribute')" How to reproduce it ? Locally, TestUiPublisher.test_course_publisher_elearning_manager of website_slides runs without errors but when executing it in the browser we get the same error as the runbot systematically: – Install website_slides – Go to shell mode and execute the setup of the test – (Backup DB if you want to run the test multiple time) – Launch in normal mode and connect with demo user – Go to URL: /web?debug=assets%2Ctests – Type “odoo.startTour('course_publisher_standard');” in the console – An error happens at step “eLearning: check uploaded pdf presence and perform comparison”: Cannot read properties of null (reading 'getAttribute') (to avoid to wait too long, you can shorten the test by keeping mostly “addPdfToSection”) The problem occurs because the rendering of the iframe o_wslides_iframe_viewer is not always completed when the check is triggered. We solve this problem by waiting for the rendering to finish before performing the test (using "await contains"). For safety, we do the same for another check as this might cause a similar problem in the future. Although the test has been introduced in 16.2 (see odoo/odoo#117293) but the error happens only in 17.0 (tested only in 16.4 the way described above), we publish only the correction in 17.0 and further to avoid different correction in various version. Task-3623736 closes odoo/odoo#144719 Signed-off-by: Warnon Aurélien (awa) --- .../static/tests/tours/slides_tour_tools.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/website_slides/static/tests/tours/slides_tour_tools.js b/addons/website_slides/static/tests/tours/slides_tour_tools.js index 1f274eed8f6..4c4f3dea026 100644 --- a/addons/website_slides/static/tests/tours/slides_tour_tools.js +++ b/addons/website_slides/static/tests/tours/slides_tour_tools.js @@ -1,5 +1,6 @@ /** @odoo-module **/ +import { contains } from "@web/../tests/utils"; import { getDataURLFromFile } from "@web/core/utils/urls"; /* @@ -204,11 +205,13 @@ const addPdfToSection = function (sectionName, pageName, backend) { trigger: `${prefix}a.o_wslides_js_slides_list_slide_link:contains("Exercise")`, }, { content: 'eLearning: check uploaded pdf presence and perform comparison', - trigger: (backend ? 'iframe ' : '') + '.o_wslides_fs_content', + trigger: (backend ? 'iframe.o_iframe ' : '') + '.o_wslides_fs_content', run: async () => { - const baseElement = backend ? document.querySelector('iframe').contentDocument : document; - const pdfViewer = baseElement.querySelector('iframe.o_wslides_iframe_viewer').contentDocument - .querySelector('#PDFSlideViewer'); + const baseElement = backend ? document.querySelector('iframe.o_iframe').contentDocument : document; + await contains('iframe.o_wslides_iframe_viewer', { target: baseElement }); + const iframeViewerDoc = baseElement.querySelector('iframe.o_wslides_iframe_viewer').contentDocument; + await contains('#PDFSlideViewer', { target: iframeViewerDoc }); + const pdfViewer = iframeViewerDoc.querySelector('#PDFSlideViewer'); if (await compareBase64Content(pdfViewer.getAttribute('data-slideurl'), 'Exercise.pdf', 'application/pdf', testPdf)) { baseElement.querySelector('.o_wslides_fs_content').classList.add('o_wslides_tour_pdf_upload_success'); }