diff --git a/guide/extending-nightwatch/adding-custom-assertions.md b/guide/extending-nightwatch/adding-custom-assertions.md index e2c8585b..f44048db 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, it polls the browser for a specific object made by another program. + +
{
+//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;
+