← back to Council 0809 Builds

rolls-ar-deeplink/verify-live.mjs

51 lines

import pw from '/Users/macstudio3/.npm-global/lib/node_modules/playwright/index.js';
const { chromium } = pw;

const cases = [
  { label: "A width='36\" Wide' -> EXPECT BUTTON", handle: 'venezia-glass-beads-wall-paper-gold-gls-111-glass-beads-gold', expect: true },
  { label: "B width='Covers 30 sq ft' -> EXPECT NOTHING", handle: '1800-s-vintage-brown-and-off-white-crest-pattern-wallcovering-wi-vin-900', expect: false },
];

const browser = await chromium.launch({ headless: true });
const ctx = await browser.newContext({
  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126 Safari/537.36',
});
const page = await ctx.newPage();

for (const c of cases) {
  const url = `https://www.designerwallcoverings.com/products/${c.handle}`;
  let title = '', hasBtn = false, href = null, label = null, note = '';
  try {
    await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 });
    // wait out a possible CF challenge
    for (let i = 0; i < 20; i++) {
      title = await page.title().catch(() => '');
      if (!/verifying your connection|just a moment/i.test(title)) break;
      await page.waitForTimeout(1500);
    }
    await page.waitForTimeout(1500);
    const btn = await page.$('a.dw-rolls-btn, a[data-dw-rolls="1"]');
    hasBtn = !!btn;
    if (btn) {
      href = await btn.getAttribute('href');
      label = (await btn.innerText().catch(() => '')).trim();
    }
    // confirm it's really the PDP (section markers present)
    const pdp = await page.$('.product-container, #dw-similar, .keywords-desktop');
    note = pdp ? 'PDP-confirmed' : 'PDP-markers-missing';
  } catch (e) {
    note = 'ERROR ' + e.message.slice(0, 120);
  }
  const pass = hasBtn === c.expect;
  console.log('====================================================');
  console.log(c.label);
  console.log('  url        :', url);
  console.log('  title      :', title.slice(0, 60));
  console.log('  page       :', note);
  console.log('  buttonFound:', hasBtn, '  expected:', c.expect, '  =>', pass ? 'PASS' : 'FAIL');
  if (href) console.log('  href       :', href);
  if (label) console.log('  label      :', label);
}

await browser.close();