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

Get external data and use results in script elsewhere

synthetics-script
developer

#1

This example makes a http request and uses the resulting data to fill in a form in the script. It could be extended to pull externally stored credentials and pass them in to prevent needing to save plain text credentials into Synthetics directly.

//This script makes a REST call then uses the results later in the script to fill in form data
var request = require('urllib-sync').request;
//Make a REST call to get some geolocation data
var result = request('http://gd.geobytes.com/GetCityDetails');

$browser.get('https://google.com').then(function(){
  var parsedResponse = JSON.parse(result.data.toString('utf-8'));
  return parsedResponse;
}).then(function(parsedResponse){
  console.log("Search for "+parsedResponse.geobytescity);
  $browser.findElement($driver.By.id('lst-ib')).sendKeys(parsedResponse.geobytescity+"\n");
}).then(function(){
  $browser.waitForAndFindElement($driver.By.xpath('//*[@id="rso"]/div[2]/li[1]/div/h3/a'));
});

Configuration files and upload files
POM (Page Object Model) DesignPattern with New Relic Synthetics