0

I want to check for specific console logs during my tests with

it('should return logs', function(done) {
  browser
      .log('browser').then(function(logs){
        console.log(logs);
      })
  ...
});

What I get is:

[ { level: 'INFO',
    message: 'https://localhost:3000/ 42:14 "foo"',
    timestamp: 1485785320222 },
  { level: 'INFO',
    message: 'https://localhost:3000/ 43:14 "bar"',
    timestamp: 1485785320222 },
  { level: 'INFO',
    message: 'https://localhost:3000/ 46:14 Array[6]',
    timestamp: 1485785320225 },
  { level: 'SEVERE',
    message: 'https://localhost:3000/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)',
    timestamp: 1485785320298 } ]

So it should just returns a list of log entries like "foo" and "bar", so I can check if it is equal to my assumed value it should be.

I am now unsure if I need a "for..in" to build my method that I can reuse or just loop through the multiple objects and looking for logs.value.message and trim the part with "".

1 Answer 1

1

It's probably easiest / most understandable to just filter for the logs that match what you're looking for:

it('should return logs', function(done) {
  browser
      .log('browser').then(function(logs){
        console.log(logs.filter(function (logItem) {
          return logItem.message.match(/"foo"|"bar"$/);
        });
      })
  ...
});
Sign up to request clarification or add additional context in comments.

1 Comment

It works when I specifically want to search for "foo" or "bar" but the goal behind is to have a helper function at the end, that just returns a list of log entries, so I can work with them later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.