Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Promises and Return



I’m new to new relic, I just want to know what would be the difference between the codes below.

A.) return $browser.takeScreenshot();
B.) $browser.takeScreenshot();

A.) .then(function() {
return $browser.findElement(By.css(‘name=name’)).click();
B.) .then(function() {
return $browser.findElement(By.css(’’)).click()


Hi @markj.v

basically to sequence the actions, we need to use the .then(function)

if you are using just $browser.takescreenshot, that it will be executed at any sequence, where as if you use it in .then function and do a return that it comes in the sequence it is.

( as per the documentation) Because WebDriverJS is asynchronous, scripting actions can sometimes execute out of order. For example, in a script containing three functions, the third function might execute before the second function. To force script actions to execute in order, wrap each action in a then(function(){}) call

Hope this help.



Hi @MKhanna, the link you provided is very helpful, but why does the new relic work even i don’t append “return” for every action I make. It makes me confuse whether to use “return” for every action or not.


Depending on the response times of each function, it is possible not to use the return statement but if any start to take longer you may see unexpected results.

Chaining the promises ensures that they always fire in the order you specify.


Thank you @stefan_garnham, this is very helpful


Awesome explanation @stefan_garnham I could not find words to explain this one.

thanks :slight_smile: I learnt something too :slight_smile:


Hey @markj.v - welcome to the New Relic community! Looks like the three of you got this ironed out, but let us know if you are looking for anything else. Thanks @MKhanna and @stefan_garnham - ya’ll are amazing!