'use strict';

var appFrame   = require('../../bellows/pages/appFrame.js');
var body     = require('../../bellows/pages/pageBody.js');
afterEach(function() {
  //browser.ignoreSyncronization = true;
  appFrame.errorMessage.isPresent().then(function(isPresent) {
    if (isPresent) {
      appFrame.errorMessage.getText().then(function(message) {
        if (message.indexOf('Oh. Exception') != -1) {
          console.log("PHP API error on this page");
          console.log(message);
          expect(true).toBe(false); // fail the test
        }
      });
    }
  });
  body.phpError.isPresent().then(function(isPresent) {
    if (isPresent) {
      console.log("PHP Error present on this page");
      expect(true).toBe(false); // fail the test
    }
  });

  // output JS console errors and fail tests
  browser.manage().logs().get('browser').then(function(browserLog) {
    if (browserLog.length > 0) {
      for (var i=0;i<browserLog.length;i++) {
        var message = browserLog[i].message;
        if (message.indexOf('\n') != -1) {
          message = message.substring(0, message.indexOf('\n'));
        }
        if (/angular\.js .* TypeError: undefined is not a function/.test(message)) {
          // we ignore errors of this type caused by Angular being unloaded prematurely on page refreshes (since it's not a real error)

        } else {
          console.log("Browser Console JS Error: " + message);
          console.log('');
          expect(true).toBe(false); // fail the test
        }

      }
    }
  });
  //browser.ignoreSyncronization = false;
});
@@ -399,36 +399,34 @@
 %7B%0A          
-console.log(
+message = 
 %22PHP API err
@@ -444,42 +444,21 @@
 page
-%22);%0A          console.log(
+: %22 + 
 message
-)
 ;%0A  
@@ -472,32 +472,35 @@
  expect(
-true).toBe(false
+message).toEqual(''
 ); // fa
@@ -625,28 +625,83 @@
 %7B%0A      
-console.log(
+body.phpError.getText().then(function(message) %7B%0A        message = 
 %22PHP Err
@@ -727,18 +727,28 @@
 page
-%22)
+:%22 + message
 ;%0A      
 expe
@@ -743,39 +743,44 @@
 ;%0A      
+  
 expect(
-true).toBe(false
+message).toEqual(''
 ); // fa
@@ -787,24 +787,34 @@
 il the test%0A
+      %7D);%0A
     %7D%0A  %7D);%0A
@@ -1419,28 +1419,26 @@
         
-console.log(
+message = 
 %22Browser
@@ -1471,71 +1471,46 @@
 sage
-);%0A          console.log('');%0A          expect(true).toBe(false
+;%0A          expect(message).toEqual(''
 ); /

make it easier to see the JS Console error in the test failure