sefiutils 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/seUtils.ts +18 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sefiutils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Utilities (and Jest/Vitest tests) for Selenium Webdriver Tests and some React tools as well",
|
|
5
5
|
"author": "Jens von Pilgrim <jens.vonpilgrim@bht-berlin.de>",
|
|
6
6
|
"license": "EPL-2.0",
|
package/src/seUtils.ts
CHANGED
|
@@ -116,14 +116,22 @@ export async function waitFor<T>(callback: () => Promise<T>, timeout = 1000, int
|
|
|
116
116
|
/**
|
|
117
117
|
* Takes screenshot of current window and saves it to the given file.
|
|
118
118
|
* The folder is created if it does not yet exists.
|
|
119
|
+
*
|
|
120
|
+
* @param fileName the file name to save the screenshot to, e.g. "screenshots/test.png", if null or empty, no screenshot is saved.
|
|
121
|
+
* @param pngProcessor optional function to process the png data, e.g., for creating a hash (or comparision with a reference png). The png data is given as base64 string.
|
|
119
122
|
*/
|
|
120
|
-
export async function saveScreenshot(driver: WebDriver, fileName: string): Promise<void> {
|
|
123
|
+
export async function saveScreenshot(driver: WebDriver, fileName: string | null, pngProcessor?: (png: string) => void): Promise<void> {
|
|
121
124
|
const pngBase64 = await driver.takeScreenshot();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
if (pngProcessor) {
|
|
126
|
+
pngProcessor(pngBase64);
|
|
127
|
+
}
|
|
128
|
+
if (fileName) {
|
|
129
|
+
const dirName = path.dirname(fileName);
|
|
130
|
+
if (!fs.existsSync(dirName)) {
|
|
131
|
+
await fsPromises.mkdir(dirName, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
await fsPromises.writeFile(fileName, pngBase64, 'base64');
|
|
125
134
|
}
|
|
126
|
-
await fsPromises.writeFile(fileName, pngBase64, 'base64');
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
|
|
@@ -736,7 +744,7 @@ export function findBestMatchingIndex(candidates: string[], variations: string[]
|
|
|
736
744
|
return -1;
|
|
737
745
|
}
|
|
738
746
|
|
|
739
|
-
export type InputElementByLabelResultType = [WebElement|undefined, string|undefined, "child"|"for"|"near"|"type"|"not found"];
|
|
747
|
+
export type InputElementByLabelResultType = [WebElement | undefined, string | undefined, "child" | "for" | "near" | "type" | "not found"];
|
|
740
748
|
|
|
741
749
|
/**
|
|
742
750
|
* Returns the best matching input element identified by the given label candidates.
|
|
@@ -754,9 +762,9 @@ export type InputElementByLabelResultType = [WebElement|undefined, string|undefi
|
|
|
754
762
|
* @return The input element (or undefined), the associated label (or undefined) and how the input element was found (child, for, near, type or not found)
|
|
755
763
|
* @package findSelectAsWell If true, select elements are also considered; otherwise, only input and textarea elements are considered
|
|
756
764
|
*/
|
|
757
|
-
export async function getInputElementByLabel(driver: WebDriver,
|
|
758
|
-
|
|
759
|
-
|
|
765
|
+
export async function getInputElementByLabel(driver: WebDriver,
|
|
766
|
+
labelCandidates: string[], typeHints: string[], positionHint = -1, findSelectAsWell = false
|
|
767
|
+
)
|
|
760
768
|
: Promise<InputElementByLabelResultType> {
|
|
761
769
|
const tagsToFind = ["input", "textarea"];
|
|
762
770
|
labelCandidates = labelCandidates.map(l => l.toLowerCase());
|
|
@@ -769,7 +777,7 @@ export async function getInputElementByLabel(driver: WebDriver,
|
|
|
769
777
|
const txtLabels: string[] = [];
|
|
770
778
|
for (const weLabel of weLabels) {
|
|
771
779
|
try {
|
|
772
|
-
const text = (await weLabel.getText()).toLowerCase().replace(/:\s*/,"").trim();
|
|
780
|
+
const text = (await weLabel.getText()).toLowerCase().replace(/:\s*/, "").trim();
|
|
773
781
|
txtLabels.push(text);
|
|
774
782
|
} catch (error) {
|
|
775
783
|
txtLabels.push("");
|