From 08f70b55b5dea4efc595cf99fa84fbd7b27adc7b Mon Sep 17 00:00:00 2001 From: John Pratt Date: Thu, 11 May 2023 11:11:41 -0600 Subject: [PATCH 1/2] Update adding-custom-assertions.md I would like to add a simpler example, one that may serve as a more basic option when trying to learn this. --- .../adding-custom-assertions.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/guide/extending-nightwatch/adding-custom-assertions.md b/guide/extending-nightwatch/adding-custom-assertions.md index e2c8585b..2241d781 100644 --- a/guide/extending-nightwatch/adding-custom-assertions.md +++ b/guide/extending-nightwatch/adding-custom-assertions.md @@ -124,6 +124,51 @@ Assertions implement a simple interface which is shared between built-in asserti }; + +Here is another example, potentially showing a simpler design. It polls the browser for a specific object made by another program. + +
globalObjectReady.js +
{
+//example of use: browser.assert.globalObjectReady("info");  
+
+GlobalObjectReady = function (info) {
+    this.message = `Testing if specificObject is on this page`;
+
+    this.expected = () => {
+        return true;
+    };
+
+    this.evaluate = (value) => {
+        return value;
+    };
+
+    this.value = (result) => {
+        return result.value;
+    };
+
+    this.command = (callback) => {
+        return this.api.execute(globalObjectCheck, [info], callback); 
+    };
+
+    async function globalObjectCheck(info){
+        //for illustrative purposes only
+        console.log(info);
+        
+        //check every 250 ms for the existence of a specific global object
+        for(let i=0; i<20; i++){
+            if(typeof specificObject === 'undefined'){
+                await new Promise(resolve => setTimeout(resolve, 250));
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
+};
+
+module.exports.assertion = GlobalObjectReady;
+
+ ### Recommended content - [Define custom commands](https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html) From 26830f78ad23203c907091c5509f806dc011c395 Mon Sep 17 00:00:00 2001 From: John Pratt Date: Fri, 12 May 2023 06:31:11 -0600 Subject: [PATCH 2/2] Update guide/extending-nightwatch/adding-custom-assertions.md Accepted Co-authored-by: Binayak Ghosh --- guide/extending-nightwatch/adding-custom-assertions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/extending-nightwatch/adding-custom-assertions.md b/guide/extending-nightwatch/adding-custom-assertions.md index 2241d781..f44048db 100644 --- a/guide/extending-nightwatch/adding-custom-assertions.md +++ b/guide/extending-nightwatch/adding-custom-assertions.md @@ -125,7 +125,7 @@ Assertions implement a simple interface which is shared between built-in asserti }; -Here is another example, potentially showing a simpler design. It polls the browser for a specific object made by another program. +Here is another example, it polls the browser for a specific object made by another program.
globalObjectReady.js
{