139 lines
5 KiB
TypeScript
139 lines
5 KiB
TypeScript
import { Browser } from '@stock-bot/browser';
|
|
|
|
async function testWithoutProxy() {
|
|
console.log('🔬 Testing WITHOUT proxy...');
|
|
|
|
try {
|
|
await Browser.initialize({ headless: true, timeout: 15000, blockResources: false });
|
|
console.log('✅ Browser initialized');
|
|
|
|
const { page, contextId } = await Browser.createPageWithProxy(
|
|
'https://www.interactivebrokers.com/en/trading/products-exchanges.php#/'
|
|
// No proxy parameter
|
|
);
|
|
console.log('✅ Page created without proxy');
|
|
|
|
let eventCount = 0;
|
|
let summaryData: SummaryResponse | null = null;
|
|
|
|
page.onNetworkEvent(event => {
|
|
eventCount++;
|
|
|
|
// Capture the summary API response
|
|
if (event.url.includes('/webrest/search/product-types/summary')) {
|
|
console.log(`🎯 Found summary API call: ${event.type} ${event.url}`);
|
|
|
|
if (event.type === 'response' && event.responseData) {
|
|
console.log(`📊 Summary API Response Data: ${event.responseData}`);
|
|
try {
|
|
summaryData = JSON.parse(event.responseData) as any;
|
|
const totalCount = summaryData[0].totalCount;
|
|
console.log('📊 Summary API Response:', JSON.stringify(summaryData, null, 2));
|
|
console.log(`🔢 Total symbols found: ${totalCount || 'Unknown'}`);
|
|
} catch (e) {
|
|
console.log('📊 Raw Summary Response:', event.responseData);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Uncomment to see all network events
|
|
// console.log(`📡 Event ${eventCount}: ${event.type} ${event.url}`);
|
|
});
|
|
|
|
console.log('⏳ Waiting for page load...');
|
|
await page.waitForLoadState('domcontentloaded', { timeout: 15000 });
|
|
console.log('✅ Page loaded');
|
|
|
|
// Complete interaction flow
|
|
try {
|
|
console.log('🔍 Looking for Products tab...');
|
|
await page.waitForTimeout(3000);
|
|
|
|
const productsTab = page.locator('#productSearchTab[role="tab"][href="#products"]');
|
|
await productsTab.waitFor({ timeout: 10000 });
|
|
console.log('✅ Found Products tab');
|
|
|
|
console.log('🖱️ Clicking Products tab...');
|
|
await productsTab.click();
|
|
console.log('✅ Products tab clicked');
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
console.log('🔍 Looking for Asset Classes accordion...');
|
|
const assetClassesAccordion = page.locator(
|
|
'#products .accordion-item #acc-products .accordion_btn:has-text("Asset Classes")'
|
|
);
|
|
await assetClassesAccordion.waitFor({ timeout: 10000 });
|
|
console.log('✅ Found Asset Classes accordion');
|
|
|
|
console.log('🖱️ Clicking Asset Classes accordion...');
|
|
await assetClassesAccordion.click();
|
|
console.log('✅ Asset Classes accordion clicked');
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
console.log('🔍 Looking for Stocks checkbox...');
|
|
const stocksSpan = page.locator('span.fs-7.checkbox-text:has-text("Stocks")');
|
|
await stocksSpan.waitFor({ timeout: 10000 });
|
|
console.log('✅ Found Stocks span');
|
|
|
|
const parentContainer = stocksSpan.locator('..');
|
|
const checkbox = parentContainer.locator('input[type="checkbox"]');
|
|
|
|
if ((await checkbox.count()) > 0) {
|
|
console.log('📋 Clicking Stocks checkbox...');
|
|
await checkbox.first().check();
|
|
console.log('✅ Stocks checkbox checked');
|
|
} else {
|
|
console.log('⚠️ Could not find checkbox near Stocks text');
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
console.log('🔍 Looking for Apply button...');
|
|
const applyButton = page.locator(
|
|
'button:has-text("Apply"), input[type="submit"][value*="Apply"], input[type="button"][value*="Apply"]'
|
|
);
|
|
|
|
if ((await applyButton.count()) > 0) {
|
|
console.log('🎯 Clicking Apply button...');
|
|
await applyButton.first().click();
|
|
console.log('✅ Apply button clicked');
|
|
await page.waitForTimeout(3000);
|
|
} else {
|
|
console.log('⚠️ Could not find Apply button');
|
|
}
|
|
} catch (interactionError) {
|
|
const errorMessage =
|
|
interactionError instanceof Error ? interactionError.message : String(interactionError);
|
|
console.error('❌ Page interaction failed:', errorMessage);
|
|
}
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
console.log(`📊 Total events captured: ${eventCount}`);
|
|
|
|
// Show final results
|
|
if (summaryData) {
|
|
console.log('✅ SUCCESS: Captured summary data!');
|
|
console.log(`🔢 Final total count: ${summaryData?.data?.totalCount || 'Unknown'}`);
|
|
console.log(`📋 Data keys: ${Object.keys(summaryData).join(', ')}`);
|
|
} else {
|
|
console.log('❌ No summary data captured');
|
|
}
|
|
|
|
await Browser.closeContext(contextId);
|
|
await Browser.close();
|
|
|
|
console.log('✅ Test completed successfully');
|
|
return true;
|
|
} catch (error) {
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
console.error('❌ Error:', errorMessage);
|
|
await Browser.close();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
testWithoutProxy().then(success => {
|
|
console.log(`🏁 Final result: ${success ? 'SUCCESS' : 'FAILED'}`);
|
|
});
|