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

Script Validation is very quiet


#1

Hello all,

My question is: How can I test a browser script in such a way that if it is syntactically correct I can see the output of the validation test or values in the vars being used? Is this even possible as when I validate I don’t get much feedback from it…

I am currently working on automating a web login to an ASP web service page and would like see which elements of the page are called/used correctly or not as I am assume that is where my issue is with the failure of the validation…

Thanks for any help with this or some advice on how to handle that…


#2

Hi, @Wren: This is typically accomplished with console.log() statements:

var By = $driver.By;
var until = $driver.until;
var assert = require('assert');

var rootUrl = 'http://ec2-35-162-124-87.us-west-2.compute.amazonaws.com:8080/#';

// Sample customer names
var customers = [ 'New Relic', 'Phil Weber', 'J. Bieber', 'T. Swiffer', 'A. Grande' ];

// Restaurants and items to order
var orders = [
  {"restaurant": "Beijing Express", "items": [4, 5, 9, 11]},
  {"restaurant": "Naan Sequitur", "items": [3, 2, 14, 6]}, 
  {"restaurant": "Czech Point", "items": [7, 5]},
  {"restaurant": "Hit Me Baby One More Thai", "items": [9, 10, 16, 3]},
  {"restaurant": "Curry Galore", "items": [4, 3, 15, 7]}, 
  {"restaurant": "Esther's German Saloon", "items": [6, 18]},
  {"restaurant": "Super Wonton Express", "items": [4, 5, 9, 11]},
  {"restaurant": "Curry Up", "items": [3, 2, 14, 6]}
];

// Select random customer
var customerId = Math.floor(Math.random() * 5);
var customerName = customers[customerId++];

// Select random restaurant order
var orderId = Math.floor(Math.random() * 8);
var order = orders[orderId++];

$browser.get(rootUrl)
  .then(function() {
    return $browser.get(rootUrl + '/customer')
    .then(function() {
      return $browser.findElement(By.id('customerName'));
    })
    .then(function(element) {
        console.log('Found customerName element');
        return element.sendKeys(customerName);
    })
    .then(function() {
        $browser.findElement(By.id('address')).sendKeys('111 SW Fifth Ave #2800, Portland, OR 97205');
        console.log('Entered address');
        $browser.findElement(By.css('button.btn.btn-primary')).click();
    });
}).then(function() {
    return $browser.get(rootUrl + '/')
      .then(function() {
        return $browser.findElement(By.linkText(order.restaurant));
      })    
      .then(function(element) {
        console.log('Found restaurant name');
        return element.click();
      })
      .then(function() {
        return order.items.forEach(orderItem);
      });
}).then(function() {
  $browser.findElement(By.linkText('Checkout')).click();

  $browser.findElement(By.name('ccType')).sendKeys('v');
  $browser.findElement(By.name('ccNum')).sendKeys('4388123412341234');
  $browser.findElement(By.name('ccExp')).sendKeys('08/2020');
  $browser.findElement(By.name('ccCvc')).sendKeys('123');
  $browser.findElement(By.css('button.btn.btn-primary')).click();
}).then(function() {
  $browser.waitForPendingRequests(30000);
});

function orderItem(item) {
  $browser.findElement(By.css('.fm-menu-list > ul > :nth-child(' + item + ') .icon-plus-sign'))
    .then(function(element) {
      $browser.actions().mouseMove(element).perform().then(
        function() {
          element.click();
        });
    });
}

When you run the script, the log entries appear below the validation screenshot:

synthetics-console-log


#3

Thanks @philweber. I will give this a shot in my work this week. I was glad to see that when I ran this example script of yours initially that I got output both related to the browser data and the extra in the log…makes me feel better to see additional information making out of my testing.


#4

Let us know how you get on when you try adding some additional logging :smiley: