Skip to content

Instantly share code, notes, and snippets.

@adenta
Created July 2, 2024 16:13
Show Gist options
  • Save adenta/e695b74efd0464e0ca7f24a873e9ade7 to your computer and use it in GitHub Desktop.
Save adenta/e695b74efd0464e0ca7f24a873e9ade7 to your computer and use it in GitHub Desktop.
import { test, expect } from '@playwright/test';
import crypto from "node:crypto"
const anthemDownload = (username, password) => {
test('Anthem Download', async ({ page }) => {
await page.goto('https://brokerportal.anthem.com/apps/ptb/login');
await page.getByPlaceholder('Enter your username').click();
await page.getByPlaceholder('Enter your username').fill(username);
await page.getByPlaceholder('Enter your password').click();
await page.getByPlaceholder('Enter your password').fill(password);
await page.getByRole('button', { name: 'Log In' }).click();
await page.getByRole('button', { name: 'View All Commissions' }).click();
// this should be fine/consistant. id="30" is not some dynamically generated ID, but rather the page container.
await page.locator('[id="\\30 arrow"]').click();
const downloadPromise = page.waitForEvent('download');
await page.locator('[id="\\30 "]').getByText('CSV').click();
const download1 = await downloadPromise;
// In a production system, you will probably want to write this somewhere ephemeral, like tmp
await download1.saveAs(`${__dirname}/${crypto.randomUUID()}_` + download1.suggestedFilename());
});
}
import { test, expect } from '@playwright/test';
import crypto from "node:crypto"
function getPreviousMonthDates() {
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
const endOfMonth = new Date(now.getFullYear(), now.getMonth(), 0);
const startDate = formatDate(startOfMonth);
const endDate = formatDate(endOfMonth);
return { startDate, endDate };
}
function formatDate(date) {
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const year = date.getFullYear();
return `${month}/${day}/${year}`;
}
const humanaDownload = (username, password)=>{
test('Humana Download', async ({ page }) => {
const previousMonthDates = getPreviousMonthDates();
await page.goto('https://account.humana.com/');
await page.getByLabel('Username', { exact: true }).click();
await page.getByLabel('Username', { exact: true }).fill(username);
await page.getByLabel('Password', { exact: true }).click();
await page.getByLabel('Password', { exact: true }).fill(password);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByRole('button', { name: 'Agent' }).click();
await page.locator('.styles_modalHeader__O67Im > .styles_icon__8VpeW').click();
await page.getByText('Quick Links').click();
const page1Promise = page.waitForEvent('popup');
await page.getByText('Commission Statement Portal').click();
const page1 = await page1Promise;
await page1.getByText('Prior Statement(s) by Date Range From Date: * From Date - Required Thru Date').click();
await page1.getByRole('img', { name: 'Show' }).click();
await page1.locator('#ctl00_ContentPlaceHolder1_TabControl_CommissionStatementsTab_ucCommnStatementsUserControl_dtcDRFromDate').fill(previousMonthDates.startDate);
await page1.locator('#ctl00_ContentPlaceHolder1_TabControl_CommissionStatementsTab_ucCommnStatementsUserControl_dtcDRThruDate').fill(previousMonthDates.endDate);
await page1.getByRole('button', { name: 'Submit' }).click();
const downloadPromise = page1.waitForEvent('download');
await page1.locator('#ctl00_ContentPlaceHolder1_TabControl_CommissionStatementsTab_ucCommnStatementsUserControl_gvCommStatementByDateRangeParent_ctl02_gvCommStatementByDateRangeParent_lbtnDownloadExcel').click();
const download1 = await downloadPromise;
// In a production system, you will probably want to write this somewhere ephemeral, like tmp
await download1.saveAs(`${__dirname}/${crypto.randomUUID()}_` + download1.suggestedFilename());
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment