Skip to content

Commit b67c761

Browse files
committed
added few more methods
1 parent 1b529ca commit b67c761

5 files changed

Lines changed: 186 additions & 139 deletions

File tree

Notes

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,9 @@ function createLocatorHelper(page) {
6666
console.warn(`Error while finding element with ${type} locator: ${value}. Error: ${error.message}`);
6767
return null;
6868
}
69-
},
69+
}
70+
7071

71-
/**
72-
* Finds all elements using the specified locator strategy
73-
* @param {string} type - Locator type
74-
* @param {string} value - Locator value
75-
* @param {Object} [options] - Optional locator options
76-
* @returns {Promise<import('@playwright/test').Locator>} Playwright locator for all matching elements
77-
*/
78-
async findAllElements(type, value, options = {}) {
79-
try {
80-
const result = await this.findElement(type, value, options);
81-
if (!result) return [];
82-
return result.locator.all();
83-
} catch (error) {
84-
console.warn(`Failed to find all elements with ${type} locator: ${value}. Error: ${error.message}`);
85-
return [];
86-
}
87-
},
8872

8973
/**
9074
* Waits for an element to be visible using the specified locator strategy
@@ -104,49 +88,8 @@ function createLocatorHelper(page) {
10488
} catch (error) {
10589
throw new Error(`Failed to wait for element with ${type} locator: ${value}. Error: ${error.message}`);
10690
}
107-
},
108-
109-
/**
110-
* Stores a locator with a key for later use
111-
* @param {string} key - Unique key to identify the locator
112-
* @param {string} type - Locator type
113-
* @param {string} value - Locator value
114-
* @param {Object} [options] - Optional locator options
115-
* @returns {Promise<void>}
116-
*/
117-
async storeLocator(key, type, value, options = {}) {
118-
try {
119-
const result = await this.findElement(type, value, options);
120-
if (!result) {
121-
throw new Error(`Cannot store null locator with key ${key}`);
122-
}
123-
locatorStorage.set(key, { type, value, options, locator: result.locator });
124-
} catch (error) {
125-
throw new Error(`Failed to store locator with key ${key}. Error: ${error.message}`);
126-
}
127-
},
128-
129-
/**
130-
* Retrieves a stored locator by key
131-
* @param {string} key - Key used to store the locator
132-
* @returns {Promise<import('@playwright/test').Locator>} Stored Playwright locator
133-
*/
134-
async getStoredLocator(key) {
135-
const stored = locatorStorage.get(key);
136-
if (!stored) {
137-
throw new Error(`No locator found with key: ${key}`);
138-
}
139-
// Recreate locator to ensure it's fresh
140-
const result = await this.findElement(stored.type, stored.value, stored.options);
141-
return result ? result.locator : null;
142-
},
143-
144-
/**
145-
* Clears all stored locators
146-
*/
147-
clearStoredLocators() {
148-
locatorStorage.clear();
14991
}
92+
15093
};
15194
}
15295

playwright.config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export default defineConfig({
4949
headless: Config.HEADLESS_BROWSER,
5050
baseURL: Config.BASE_URL,
5151
screenshot: "on",
52-
video: "on",
53-
storageState:"auth.json",
52+
video: "on",
53+
storageState: "auth.json",
5454
},
5555

5656
/* Configure projects for major browsers */
@@ -112,9 +112,9 @@ export default defineConfig({
112112

113113

114114
/* Run your local dev server before starting the tests */
115-
webServer: {
116-
command: 'npm run mock-data',
117-
url: 'http://localhost:3001',
118-
reuseExistingServer: !process.env.CI,
119-
},
115+
// webServer: {
116+
// command: 'npm run mock-data',
117+
// url: 'http://localhost:3001',
118+
// reuseExistingServer: !process.env.CI,
119+
// },
120120
});

src/helper/Helper.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import { step } from "../utils/report/ReportAction";
33

44
export class Helper {
5+
// Internal storage for locators
6+
const locatorStorage = new Map();
57

6-
/**
7-
* The `delay` function is an asynchronous function that waits for a specified amount of time before
8-
* resolving.
9-
* @param {number} time - The `time` parameter is a number that represents the duration of the delay
10-
* in seconds.
11-
* @returns a Promise that resolves to void.
12-
*/
8+
/**
9+
* The `delay` function is an asynchronous function that waits for a specified amount of time before
10+
* resolving.
11+
* @param {number} time - The `time` parameter is a number that represents the duration of the delay
12+
* in seconds.
13+
* @returns a Promise that resolves to void.
14+
*/
1315
@step('delay')
1416
async delay(time: number): Promise<void> {
1517
return new Promise(function (resolve) {
@@ -30,4 +32,13 @@ export class Helper {
3032
return false;
3133
}
3234
}
35+
36+
/**
37+
* Clears all stored locators
38+
*/
39+
clearStoredLocators() {
40+
this.locatorStorage.clear();
41+
}
42+
43+
3344
}

0 commit comments

Comments
 (0)