-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy.spec.ts
85 lines (63 loc) · 3 KB
/
my.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {test, expect, Browser, Page, Locator, FrameLocator} from '@playwright/test'
import { doesNotThrow, strict } from 'assert';
import * as fs from 'fs';
import * as path from 'path';
import { time } from 'console';
import { webkit, firefox, chromium } from 'playwright'
import { TIMEOUT } from 'dns';
test('basic test', async ({ }) => {
const outputPath = path.join(__dirname, 'bruh.pdf' );
const browser:Browser = await chromium.launch({ headless: false, channel: 'chrome'})
const context = await browser.newContext()
const page:Page = await context.newPage()
// Enable request interception
await context.route('**/*', async (route) => {
const response = await route.fetch();
const headers = response.headers();
const contentType = headers['content-type'];
const contentDisposition = headers['content-disposition'];
if (contentType?.includes('application/pdf') || contentDisposition?.includes('filename=')) {
const buffer = await response.body();
route.continue()
fs.writeFileSync(outputPath, buffer);
console.log(`PDF downloaded to: ${outputPath}`);
} else {
route.continue();
}
});
await page.goto('https://assessmentonline.naac.gov.in/public/index.php/hei_dashboard' , {waitUntil: 'networkidle'})
await page.waitForSelector('select[name="state"]')
await page.selectOption('select[name="state"]', '99')
await page.click('button[id="showbtn"]')
await page.locator('//*[@id="details_table_length"]/label/select').selectOption('100')
// change i=1 to 100 when ready
for (let i = 0; i <=2; i++) {
if (i == null)
break
if(i < 2){
if (page.getByRole('link' , {name: 'view'}).nth(i) != null)
{
await page.getByRole('link' , {name: 'view'}).nth(i).click()
await page.waitForSelector('div[id="modal_box"]')
const pagePromise = context.waitForEvent('page')
await page.click('div[class="col-md-3"] a[href*= "https://assessmentonline.naac.gov.in/public/index.php/ssr_report/"]')
const newPage = await pagePromise;
await newPage.waitForLoadState()
console.log(`New tab opened with URL: ${newPage.url()}`);
await newPage.bringToFront();
await page.waitForTimeout(5000)
await page.waitForSelector('div[id="modal_box"]')
await page.click('button[class="close"]')
continue
}
else
break
}
if (i == 2)
{
await page.getByRole('link' , {name: 'Next'}).click()
i=-1
continue
}
}
})