@cuppet/core 1.0.11 → 1.0.13

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/README.md CHANGED
@@ -137,6 +137,12 @@ Make sure to install these in your project:
137
137
  yarn install @cucumber/cucumber config
138
138
  ```
139
139
 
140
+ ## Contributing
141
+
142
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to submit pull requests and our development workflow.
143
+
144
+ For detailed development setup and publishing information, check out our [Development Guide](developmentGuide.md).
145
+
140
146
  ## License
141
147
 
142
148
  ISC
@@ -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);
@@ -49,9 +54,13 @@ Then('I should see the element with selector {string} in the DOM', async functio
49
54
  const selector = this.commonFields[cssSelector] ?? cssSelector;
50
55
  await utils.seeElement(this.page, selector, false);
51
56
  });
57
+ Then('I should not see the element with selector {string} in the DOM', async function (cssSelector) {
58
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
59
+ await utils.notSeeElement(this.page, selector, false);
60
+ });
52
61
  Then('I should not see the element with selector {string}', async function (cssSelector) {
53
62
  const selector = this.commonFields[cssSelector] ?? cssSelector;
54
- await utils.notSeeElement(this.page, selector);
63
+ await utils.notSeeElement(this.page, selector, true);
55
64
  });
56
65
  Then('I wait for element {string} to disappear within {string} seconds', async function (cssSelector, time) {
57
66
  const selector = this.commonFields[cssSelector] ?? cssSelector;
@@ -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.13",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -311,13 +311,15 @@ module.exports = {
311
311
  },
312
312
 
313
313
  /**
314
- * Element should not exist in the page DOM.
314
+ * Verify whether element is visible or not.
315
+ * Depending on VisibleInDOM boolean will check if it is only hidden or not present in the DOM.
315
316
  * @param {Page} page
316
317
  * @param selector
318
+ * @param VisibleInDOM
317
319
  * @param time
318
320
  * @returns {Promise<void>}
319
321
  */
320
- notSeeElement: async function (page, selector, time = 5000) {
322
+ notSeeElement: async function (page, selector, VisibleInDOM, time = 5000) {
321
323
  const options = {
322
324
  hidden: true,
323
325
  timeout: time, // Maximum time to wait in milliseconds (default: 30000)
@@ -328,8 +330,8 @@ module.exports = {
328
330
  } catch {
329
331
  throw new Error('Element is visible!');
330
332
  }
331
- if (isElementInPage) {
332
- throw new Error(`${selector} is hidden but can be found in the page source!`);
333
+ if (!VisibleInDOM && isElementInPage) {
334
+ throw new Error(`${selector} is hidden but can be found in the page source (DOM)!`);
333
335
  }
334
336
  },
335
337
 
@@ -411,6 +413,31 @@ module.exports = {
411
413
  }
412
414
  },
413
415
 
416
+ /**
417
+ * Validate that text is not visible in specific region (another element).
418
+ * To be used when multiple renders of the same text are shown on the page.
419
+ * @param {Page} page
420
+ * @param text
421
+ * @param region
422
+ * @param time
423
+ * @returns {Promise<void>}
424
+ */
425
+ notSeeTextInRegion: async function (page, text, region, time = 3000) {
426
+ const regionClass = await helper.getRegion(page, region);
427
+ const selector = 'xpath/' + `//*[contains(@class,'${regionClass}') and .//text()[contains(.,"${text}")]]`;
428
+ const options = {
429
+ visible: true, // With true flag it will fail only if the element is in the dom and visible
430
+ timeout: time, // Maximum time to wait in milliseconds (default is 30s which is a lot for a negative step)
431
+ };
432
+ try {
433
+ await page.waitForSelector(selector, options);
434
+ throw new Error(`Text ${text} is visible in ${regionClass}!`);
435
+ } catch {
436
+ // Element not visible - that's the expected result
437
+ return;
438
+ }
439
+ },
440
+
414
441
  /**
415
442
  * Hover element based on text content (useful for text inside spans, paragraphs etc. like menu links)
416
443
  * @param {Page} page