@@ -30,63 +30,65 @@ describe('Extension UI Testing', function() {
3030
3131 before ( async function ( ) {
3232 await boot ( ) ;
33- await new Promise ( r => setTimeout ( r , 5000 ) ) ;
3433 } ) ;
3534
3635 describe ( 'Page rewrite' , async function ( ) {
37- // JAPAN
38- it ( 'Rewrite target 1' , async function ( ) {
39- await page . goto ( urlPath + "1.html" , gotoOpts ) ;
40- const element = await page . waitForSelector ( "h1" ) ;
41- const value = await element . evaluate ( el => el . textContent ) ;
42- assert . equal ( value , '105.31 (Tormore, Speyside)' ) ;
43- await page . screenshot ( { path : extensionPath + `/test-extension-1.png` } ) ;
44- } ) ;
36+ /**
37+ * Waits for an element's textContent to match the expected text.
38+ * This is more reliable for dynamic content changes than waiting for the selector alone.
39+ * @param {string } selector - The CSS selector for the element.
40+ * @param {string } text - The expected text content.
41+ */
42+ const waitForText = ( selector , text ) => {
43+ return page . waitForFunction (
44+ ( sel , txt ) => document . querySelector ( sel ) ?. textContent === txt ,
45+ { } , // Options like timeout can be passed here
46+ selector ,
47+ text
48+ ) ;
49+ } ;
50+
51+ // JAPAN
52+ it ( 'Rewrite target 1' , async function ( ) {
53+ await page . goto ( urlPath + "1.html" , gotoOpts ) ;
54+ await waitForText ( 'h1' , '105.31 (Tormore, Speyside)' ) ;
55+ await page . screenshot ( { path : extensionPath + `/test-extension-1.png` } ) ;
56+ } ) ;
4557
4658 it ( 'Rewrite target 2' , async function ( ) {
4759 await page . goto ( urlPath + "2.html" , gotoOpts ) ;
48- const element = await page . waitForSelector ( ".product-box--title" ) ;
49- const value = await element . evaluate ( el => el . textContent ) ;
50- assert . equal ( value , '68.59 (Blair Athol, Highlands)' ) ;
60+ await waitForText ( '.product-box--title' , '68.59 (Blair Athol, Highlands)' ) ;
5161 await page . screenshot ( { path : extensionPath + `/test-extension-2.png` } ) ;
5262 } ) ;
5363
5464 it ( 'Rewrite target 6' , async function ( ) {
5565 await page . goto ( urlPath + "6.html" , gotoOpts ) ;
56- const element = await page . waitForSelector ( ".product-box--title" ) ;
57- const value = await element . evaluate ( el => el . textContent ) ;
58- assert . equal ( value , '151.3 (Mackmyra, Sweden)' ) ;
66+ await waitForText ( '.product-box--title' , '151.3 (Mackmyra, Sweden)' ) ;
5967 await page . screenshot ( { path : extensionPath + `/test-extension-6.png` } ) ;
6068 } )
6169
6270 // USA
6371 it ( 'Rewrite target 3' , async function ( ) {
6472 await page . goto ( urlPath + "3.html" , gotoOpts ) ;
65- const element = await page . waitForSelector ( "h1" ) ;
66- const value = await element . evaluate ( el => el . textContent ) ;
67- assert . equal ( value , '7.264 (Longmorn, Speyside)' ) ;
73+ await waitForText ( 'h1' , '7.264 (Longmorn, Speyside)' ) ;
6874 await page . screenshot ( { path : extensionPath + `/test-extension-3.png` } ) ;
6975 } ) ;
7076
7177 // UK
7278 it ( 'Rewrite target 4' , async function ( ) {
7379 await page . goto ( urlPath + "4.html" , gotoOpts ) ;
74- const element = await page . waitForSelector ( ".caskNo" ) ;
75- const value = await element . evaluate ( el => el . textContent ) ;
76- assert . equal ( value , '6.55 (Glen Deveron / Macduff, Speyside)' ) ;
80+ await waitForText ( '.caskNo' , '6.55 (Glen Deveron / Macduff, Speyside)' ) ;
7781 await page . screenshot ( { path : extensionPath + `/test-extension-4.png` } ) ;
7882 } )
7983
8084 it ( 'Rewrite target 5' , async function ( ) {
8185 await page . goto ( urlPath + "5.html" , gotoOpts ) ;
82- const element = await page . waitForSelector ( ".caskNo" ) ;
83- const value = await element . evaluate ( el => el . textContent ) ;
84- assert . equal ( value , '4.305 (Highland Park, Highlands)' ) ;
86+ await waitForText ( '.caskNo' , '4.305 (Highland Park, Highlands)' ) ;
8587 await page . screenshot ( { path : extensionPath + `/test-extension-5.png` } ) ;
8688 } )
87- } ) ;
89+ } ) ;
8890
89- after ( async function ( ) {
90- await browser . close ( ) ; // comment for dev
91- } ) ;
91+ after ( async function ( ) {
92+ await browser . close ( ) ; // comment for dev
93+ } ) ;
9294} ) ;
0 commit comments