← back to Watches

thibaut-login-test.js

93 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');

  // Go to login page
  console.log('Navigating to login...');
  await page.goto('https://www.thibautdesign.com/account/login', { waitUntil: 'networkidle2', timeout: 30000 });
  console.log('Page title:', await page.title());

  // Login with correct selectors
  console.log('Logging in...');
  await page.type('#email', 'info@designerwallcoverings.com');
  await page.type('#password', '*Thibautaccess911*');

  // Click submit via JS to avoid clickability issues
  await page.evaluate(() => {
    const btn = document.querySelector('button[type="submit"]') || document.querySelector('input[type="submit"]');
    if (btn) btn.click();
  });
  console.log('Submitted login form');
  await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 }).catch(() => {});
  console.log('After login URL:', page.url());

  const loggedIn = !page.url().includes('/login');
  console.log('Logged in:', loggedIn);

  // Test product page
  console.log('\n--- Testing product page TM42054 ---');
  await page.goto('https://www.thibautdesign.com/products/wallcoverings/TM42054', { waitUntil: 'networkidle2', timeout: 30000 });
  console.log('Product URL:', page.url());

  // Get all text and find price info
  const bodyText = await page.evaluate(() => document.body.innerText);
  const lines = bodyText.split('\n').filter(l => l.trim().length > 0);

  // Search for price-related text
  const priceLines = lines.filter(l =>
    l.toLowerCase().includes('price') ||
    l.toLowerCase().includes('cost') ||
    l.toLowerCase().includes('retail') ||
    l.toLowerCase().includes('your') ||
    l.includes('$')
  );
  console.log('\nPrice-related lines:');
  priceLines.slice(0, 30).forEach(l => console.log('  >', l.trim()));

  // Get all elements with price classes
  const priceEls = await page.$$eval('*', els => {
    return els
      .filter(el => {
        const cls = el.className ? el.className.toString() : '';
        const text = el.innerText ? el.innerText.trim() : '';
        return (
          cls.toLowerCase().includes('price') ||
          cls.toLowerCase().includes('cost') ||
          cls.toLowerCase().includes('retail') ||
          (text.includes('$') && text.length < 50)
        );
      })
      .slice(0, 30)
      .map(el => ({
        tag: el.tagName,
        cls: el.className ? el.className.toString().substring(0, 80) : '',
        text: el.innerText ? el.innerText.trim().substring(0, 100) : ''
      }));
  });
  console.log('\nPrice-like elements:', JSON.stringify(priceEls, null, 2));

  // Screenshot
  await page.screenshot({ path: '/tmp/thibaut-product.png', fullPage: false });
  console.log('\nScreenshot saved to /tmp/thibaut-product.png');

  // Try second product
  console.log('\n--- Testing T14340 ---');
  await page.goto('https://www.thibautdesign.com/products/wallcoverings/T14340', { waitUntil: 'networkidle2', timeout: 30000 });
  const bodyText2 = await page.evaluate(() => document.body.innerText);
  const priceLines2 = bodyText2.split('\n').filter(l =>
    l.toLowerCase().includes('price') || l.toLowerCase().includes('cost') || l.includes('$')
  );
  console.log('Price lines for T14340:');
  priceLines2.slice(0, 15).forEach(l => console.log('  >', l.trim()));

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