while (element not present) {pause then refresh the page}

56 views
Skip to first unread message

Brian Annett

unread,
Jan 20, 2021, 11:52:53 AM1/20/21
to NightwatchJs
I'm trying to test a notification element, which wont be present when this part of the test executes but will arrive. 
The notifications are a bit slow and require a page refresh to become visible.

The trouble with my approach below is that I don't know how to return the continueLooping from within the function, to then break out of the while loop. 

Q: How can I return continueLooping, OR is there a simpler approach?

let continueLooping = true
while(loopCount++ <= loopCountMax && continueLooping) {
   this.assert.not.elementPresent("@bellIconRedDot", results => {
      results.abortOnFailure = false // Set to 'false' so that we don't fail on the above error
      if (results == true) {  // Notification not present so pause then refresh
         browser.pause(2000)
         browser.refresh()
      } else { // if it's not true we must have a red dot!
         continueLooping = false
      }
   }
}

Zachary Betz

unread,
Jan 20, 2021, 12:01:59 PM1/20/21
to NightwatchJs
I would use the built-in expect api. For example, refresh the page, then wait for 15 secs for the element to be present:

browser.refresh();
browser.expect
.element('@bellIconRedDot')
.to.be.present
.before(15 * 1000);

Brian Annett

unread,
Jan 20, 2021, 12:57:46 PM1/20/21
to NightwatchJs
But the notification is not displayed until after it's both received and the page is then refreshed. 
So you could do the following and the notification would never be displayed if it hadn't been received at the first refresh
browser.refresh();
browser.expect.element('@bellIconRedDot').to.be.present.before(1500000 * 1000);

Zachary Betz

unread,
Jan 20, 2021, 12:59:43 PM1/20/21
to nightw...@googlegroups.com
It's time to have a talk with your developers :)

A page refresh should not be necessary in order to see a notification. 

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/eb8f8d41-f98f-43a9-9e7b-faae3654ded5n%40googlegroups.com.

Brian Annett

unread,
Jan 22, 2021, 6:31:43 AM1/22/21
to NightwatchJs
So to clarify, whilst I wait for this low priority fix to bubble up the developers backlog. 
In Nightwatch it is not possible to get a value returned from code such as below?


this.assert.not.elementPresent("@bellIconRedDot", results => {
      results.abortOnFailure = false // Set to 'false' so that we don't fail on the above error
      // return some_value ?
}
console.log("My returned value was ", some_value)


Zachary Betz

unread,
Jan 22, 2021, 8:07:20 AM1/22/21
to nightw...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages