Common Page Tests

Common Page Tests#

This section documents the common page tests used in the automation testing suite.

/**

* Setup a timestamped downloads folder (if needed)
 */
function setupDownloadDirectory(): string {
  const basePath = process.env.DOWNLOAD_DIR_BASE_PATH || path.join(__dirname, '../Downloads');
  const now = new Date();
  const pad = (num: number) => (num < 10 ? `0${num}` : `${num}`);
  const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(
    now.getHours()
  )}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
  const folder = path.join(basePath, stamp);
  fs.mkdirSync(folder, { recursive: true });
  return folder;
}

/** Basic login helper */
async function login(page: Page) {
  const user = process.env.CIT_APP_SUPER_ADMIN_LOGIN_NAME;
  const pass = process.env.CIT_APP_SUPER_ADMIN_LOGIN_PASS;

  if (!user || !pass) {
    throw new Error(
      'Must set CIT_APP_SUPER_ADMIN_LOGIN_NAME and CIT_APP_SUPER_ADMIN_LOGIN_PASS in env'
    );
  }

  console.info('[INFO] Logging in...');
  await page.goto(URL_CONFIG.loginUrl);
  await page.locator('#mat-input-0').fill(user);
  await page.locator('#mat-input-1').fill(pass);
  await page.getByRole('button', { name: 'Sign In' }).click();
  await takeNamedScreenshot(page, 'login', 'completed');
}

// Configure the suite so the tests run in serial (one after the other).

// ─────────────────────────────────────────────────────────────────────────────
// Test Suite: Example – Using a Single Shared Page
// ─────────────────────────────────────────────────────────────────────────────
test.describe.serial('Billing & Invoices Tests (Shared Page)', () => {
  let context: BrowserContext;
  let page: Page;

  test.beforeAll(async ({ browser }) => {
    try {
      context = await browser.newContext();
      page = await context.newPage();
      page.setDefaultTimeout(60_000);
      await page.setViewportSize({ width: 1280, height: 720 });
      await login(page);
      await clickDropdownFromSideBar(page, 'local_offerInvestment', 'Monthly & Quarterly');
    } catch (err) {
      console.error('[beforeAll] Setup failed:', err);
      if (page) await page.close().catch(() => {});
      if (context) await context.close().catch(() => {});
      throw err;
    }
  });
  
  test('Monthly and Quarterly Investment Summary Test - Check Table Headers', async () => {

    // Apply Status filter using existing helper

    /*
    const statuses = [
      'All', 
      'Open & Payment Received', 
      'Canceled/Failed', 
      'Open',
      'Payment Received', 
      'Shares Issued', 
      'Cashout'
    ];

    for (const status of statuses) {
      await filterInvestments(page, status, 'All');
    }
    */

    await selectDropdown(page, "Choose CIT Corporation");

    await selectDropdownValue(page, "East Portland CIT");

    const tableNames = [
      "Monthly Summary",
      "Quarterly Summary"
    ];

    const columnConfig = {
      "Monthly Summary": columnNames.Investment.MonthlyQuarterly,
      "Quarterly Summary": columnNames.Investment.MonthlyQuarterly
    };

    for (const tableName of tableNames) {
      await checkColumnHeaders(page, columnConfig[tableName], tableName);
    }
    
  });

  test('Monthly and Quarterly Investment Summary Test - Download Excel', async () => {

    const locatorName = [
      "app-monthly-summary",
      "app-quarterly-summary"
    ];
    
    for (const tableName of locatorName) {
      await downloadFile(page, "Export to Excel", "./Downloads", false, 10000, tableName);
    }

    await takeNamedScreenshot(page, "Monthly and Quarterly Investment Summary", "completed");

  });

  test.afterAll(async () => {
    try { if (page) await page.close(); } catch (e) { console.error("[afterAll] Error closing page:", e); }
    try { if (context) await context.close(); } catch (e) { console.error("[afterAll] Error closing context:", e); }
  });
});

```