froth-webdriverio-framework 2.0.29 → 2.0.30
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/commonMethods/assertText.js +30 -21
- package/package.json +1 -1
|
@@ -2,35 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
async function assertText(driver, elementSelector, expectedText) {
|
|
4
4
|
|
|
5
|
-
try {
|
|
6
|
-
console.log("inside the assert text function" + elementSelector)
|
|
7
|
-
// Wait for the element to be visible
|
|
8
|
-
|
|
9
|
-
// Get the actual text from the element
|
|
10
|
-
// const element = await driver.$(elementSelector);
|
|
11
|
-
// console.log("actual text is:" + element)
|
|
12
|
-
let element = await $(elementSelector)
|
|
13
|
-
const actualText = await element.getText();
|
|
14
|
-
console.log("actual text is:" + status)
|
|
15
|
-
|
|
16
|
-
let status = await expect(element).toHaveText(expectedText)
|
|
17
5
|
|
|
18
|
-
|
|
6
|
+
console.log("inside the assert text function" + elementSelector)
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
let element = await $(elementSelector)
|
|
9
|
+
let assertionStatus = false; // Initialize status
|
|
10
|
+
try {
|
|
11
|
+
await expect(element).toHaveText(expectedText);
|
|
12
|
+
assertionStatus = true; // If assertion passes, set status to true
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.warn("Assertion failed:", error.message);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
let actualText;
|
|
18
|
+
// You can now use assertionStatus in your code
|
|
19
|
+
if (assertionStatus) {
|
|
20
|
+
console.log("Assertion succeeded.");
|
|
21
|
+
actualText = await element.getText();
|
|
22
|
+
console.log("actual text is:" + actualText);
|
|
23
|
+
let annotationMessage = `Assertion passed. Actual text: ${actualText}, Expected text: ${expectedText}.`;
|
|
24
|
+
await browser.execute(function () {
|
|
25
|
+
// Use BrowserStack's reporting API to log the success
|
|
26
|
+
window.parent.BrowserStack && window.parent.BrowserStack.addEvent('Passed', annotationMessage);
|
|
27
|
+
});
|
|
25
28
|
} else {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
console.log(`Assertion failed. Expected text: ,${expectedText}.`);
|
|
30
|
+
let annotationMessage = `Assertion failed. Expected text: ,${expectedText}.`;
|
|
31
|
+
|
|
32
|
+
await browser.execute(function () {
|
|
33
|
+
// Use BrowserStack's reporting API to log the failure
|
|
34
|
+
window.parent.BrowserStack && window.parent.BrowserStack.addEvent('Failed', annotationMessage);
|
|
35
|
+
});
|
|
29
36
|
}
|
|
30
37
|
} catch (error) {
|
|
31
38
|
console.error('Error occurred while verifying text:', error);
|
|
32
39
|
throw error;
|
|
33
40
|
}
|
|
41
|
+
|
|
42
|
+
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
module.exports = assertText;
|