@cuppet/core 1.0.11 → 1.0.12

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.
@@ -41,6 +41,11 @@ Then('I should see {string} in {string} region', async function (text, region) {
41
41
  await utils.seeTextInRegion(this.page, resolvedText, region);
42
42
  });
43
43
 
44
+ Then('I should not see {string} in {string} region', async function (text, region) {
45
+ const resolvedText = this.mlStrings[text] ?? text;
46
+ await utils.notSeeTextInRegion(this.page, resolvedText, region);
47
+ });
48
+
44
49
  Then('I should see the element with selector {string}', async function (cssSelector) {
45
50
  const selector = this.commonFields[cssSelector] ?? cssSelector;
46
51
  await utils.seeElement(this.page, selector);
@@ -25,4 +25,4 @@ class World {
25
25
  setWorldConstructor(World);
26
26
 
27
27
  // Export the World class for use in the main repository
28
- module.exports = { World };
28
+ module.exports = { World };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -411,6 +411,31 @@ module.exports = {
411
411
  }
412
412
  },
413
413
 
414
+ /**
415
+ * Validate that text is not visible in specific region (another element).
416
+ * To be used when multiple renders of the same text are shown on the page.
417
+ * @param {Page} page
418
+ * @param text
419
+ * @param region
420
+ * @param time
421
+ * @returns {Promise<void>}
422
+ */
423
+ notSeeTextInRegion: async function (page, text, region, time = 3000) {
424
+ const regionClass = await helper.getRegion(page, region);
425
+ const selector = 'xpath/' + `//*[contains(@class,'${regionClass}') and .//text()[contains(.,"${text}")]]`;
426
+ const options = {
427
+ visible: true, // With true flag it will fail only if the element is in the dom and visible
428
+ timeout: time, // Maximum time to wait in milliseconds (default is 30s which is a lot for a negative step)
429
+ };
430
+ try {
431
+ await page.waitForSelector(selector, options);
432
+ throw new Error(`Text ${text} is visible in ${regionClass}!`);
433
+ } catch {
434
+ // Element not visible - that's the expected result
435
+ return;
436
+ }
437
+ },
438
+
414
439
  /**
415
440
  * Hover element based on text content (useful for text inside spans, paragraphs etc. like menu links)
416
441
  * @param {Page} page