← back to Watches

thibaut-price-test.js

84 lines

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: 'new',
    executablePath: '/root/.cache/puppeteer/chrome/linux-145.0.7632.46/chrome-linux64/chrome',
    args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
  });
  const page = await browser.newPage();
  await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');

  // Login
  console.log('Logging in...');
  await page.goto('https://www.thibautdesign.com/account/login', { waitUntil: 'networkidle2', timeout: 30000 });
  await page.type('#email', 'info@designerwallcoverings.com');
  await page.type('#password', '*Thibautaccess911*');
  const navP = page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 }).catch(() => {});
  await page.evaluate(() => {
    const forms = document.querySelectorAll('form');
    for (const f of forms) {
      if (f.action.includes('/account/login')) { f.submit(); break; }
    }
  });
  await navP;
  console.log('Logged in, URL:', page.url());

  // Test 3 product pages
  const testSkus = ['TM42054', 'T14340', 'T72654'];
  for (const sku of testSkus) {
    console.log(`\n=== Product: ${sku} ===`);
    await page.goto(`https://www.thibautdesign.com/products/wallcoverings/${sku}`, { waitUntil: 'networkidle2', timeout: 30000 });

    // Wait a bit for dynamic content
    await new Promise(r => setTimeout(r, 2000));

    const bodyText = await page.evaluate(() => document.body.innerText);
    const lines = bodyText.split('\n').filter(l => l.trim().length > 0);

    // Find price lines
    const priceLines = lines.filter(l =>
      l.toLowerCase().includes('price') ||
      l.toLowerCase().includes('cost') ||
      l.toLowerCase().includes('retail') ||
      (l.includes('$') && l.length < 80)
    );
    console.log('Price lines:');
    priceLines.forEach(l => console.log('  >', l.trim()));

    // Also get specific price elements
    const priceData = await page.evaluate(() => {
      const result = {};
      // Look for specific text patterns
      const text = document.body.innerText;

      // Try patterns like "Retail Price: $XX.XX" or "Your Cost: $XX.XX"
      const retailMatch = text.match(/Retail\s*(?:Price)?[:\s]*\$?([\d,.]+)/i);
      const costMatch = text.match(/Your\s*(?:Cost|Price)?[:\s]*\$?([\d,.]+)/i);
      const priceMatch = text.match(/(?:^|\n)\s*\$\s*([\d,.]+)/m);

      if (retailMatch) result.retail = retailMatch[0].trim();
      if (costMatch) result.yourCost = costMatch[0].trim();
      if (priceMatch) result.price = priceMatch[0].trim();

      // Also look at all elements with price in class
      const els = document.querySelectorAll('[class*="price"], [class*="Price"], [class*="cost"], [class*="Cost"], [class*="retail"], [class*="Retail"]');
      result.priceElements = Array.from(els).slice(0, 10).map(e => ({
        cls: e.className.toString().substring(0, 60),
        text: e.innerText.trim().substring(0, 100)
      }));

      return result;
    });
    console.log('Price data:', JSON.stringify(priceData, null, 2));

    if (sku === testSkus[0]) {
      await page.screenshot({ path: '/tmp/thibaut-product-loggedin.png', fullPage: false });
      console.log('Screenshot saved');
    }
  }

  await browser.close();
  console.log('\nDone!');
})().catch(e => { console.error('Error:', e.message); process.exit(1); });