Skip to content

Commit f1a298b

Browse files
committed
Playwright JavaScript Automation Framework
1 parent 92dac73 commit f1a298b

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export async function waitUntilAppIdle(page) {
2+
try {
3+
await page.waitForFunction(() => (window).UCWorkBlockTracker?.isAppIdle());
4+
} catch (e) {
5+
console.log("waitUntilIdle failed, ignoring.., error: " + e?.message);
6+
}
7+
}
8+
9+
export const stringFormat = (str, ...args) =>
10+
str.replace(/{(\d+)}/g, (match, index) => args[index].toString() || "");
11+
12+
export async function navigateToApps(page, appId, appName) {
13+
console.log('Navigate to ' + appName.toString() + ' - Start');
14+
await page.goto('/main.aspx?appid=' + appId.toString());
15+
await expect(page.getByRole('button', { name: appName })).toBeTruthy();
16+
console.log('Navigated to ' + appName.toString() + '- Success');
17+
}
18+
19+
/**
20+
* Load state conditions.
21+
*/
22+
export let LoadState
23+
; (function (LoadState) {
24+
LoadState["DomContentLoaded"] = "domcontentloaded"
25+
LoadState["Load"] = "load"
26+
LoadState["NetworkIdle"] = "networkidle"
27+
})(LoadState || (LoadState = {}))
28+
29+
export let TimeOut; (function (TimeOut) {
30+
TimeOut[(TimeOut["DefaultLoopWaitTime"] = 5000)] = "DefaultLoopWaitTime"
31+
TimeOut[(TimeOut["DefaultWaitTime"] = 30000)] = "DefaultWaitTime"
32+
TimeOut[(TimeOut["DefaultMaxWaitTime"] = 180000)] = "DefaultMaxWaitTime"
33+
TimeOut[(TimeOut["DefaultWaitTimeForValidation"] = 30000)] =
34+
"DefaultWaitTimeForValidation"
35+
TimeOut[(TimeOut["ElementWaitTime"] = 2000)] = "ElementWaitTime"
36+
TimeOut[(TimeOut["ExpectRetryDefaultWaitTime"] = 30000)] =
37+
"ExpectRetryDefaultWaitTime"
38+
TimeOut[(TimeOut["LoadTimeOut"] = 60000)] = "LoadTimeOut"
39+
TimeOut[(TimeOut["NavigationTimeout"] = 60000)] = "NavigationTimeout"
40+
TimeOut[(TimeOut["PageLoadTimeOut"] = 30000)] = "PageLoadTimeOut"
41+
TimeOut[(TimeOut["TestTimeout"] = 360000)] = "TestTimeout"
42+
TimeOut[(TimeOut["TestTimeoutMax"] = 6000000)] = "TestTimeoutMax"
43+
TimeOut[(TimeOut["OneMinuteTimeOut"] = 60000)] = "OneMinuteTimeOut"
44+
TimeOut[(TimeOut["TwoMinutesTimeout"] = 120000)] = "TwoMinutesTimeout"
45+
TimeOut[(TimeOut["ThreeMinutesTimeout"] = 180000)] = "ThreeMinutesTimeout"
46+
TimeOut[(TimeOut["FourMinutesTimeout"] = 240000)] = "FourMinutesTimeout"
47+
TimeOut[(TimeOut["FiveMinutesTimeout"] = 300000)] = "FiveMinutesTimeout"
48+
})(TimeOut || (TimeOut = {}))
49+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* author: Bakkappa N
3+
*/
4+
export async function ZoomIn(page, zoomLevel) {
5+
const totalZoomLevel = parseFloat(zoomLevel);
6+
await page.evaluate((zoomLevel) => {
7+
document.body.style.zoom = zoomLevel;
8+
}, totalZoomLevel);
9+
}
10+
11+
/**
12+
* author: Bakkappa N
13+
*/
14+
export async function ScrollToHeight() {
15+
await page.evaluate(() => {
16+
window.scrollTo(0, document.body.scrollHeight);
17+
});
18+
}
19+
20+
/**
21+
* author: Bakkappa N
22+
*/
23+
export async function ScrollByLabel() {
24+
let isElementPresent = true;
25+
while (isElementPresent) {
26+
let isElement = await page.getByLabel('label', { exact : true}).isVisible();
27+
if (isElement) {
28+
await page.evaluate(() => {
29+
window.scrollBy(0, 100);
30+
});
31+
break;
32+
} else {
33+
await page.keyboard.press('PageDown');
34+
await page.waitForTimeout(1000);
35+
isElementPresent = true;
36+
}
37+
}
38+
}
39+
40+
/**
41+
* author: Bakkappa N
42+
*/
43+
export async function ZoomToEightyPercent() {
44+
await page.evaluate(() => {
45+
document.body.style.transform = 'scale(0.8)';
46+
document.body.style.transformOrigin = '0 0';
47+
document.body.style.width = '125%';
48+
document.body.style.height = '125%';
49+
});
50+
}
51+

0 commit comments

Comments
 (0)