froth-webdriverio-framework 2.0.29 → 2.0.31
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 +24 -20
- package/package.json +1 -1
|
@@ -2,35 +2,39 @@
|
|
|
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
5
|
|
|
16
|
-
|
|
6
|
+
console.log("inside the assert text function" + elementSelector)
|
|
17
7
|
|
|
18
|
-
|
|
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 driver.execute('browserstack_executor: {"action": "annotate", "arguments": {"data":"Assertion passed. Actual text:'+ actualText+ '","level": "info"}}');
|
|
19
25
|
|
|
20
|
-
// Compare the actual text with the expected text
|
|
21
|
-
if (status) {
|
|
22
|
-
let annotationMessage = `Assertion pass. Actual text: ${actualText}, Expected text: ${expectedText}.`;
|
|
23
|
-
console.log(`Assertion pass. Actual text: ${actualText}, Expected text: ${expectedText}.`);
|
|
24
|
-
// await driver.execute(`browserstack_executor: {"action": "annotate", "arguments": {"data":"${annotationMessage}","level": "info"}}`);
|
|
25
26
|
} else {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
console.log(`Assertion failed. Expected text: ,${expectedText}.`);
|
|
28
|
+
let annotationMessage = `Assertion failed. Expected text: ,${expectedText}.`;
|
|
29
|
+
await driver.execute('browserstack_executor: {"action": "annotate", "arguments": {"data":"Assertion failed. Expected text:'+ expectedText+ '","level": "error"}}');
|
|
30
|
+
|
|
29
31
|
}
|
|
30
32
|
} catch (error) {
|
|
31
33
|
console.error('Error occurred while verifying text:', error);
|
|
32
34
|
throw error;
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
module.exports = assertText;
|