Files
cannaiq/backend/test-curaleaf-playwright-advanced.ts
2025-11-28 19:45:44 -07:00

164 lines
5.2 KiB
TypeScript

import { chromium } from 'playwright';
const TEST_URL = 'https://curaleaf.com/stores/curaleaf-dispensary-48th-street';
async function testCuraleafAdvanced() {
console.log('\n🎭 Testing Curaleaf with Advanced Playwright Techniques\n');
const browser = await chromium.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
});
try {
const context = await browser.newContext({
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
viewport: { width: 1280, height: 720 },
locale: 'en-US',
timezoneId: 'America/Phoenix',
geolocation: { longitude: -112.0740, latitude: 33.4484 }, // Phoenix, AZ
permissions: ['geolocation']
});
const page = await context.newPage();
// Navigate directly
console.log('📍 Navigating to age gate page...');
await page.goto(TEST_URL, { waitUntil: 'networkidle', timeout: 60000 });
const currentUrl = page.url();
console.log(`Current URL: ${currentUrl}`);
if (!currentUrl.includes('/age-gate')) {
console.log('✅ No age gate - page loaded directly!');
return;
}
console.log('\n📍 Age gate detected. Analyzing page structure...');
// Wait for age gate to fully render
await page.waitForTimeout(2000);
// Take screenshot
await page.screenshot({ path: '/tmp/curaleaf-adv-before.png', fullPage: true });
console.log('📸 Before screenshot: /tmp/curaleaf-adv-before.png');
// Get all interactive elements
console.log('\n🔍 Finding interactive elements...');
// Method 1: Check for the state dropdown using multiple selectors
const dropdownSelectors = [
'button#state',
'button[id="state"]',
'[role="combobox"]',
'button:has-text("Select")',
'button:has-text("State")'
];
let dropdownFound = false;
for (const selector of dropdownSelectors) {
const count = await page.locator(selector).count();
if (count > 0) {
console.log(`✅ Found dropdown with selector: ${selector}`);
dropdownFound = true;
// Click to open
await page.locator(selector).first().click();
await page.waitForTimeout(1500);
// Look for Arizona in various ways
const arizonaSelectors = [
'[role="option"]:has-text("Arizona")',
'text=Arizona',
'[data-value="Arizona"]',
'[data-value="AZ"]'
];
for (const azSelector of arizonaSelectors) {
const azCount = await page.locator(azSelector).count();
if (azCount > 0) {
console.log(`✅ Found Arizona with selector: ${azSelector}`);
await page.locator(azSelector).first().click();
await page.waitForTimeout(2000);
// Take screenshot after state selection
await page.screenshot({ path: '/tmp/curaleaf-adv-after-state.png' });
console.log('📸 After state selection: /tmp/curaleaf-adv-after-state.png');
// Look for continue/submit button
const submitSelectors = [
'button:has-text("Continue")',
'button:has-text("Submit")',
'button:has-text("Enter")',
'button:has-text("Confirm")',
'button[type="submit"]',
'a:has-text("Continue")'
];
for (const submitSel of submitSelectors) {
const submitCount = await page.locator(submitSel).count();
if (submitCount > 0) {
console.log(`✅ Found submit button: ${submitSel}`);
// Click and wait for navigation
const [response] = await Promise.all([
page.waitForNavigation({ timeout: 10000 }).catch(() => null),
page.locator(submitSel).first().click()
]);
await page.waitForTimeout(3000);
break;
}
}
break;
}
}
break;
}
}
if (!dropdownFound) {
console.log('❌ No dropdown found. Checking page HTML...');
const html = await page.content();
console.log('\nPage HTML (first 1000 chars):');
console.log(html.substring(0, 1000));
}
// Check final state
const finalUrl = page.url();
console.log(`\nFinal URL: ${finalUrl}`);
await page.screenshot({ path: '/tmp/curaleaf-adv-final.png', fullPage: true });
console.log('📸 Final screenshot: /tmp/curaleaf-adv-final.png');
if (finalUrl.includes('/age-gate')) {
console.log('❌ Still at age gate');
// Try to get cookies anyway
const cookies = await context.cookies();
console.log('\nCurrent cookies:');
cookies.forEach(c => console.log(` ${c.name}: ${c.value}`));
} else {
console.log('✅ Successfully bypassed age gate!');
// Save successful cookies
const cookies = await context.cookies();
console.log('\nSuccessful cookies:');
cookies.forEach(c => console.log(` ${c.name}: ${c.value}`));
}
} catch (error) {
console.error('❌ Error:', error);
} finally {
await browser.close();
console.log('\n✅ Test completed');
}
}
testCuraleafAdvanced();