How to use logEvent method in Playwright Internal

Best JavaScript code snippet using playwright-internal

log-event-spec.js

Source:log-event-spec.js Github

copy

Full Screen

1// Copyright 2015, EMC, Inc.2'use strict';3describe('LogEvent', function () {4 var LogEvent;5 var lookupService;6 helper.before();7 before(function () {8 LogEvent = helper.injector.get('LogEvent');9 lookupService = helper.injector.get('Services.Lookup');10 });11 helper.after();12 describe('Class Methods', function() {13 describe('sanitize', function() {14 it('should not remove fields not marked for sanitization', function() {15 LogEvent.sanitize(16 { foo: 'bar' }17 ).should.deep.equal({ foo: 'bar' });18 });19 it('should remove fields marked for sanitization', function() {20 LogEvent.sanitize(21 { ip: '127.0.0.1', foo: 'bar' }22 ).should.deep.equal({ foo: 'bar' });23 });24 it('should not remove nested fields marked for sanitization', function() {25 LogEvent.sanitize(26 { foo: { ip: '127.0.0.1' } }27 ).should.deep.equal({ foo: { ip: '127.0.0.1' } });28 });29 });30 describe('redact', function() {31 var testRedactKeys = ['password', 'PASSWORD', 'serverPassword', 'plainPassword',32 'Password123', 'pppassword', 'encryptedPasswords', 'community'];33 var testNotRedactKeys = ['pass_word', 'foobar', 'Community', 'community123',34 'acommunity', 'p.assword'];35 before('redact', function() {36 //intentionally add some non-supported redactions to verify they are ignored37 LogEvent.initRedact([/password/i, 'community', 123, ['a', 'b']]);38 });39 it('should have initialized the RegExp redaction pattern in advance', function() {40 LogEvent._redactPatterns.should.be.an.array;41 LogEvent._redactPatterns.should.have.length(2);42 _.isRegExp(LogEvent._redactPatterns[0]).should.be.true;43 LogEvent._redactPatterns[0].toString().should.equal('/password/i');44 });45 it('should have kept the String redaction pattern of its original type', function() {46 LogEvent._redactPatterns[1].should.be.a('string');47 LogEvent._redactPatterns[1].toString().should.equal('community');48 });49 it('should not redact fields not marked for redaction', function() {50 _.forEach(testNotRedactKeys, function(key) {51 var srcObj = {};52 srcObj[key] = 'bar';53 LogEvent.redact(srcObj).should.deep.equal(srcObj);54 });55 });56 it('should redact fields which are marked for redaction', function() {57 _.forEach(testRedactKeys, function(key) {58 var srcObj = {}, dstObj = {};59 srcObj[key] = 'bar';60 dstObj[key] = '[REDACTED]';61 LogEvent.redact(srcObj).should.deep.equal(dstObj);62 });63 });64 it('should redact fields in nested objects', function() {65 _.forEach(testRedactKeys, function(key) {66 var srcObj = { nested: {} };67 var dstObj = { nested: {} };68 srcObj.nested[key] = 'bar';69 dstObj.nested[key] = '[REDACTED]';70 LogEvent.redact(srcObj).should.deep.equal(dstObj);71 });72 });73 it('should redact fields in nested arrays', function() {74 _.forEach(testRedactKeys, function(key) {75 var srcObj = { array: [ {} ] };76 var dstObj = { array: [ {} ] };77 srcObj.array[0][key] = 'bar';78 dstObj.array[0][key] = '[REDACTED]';79 LogEvent.redact(srcObj).should.deep.equal(dstObj);80 });81 });82 it('should not modify the original object', function () {83 _.forEach(testRedactKeys, function(key) {84 var target = {};85 target[key] = 'bar';86 var cloneTarget = _.cloneDeep(target);87 LogEvent.redact(target);88 target.should.deep.equal(cloneTarget);89 });90 });91 describe('LogEvent.testRedact', function() {92 it('should return false if the tested value is not string', function() {93 _.forEach([1, {foo: 'bar'}, null, ['a', 'b'] ], function(val) {94 LogEvent.testRedact(val).should.be.false;95 });96 });97 });98 });99 describe('getUniqueId', function() {100 var sandbox;101 before(function() {102 sandbox = sinon.sandbox.create();103 });104 afterEach(function() {105 sandbox.restore();106 });107 it('should return undefined for empty context', function() {108 return LogEvent.getUniqueId().should.become(undefined);109 });110 it('should favor context.id', function() {111 return LogEvent.getUniqueId({112 id: 'testid',113 macaddress: 'testmac',114 ip: 'testip'115 }).should.become('testid');116 });117 it('should favor macaddress if id not exists', function() {118 sandbox.stub(lookupService, 'macAddressToNodeId')119 .withArgs('testmac').resolves('aa:bb:cc:dd:ee:ff');120 return LogEvent.getUniqueId({121 macaddress: 'testmac',122 ip: 'testip'123 }).should.become('aa:bb:cc:dd:ee:ff');124 });125 it('should reject if lookup macaddress fails', function() {126 sandbox.stub(lookupService, 'macAddressToNodeId')127 .withArgs('testmac').rejects();128 return LogEvent.getUniqueId({129 macaddress: 'testmac',130 ip: 'testip'131 }).should.be.rejected;132 });133 it('should favor ip if both id & macaddress not exists', function() {134 sandbox.stub(lookupService, 'ipAddressToNodeId')135 .withArgs('testip').resolves('192.168.100.1');136 return LogEvent.getUniqueId({137 ip: 'testip',138 other: 'testother'139 }).should.become('192.168.100.1');140 });141 it('should reject if lookup ip fails', function() {142 sandbox.stub(lookupService, 'ipAddressToNodeId')143 .withArgs('testip').rejects();144 return LogEvent.getUniqueId({145 ip: 'testip',146 other: 'testother'147 }).should.be.rejected;148 });149 it('should return undefined if id/macaddress/ip all not exist', function() {150 return LogEvent.getUniqueId({151 'test': 'testmessage',152 'abc': 'testabc'153 }).should.become(undefined);154 });155 });156 describe('getSubject', function() {157 var sandbox;158 before(function() {159 sandbox = sinon.sandbox.create();160 });161 afterEach(function() {162 sandbox.restore();163 });164 it('should return subject', function() {165 sandbox.stub(LogEvent, 'getUniqueId')166 .withArgs('testContext').resolves('testSubject');167 return LogEvent.getSubject('testContext').should.become('testSubject');168 });169 it('should return default subject if getUniqueId returns empty', function() {170 sandbox.stub(LogEvent, 'getUniqueId')171 .withArgs('testContext').resolves();172 return LogEvent.getSubject('testContext').should.become('Server');173 });174 it('should return default subject if getUniqueId rejects', function() {175 sandbox.stub(LogEvent, 'getUniqueId')176 .withArgs('testContext').rejects();177 return LogEvent.getSubject('testContext').should.become('Server');178 });179 });180 describe('setColorEnable', function() {181 var colors;182 before(function() {183 colors = helper.injector.get('colors');184 });185 it('should enable colors', function() {186 LogEvent.setColorEnable(true);187 expect(colors.enabled).to.be.true;188 expect(LogEvent.colorEnable).to.be.true;189 });190 it('should disable colors', function() {191 LogEvent.setColorEnable(false);192 expect(colors.enabled).to.be.false;193 expect(LogEvent.colorEnable).to.be.false;194 });195 });196 });...

Full Screen

Full Screen

browser-transmit.test.js

Source:browser-transmit.test.js Github

copy

Full Screen

1'use strict'2const test = require('tape')3const pino = require('../browser')4function noop () {}5test('throws if transmit object does not have send function', ({ end, throws }) => {6 throws(() => {7 pino({ browser: { transmit: {} } })8 })9 throws(() => {10 pino({ browser: { transmit: { send: 'not a func' } } })11 })12 end()13})14test('calls send function after write', ({ end, is }) => {15 let c = 016 const logger = pino({17 browser: {18 write: () => {19 c++20 },21 transmit: {22 send () { is(c, 1) }23 }24 }25 })26 logger.fatal({ test: 'test' })27 end()28})29test('passes send function the logged level', ({ end, is }) => {30 const logger = pino({31 browser: {32 write () {},33 transmit: {34 send (level) {35 is(level, 'fatal')36 }37 }38 }39 })40 logger.fatal({ test: 'test' })41 end()42})43test('passes send function message strings in logEvent object when asObject is not set', ({ end, same, is }) => {44 const logger = pino({45 browser: {46 write: noop,47 transmit: {48 send (level, { messages }) {49 is(messages[0], 'test')50 is(messages[1], 'another test')51 }52 }53 }54 })55 logger.fatal('test', 'another test')56 end()57})58test('passes send function message objects in logEvent object when asObject is not set', ({ end, same, is }) => {59 const logger = pino({60 browser: {61 write: noop,62 transmit: {63 send (level, { messages }) {64 same(messages[0], { test: 'test' })65 is(messages[1], 'another test')66 }67 }68 }69 })70 logger.fatal({ test: 'test' }, 'another test')71 end()72})73test('passes send function message strings in logEvent object when asObject is set', ({ end, same, is }) => {74 const logger = pino({75 browser: {76 asObject: true,77 write: noop,78 transmit: {79 send (level, { messages }) {80 is(messages[0], 'test')81 is(messages[1], 'another test')82 }83 }84 }85 })86 logger.fatal('test', 'another test')87 end()88})89test('passes send function message objects in logEvent object when asObject is set', ({ end, same, is }) => {90 const logger = pino({91 browser: {92 asObject: true,93 write: noop,94 transmit: {95 send (level, { messages }) {96 same(messages[0], { test: 'test' })97 is(messages[1], 'another test')98 }99 }100 }101 })102 logger.fatal({ test: 'test' }, 'another test')103 end()104})105test('supplies a timestamp (ts) in logEvent object which is exactly the same as the `time` property in asObject mode', ({ end, is }) => {106 let expected107 const logger = pino({108 browser: {109 asObject: true, // implicit because `write`, but just to be explicit110 write (o) {111 expected = o.time112 },113 transmit: {114 send (level, logEvent) {115 is(logEvent.ts, expected)116 }117 }118 }119 })120 logger.fatal('test')121 end()122})123test('passes send function child bindings via logEvent object', ({ end, same, is }) => {124 const logger = pino({125 browser: {126 write: noop,127 transmit: {128 send (level, logEvent) {129 const messages = logEvent.messages130 const bindings = logEvent.bindings131 same(bindings[0], { first: 'binding' })132 same(bindings[1], { second: 'binding2' })133 same(messages[0], { test: 'test' })134 is(messages[1], 'another test')135 }136 }137 }138 })139 logger140 .child({ first: 'binding' })141 .child({ second: 'binding2' })142 .fatal({ test: 'test' }, 'another test')143 end()144})145test('passes send function level:{label, value} via logEvent object', ({ end, is }) => {146 const logger = pino({147 browser: {148 write: noop,149 transmit: {150 send (level, logEvent) {151 const label = logEvent.level.label152 const value = logEvent.level.value153 is(label, 'fatal')154 is(value, 60)155 }156 }157 }158 })159 logger.fatal({ test: 'test' }, 'another test')160 end()161})162test('calls send function according to transmit.level', ({ end, is }) => {163 let c = 0164 const logger = pino({165 browser: {166 write: noop,167 transmit: {168 level: 'error',169 send (level) {170 c++171 if (c === 1) is(level, 'error')172 if (c === 2) is(level, 'fatal')173 }174 }175 }176 })177 logger.warn('ignored')178 logger.error('test')179 logger.fatal('test')180 end()181})182test('transmit.level defaults to logger level', ({ end, is }) => {183 let c = 0184 const logger = pino({185 level: 'error',186 browser: {187 write: noop,188 transmit: {189 send (level) {190 c++191 if (c === 1) is(level, 'error')192 if (c === 2) is(level, 'fatal')193 }194 }195 }196 })197 logger.warn('ignored')198 logger.error('test')199 logger.fatal('test')200 end()201})202test('transmit.level is effective even if lower than logger level', ({ end, is }) => {203 let c = 0204 const logger = pino({205 level: 'error',206 browser: {207 write: noop,208 transmit: {209 level: 'info',210 send (level) {211 c++212 if (c === 1) is(level, 'warn')213 if (c === 2) is(level, 'error')214 if (c === 3) is(level, 'fatal')215 }216 }217 }218 })219 logger.warn('ignored')220 logger.error('test')221 logger.fatal('test')222 end()223})224test('applies all serializers to messages and bindings (serialize:false - default)', ({ end, same, is }) => {225 const logger = pino({226 serializers: {227 first: () => 'first',228 second: () => 'second',229 test: () => 'serialize it'230 },231 browser: {232 write: noop,233 transmit: {234 send (level, logEvent) {235 const messages = logEvent.messages236 const bindings = logEvent.bindings237 same(bindings[0], { first: 'first' })238 same(bindings[1], { second: 'second' })239 same(messages[0], { test: 'serialize it' })240 is(messages[1].type, 'Error')241 }242 }243 }244 })245 logger246 .child({ first: 'binding' })247 .child({ second: 'binding2' })248 .fatal({ test: 'test' }, Error())249 end()250})251test('applies all serializers to messages and bindings (serialize:true)', ({ end, same, is }) => {252 const logger = pino({253 serializers: {254 first: () => 'first',255 second: () => 'second',256 test: () => 'serialize it'257 },258 browser: {259 serialize: true,260 write: noop,261 transmit: {262 send (level, logEvent) {263 const messages = logEvent.messages264 const bindings = logEvent.bindings265 same(bindings[0], { first: 'first' })266 same(bindings[1], { second: 'second' })267 same(messages[0], { test: 'serialize it' })268 is(messages[1].type, 'Error')269 }270 }271 }272 })273 logger274 .child({ first: 'binding' })275 .child({ second: 'binding2' })276 .fatal({ test: 'test' }, Error())277 end()278})279test('extracts correct bindings and raw messages over multiple transmits', ({ end, same, is }) => {280 let messages = null281 let bindings = null282 const logger = pino({283 browser: {284 write: noop,285 transmit: {286 send (level, logEvent) {287 messages = logEvent.messages288 bindings = logEvent.bindings289 }290 }291 }292 })293 const child = logger.child({ child: true })294 const grandchild = child.child({ grandchild: true })295 logger.fatal({ test: 'parent:test1' })296 logger.fatal({ test: 'parent:test2' })297 same([], bindings)298 same([{ test: 'parent:test2' }], messages)299 child.fatal({ test: 'child:test1' })300 child.fatal({ test: 'child:test2' })301 same([{ child: true }], bindings)302 same([{ test: 'child:test2' }], messages)303 grandchild.fatal({ test: 'grandchild:test1' })304 grandchild.fatal({ test: 'grandchild:test2' })305 same([{ child: true }, { grandchild: true }], bindings)306 same([{ test: 'grandchild:test2' }], messages)307 end()...

Full Screen

Full Screen

log-event.js

Source:log-event.js Github

copy

Full Screen

1// Copyright 2015, EMC, Inc.2'use strict';3module.exports = LogEventFactory;4LogEventFactory.$provide = 'LogEvent';5LogEventFactory.$inject = [6 'Errors',7 'Constants',8 'Serializable',9 'Services.Lookup',10 'Assert',11 '_',12 'Promise',13 'stack-trace',14 'colors',15 'prettyjson',16 'console'17];18function LogEventFactory (19 Errors,20 Constants,21 Serializable,22 lookupService,23 assert,24 _,25 Promise,26 stack,27 colors,28 pretty,29 console30) {31 //default turn off the colorful output to achieve tidy and clean log file.32 LogEvent.colorEnable = false;33 colors.setTheme(Constants.Logging.Colors); //setTheme will not impact color enable or not34 function LogEvent(defaults) {35 Serializable.call(this, LogEvent.schema, defaults);36 }37 LogEvent.schema = {38 id: 'LogEvent',39 type: 'object',40 properties: {41 package: {42 type: 'string',43 },44 host: {45 type: 'string'46 },47 module: {48 type: 'string'49 },50 level: {51 type: 'string',52 enum: _.keys(Constants.Logging.Levels)53 },54 message: {55 type: 'string'56 },57 context: {58 type: 'object'59 },60 timestamp: {61 type: 'string',62 },63 caller: {64 type: 'string'65 },66 subject: {67 type: 'string'68 }69 },70 required: [ 'module', 'level', 'timestamp', 'caller', 'subject' ]71 };72 Serializable.register(LogEventFactory, LogEvent);73 LogEvent.prototype.print = function () {74 var statement = [];75 this.context = LogEvent.redact(this.context);76 statement.push('[%s]'.format(this.level));77 statement.push('[%s]'.format(this.timestamp));78 statement.push('[%s]'.format(this.name));79 statement.push('[%s]'.format(this.module));80 statement.push('[%s]'.format(81 this.subject.substring(this.subject.length - Constants.Logging.Context.Length)82 ));83 statement.push(this.message);84 var output = statement.join(' ');85 console.log(colors[this.level](output));86 console.log(colors[this.level](' -> ' + this.caller));87 if (_.keys(this.context).length > 0) {88 console.log(89 pretty.render(90 this.context,91 {92 noColor: !LogEvent.colorEnable,93 numberColor: 'cyan'94 }95 )96 );97 }98 return this;99 };100 LogEvent.create = function (options) {101 assert.object(options, 'options');102 return LogEvent.getSubject(options.context)103 .then(function(subject) {104 options.context = LogEvent.sanitize(options.context);105 return new LogEvent(_.merge(options, { subject: subject }));106 }).then(function (object) {107 return object.validate();108 });109 };110 /**111 * Set enabled or disabled for colorful log112 * @param {boolean} enable - true to enable colorful log; false to disable113 */114 LogEvent.setColorEnable = function(enable) {115 LogEvent.colorEnable = (enable ? true : false);116 colors.enabled = LogEvent.colorEnable;117 };118 LogEvent.sanitize = function(context) {119 return _.omit(context, Constants.Logging.Sanitizations);120 };121 /**122 * Initialize the redact regex123 *124 * By initializing all the redact 'RegExp' pattern in advance can speed up the subsequent125 * testing; Keep the 'String` pattern of its original type can leverage the string comparasion126 * which is faster than regex.127 *128 * @param {Array} redactions - The array of regex129 */130 LogEvent.initRedact = function(redactions) {131 LogEvent._redactPatterns = _.reduce(redactions, function(result, value) {132 if (_.isString(value)) {133 result.push(value); //exactly full word match134 } else if (_.isRegExp(value)) {135 result.push(new RegExp(value));136 } else {137 console.log("warning: unsupported redaction type '" + typeof(value) + "', " +138 "only 'RegExp' and 'String' is allowed.");139 }140 return result;141 }, []);142 };143 /**144 * Test whether the value meet the redaction criteria145 * @param {String} value - the target value to test146 * @return {Boolean} true if it is need redaction, otherwise faluse147 */148 LogEvent.testRedact = function(value) {149 if (!_.isString(value)) {150 return false;151 }152 return _.some(LogEvent._redactPatterns, function(pattern) {153 if (_.isString(pattern)) {154 // The reason why use 'valueOf':155 // new String('abc') is not strictly equal to new String('abc'),156 // but new String('abc').valueOf() is strictly equal to new String('abc').valueOf()157 return (pattern.valueOf() === value.valueOf());158 }159 else { //Regex160 return pattern.test(value);161 }162 });163 };164 LogEvent.redact = function (target) {165 return LogEvent._redact(_.cloneDeep(target));166 };167 LogEvent._redact = function (target) {168 return _.transform(target, function (accumulator, value, key) {169 if (LogEvent.testRedact(key)) {170 accumulator[key] = '[REDACTED]';171 } else {172 accumulator[key] = value;173 }174 if (_.isObject(accumulator[key])) {175 accumulator[key] = LogEvent._redact(accumulator[key]);176 }177 if (_.isArray(accumulator[key])) {178 accumulator[key] = _.map(accumulator[key], function (item) {179 return LogEvent._redact(item);180 });181 }182 }, target || {});183 };184 LogEvent.getUniqueId = function(context) {185 if (_.isEmpty(context)) {186 return Promise.resolve();187 }188 if (context.id) {189 return Promise.resolve(context.id);190 }191 if (context.macaddress) {192 return lookupService.macAddressToNodeId(context.macaddress)193 .then(function (identifier) {194 return identifier;195 });196 }197 if (context.ip) {198 return lookupService.ipAddressToNodeId(context.ip)199 .then(function (identifier) {200 return identifier;201 });202 }203 // NOTE: This should not be reached204 return Promise.resolve();205 };206 LogEvent.getSubject = function(context) {207 var defaultSubject = 'Server';208 return LogEvent.getUniqueId(context)209 .then(function(subject) {210 return subject || defaultSubject;211 })212 .catch(function() {213 return defaultSubject;214 });215 };216 LogEvent.initRedact(Constants.Logging.Redactions);217 return LogEvent;...

Full Screen

Full Screen

FBAD.js

Source:FBAD.js Github

copy

Full Screen

...30 t.loadAd(3);31 setTimeout(function() { t.loadAd(4); }, 15e3);32 setTimeout(function() { t.loadAd(5); }, 20e3);33 } catch (err) {34 t.logEvent('FBAD2_con_Err');35 // console.log('FBAD constructor err:' + err.message);36 }37 }38 loadAd(idx, show) {39 let t = this;40 let info = (idx < 3 ? t.inter : t.video);41 try {42 // console.log('FBAD loadAd() start:' + idx);43 if (!info.support) {44 return;45 }46 let ad = t.ads[idx];47 if(ad.loaded)48 return;49 if(ad.item) {50 t._realLoad(idx, show);51 } else {52 if(idx < 3) {53 FBInstant.getInterstitialAdAsync(t.ids[idx]).then(function (inter) {54 // console.log('FBAD loadAd() getAsync:' + idx + ' success');55 ad.item = inter;56 return t._realLoad(idx, show);57 }).catch(function(e){58 // console.log('FBAD loadAd() getAsync:' + idx + ' catch:' + e.code + e.message);59 if(e.code == 'CLIENT_UNSUPPORTED_OPERATION') {60 info.support = false;61 } else {62 if(e.code == 'UNKNOWN') {63 t.logEvent('FBAD2_get_Unknown', {'type':idx});64 } else {65 t.logEvent('FBAD2_get_Err', {'type':idx,'code':e.code});66 }67 setTimeout(function() { t.loadAd(idx, show); }, 5e3);68 }69 });70 } else {71 FBInstant.getRewardedVideoAsync(t.ids[idx]).then(function (inter) {72 // console.log('FBAD loadAd() getAsync:' + idx + ' success');73 ad.item = inter;74 return t._realLoad(idx, show);75 }).catch(function(e){76 // console.log('FBAD loadAd() getAsync:' + idx + ' catch:' + e.code + e.message);77 if(e.code == 'CLIENT_UNSUPPORTED_OPERATION') {78 info.support = false;79 } else {80 if(e.code == 'UNKNOWN') {81 t.logEvent('FBAD2_get_Unknown', {'type':idx});82 } else {83 t.logEvent('FBAD2_get_Err', {'type':idx,'code':e.code});84 }85 setTimeout(function() { t.loadAd(idx, show); }, 5e3);86 }87 }); 88 }89 }90 } catch (err) {91 // console.log('FBAD_loadAd_try_Err:' + idx + ', err:' + err.message);92 t.logEvent('FBAD2_load_try_Err', {'type':idx,'msg':err.message});93 }94 }95 _realLoad(idx, show) {96 // console.log('FBAD _realLoad() start:' + idx);97 let t = this;98 let info = (idx < 3 ? t.inter : t.video);99 let ad = t.ads[idx];100 101 ad.item.loadAsync().then(function () {102 // console.log('FBAD _realLoad():' + idx + ' success');103 ad.loaded = true;104 if(show)105 t.showAd(idx < 3 ? 'inter' : 'video');106 }).catch(function (e) {107 // console.log('FBAD _realLoad() ' + idx + ' catch: ' + e.code + ', ' + e.message);108 if(e.code == 'CLIENT_UNSUPPORTED_OPERATION') {109 info.support = false;110 } else {111 let next = 5e3;112 switch(e.code) {113 case 'ADS_NO_FILL':114 t.logEvent('FBAD2_load_NoFill', {'type':idx});115 next = 3e4;116 break;117 case 'NETWORK_FAILURE':118 t.logEvent('FBAD2_load_NetFail', {'type':idx});119 break;120 case 'ADS_FREQUENT_LOAD':121 t.logEvent('FBAD2_load_Frequent', {'type':idx});122 next = 3e4;123 break;124 case 'UNKNOWN':125 t.logEvent('FBAD2_load_Unknown', {'type':idx});126 break;127 case 'INVALID_PARAM':128 t.logEvent('FBAD2_load_Invalid', {'type':idx});129 break;130 default:131 t.logEvent('FBAD2_load_Err', {'type':idx,'code':e.code});132 }133 setTimeout(function() { t.loadAd(idx, show); }, next);134 }135 });136 }137 canShowInter() {138 let now = new Date().getTime(); 139 if(now - this.inter.showTime > 3e4)140 for(let i = 0; i < 3; i++)141 if(this.ads[i].loaded)142 return true;143 return false;144 }145 canShowVideo() {146 for(let i = 3; i < 6; i++)147 if(this.ads[i].loaded)148 return true;149 return false;150 }151 showAd(place, cb) {152 let t = this;153 try {154 // console.log('FBAD showAd() start:' + place);155 if(place == 'video' && !t.video.support)156 place = 'inter';157 let info = null;158 let start = 0;159 if(place == 'inter') {160 info = t.inter;161 let now = new Date().getTime();162 if (!info.support || (now - info.showTime <= 3e4)) {163 // console.log('FBAD showAd() interval too small: ' + (now - info.showTime));164 cb && cb(false);165 return;166 }167 } else {168 info = t.video;169 start = 3;170 }171 let idx = -1;172 for(let i = start; i < start + 3; i++) {173 if(t.ads[i].loaded && !t.ads[i].showing) {174 idx = i;175 break;176 }177 }178 179 if(idx < 0) {180 cb && cb(false);181 return;182 }183 // console.log('FBAD showAd() idx:' + idx);184 let ad = t.ads[idx];185 ad.showing = true;186 if(ad.item) {187 ad.item.showAsync().then(function () {188 // console.log('FBAD showAd() showAsync:' + idx + ' success');189 cb && cb(true);190 ad.loaded = false;191 ad.showing = false;192 ad.item = null;193 info.showTime = new Date().getTime();194 t.loadAd(idx);195 }).catch(function (e) {196 // console.log('FBAD showAd() ' + idx + ' catch:' + e.code + ', ' + e.message);197 cb && cb(false);198 ad.showing = false;199 t.logEvent('FBAD2_show_Err', {'type':idx,'code':e.code});200 if(e.code == 'RATE_LIMITED') {201 } else if(e.code == 'PENDING_REQUEST') {202 } else if(e.code == 'INVALID_PARAM' || e.code == 'UNKNOWN') {203 ad.loaded = false;204 ad.item = null;205 t.loadAd(idx);206 } else {207 }208 });209 } else {210 cb && cb(false);211 }212 } catch (err) {213 // console.log('FBAD showAd ' + place + ' err:' + err.message);214 t.logEvent('FBAD2_show_try_Err', {'type':place,'msg':err.message});215 cb && cb(false);216 }217 }218 logEvent(name, param) {219 FBInstant.logEvent(name, 1, param);220 }...

Full Screen

Full Screen

ERRORCONTROL.JS

Source:ERRORCONTROL.JS Github

copy

Full Screen

1function showError(str,rsp){2 if (str == "ExpiredCard"){3 safeChangeScreen("ExpiredCard");4 logEvent(getScreenName(),"EXPIRED_CREDIT_CARD");5 } else6 if (str == "LogOff"){7 safeChangeScreen("LogOff");8 } else9 if (str == "badLogin" && rsp == "badSecurityLevel"){10 changeScreen("BadSecurityLevel");11 logEvent(getScreenName(),"BAD_SECURITY_LEVEL");12 } else13 if (str == "badLogin"){14 changeScreen("BadLogin");15 logEvent(getScreenName(),"BAD_LOGIN");16 } else17 if (str == "tooManyTries"){18 changeScreen("TooManyTries");19 logEvent(getScreenName(),"TOO_MANY_TRIES");20 } else21 if (str == "loginError"){22 logEvent(getScreenName(),"LOGIN_ERROR");23 changeScreen("LoginError");24 } else25 if (str == "badLoginSec" && rsp == "inactiveUser"){26 changeScreen("InactiveUser");27 logEvent(getScreenName(),"INACTIVE_USER");28 } else29 if (str == "badLoginSec"){30 changeScreen("BadLoginSec");31 logEvent(getScreenName(),"BAD_LOGIN");32 } else33 if (str == "outOfService"){3435 if (lastKioskUrl.indexOf("kioskShowTransfer") != -1) {36 logEvent(getScreenName(),"BCO_TRANSFER_ERROR");37 } else if (lastKioskUrl.indexOf("OpcionesPago") != -1) {38 logEvent(getScreenName(),"BCO_CARDPAYMENT_ERROR");39 } else {40 logEvent(getScreenName(),"OUT_OF_SERVICE");41 }42434445 changeScreen("OutOfService");464748 } else49 if (str == "tooManyClients"){50 changeScreen("TooManyClients");51 logEvent(getScreenName(),"TOO_MANY_CLIENTS");52 } else53 if (str == "noClients"){54 changeScreen("NoClients");55 logEvent(getScreenName(),"NO_CLIENTS");56 } else57 if (str == "noCreditCards"){58 changeScreen("NoCreditCards");59 logEvent(getScreenName(),"NO_CREDIT_CARDS");60 } else61 if (str == "noAccounts"){62 changeScreen("NoAccounts");63 logEvent(getScreenName(),"NO_ACCOUNTS");64 }else65 if (str == "statementError" && rsp == "006"){ // Estado de cuenta Invalido66 changeScreen("BadLastStatement");67 logEvent(getScreenName(),"STATEMENT_ERROR");68 }else69 if (str == "statementError"){70 changeScreen("OutOfService");71 logEvent(getScreenName(),"OUT_OF_SERVICE");72 }else73 if (str == "cardInvalidStatus"){ // Tarjeta con status invalido74 if (authenticated) {75 changeScreen("OutOfService");76 } else {77 changeScreen("InvalidCard");78 }79 logEvent(getScreenName(),"INVALID_CREDIT_CARD");80 }else81 if (str == "invalidCard"){82 changeScreen("InvalidCard");83 logEvent(getScreenName(),"UNKOWN_CREDIT_CARD");84 }else85 if (str == "unknownCard"){ // Tarjeta desconocida86 if (authenticated) {87 changeScreen("OutOfService");88 } else {89 changeScreen("InvalidCard");90 }91 logEvent(getScreenName(),"UNKOWN_CREDIT_CARD");92 }else93 if (str == "debitCardCreditBalance"){ // Consulta de Credito con tarjeta de credito94 changeScreen("BadComBalance");95 logEvent(getScreenName(),"DEBIT_CARD_CREDIT_BALANCE");96 }else97 if (str == "comBalanceError"){9899 if (lastKioskUrl.indexOf("kioskComPago") != -1) {100 logEvent(getScreenName(),"BCO_CARDPAYMENT_ERROR");101 } else {102 logEvent(getScreenName(),"COM_BALANCE_ERROR");103 }104105 changeScreen("OutOfService");106107 }else108 if (str == "bcoBalanceError"){109 changeScreen("OutOfService");110 logEvent(getScreenName(),"BCO_BALANCE_ERROR");111 }else112 if (str == "bcoStatementError"){113 changeScreen("OutOfService");114 logEvent(getScreenName(),"BCO_STATEMENT_ERROR");115 }else116 if (str == "opcStatementError"){117 changeScreen("OutOfService");118 logEvent(getScreenName(),"BCO_OPCSTATEMENT_ERROR");119 }else120 if (str == "sfiStatementError"){121 changeScreen("OutOfService");122 logEvent(getScreenName(),"BCO_SFISTATEMENT_ERROR");123 }else124 if (str == "comOperationsError"){125 changeScreen("OutOfService");126 logEvent(getScreenName(),"COM_OPERATIONS_ERROR");127 }else128 if (str == "comStatementError"){129 changeScreen("OutOfService");130 logEvent(getScreenName(),"COM_STATEMENT_ERROR");131 }else132 if (str == "bcoTransferError"){133 changeScreen("OutOfService");134 logEvent(getScreenName(),"BCO_TRANSFER_ERROR");135 }else136 if (str == "duplicateTransfer"){137 changeScreen("RepeatedTransfer");138 logEvent(getScreenName(),"REPEATED_TRANSFER");139 }else140 if (str == "bcoCardPaymentError"){141 changeScreen("OutOfService");142 logEvent(getScreenName(),"BCO_CARDPAYMENT_ERROR");143 }else144 if (str == "duplicateCardPayment"){145 changeScreen("RepeatedPayment");146 logEvent(getScreenName(),"REPEATED_PAYMENT");147 }else148 if (str == "noTransferAccounts"){149 changeScreen("NoTransferAccounts");150 logEvent(getScreenName(),"NO_TRANSFER_ACCOUNTS");151 }else152 if (str == "noProducts"){153 changeScreen("NoProducts");154 logEvent(getScreenName(),"NO_PRODUCTS");155 }else156 if (str == "noClientData"){157 changeScreen("LoginError");158 logEvent(getScreenName(),"NO_DATA_FOR_CLIENT");159 }else160 if (str == "notAvailable"){161 changeScreen("NotAvailable");162 logEvent(getScreenName(),"SERVER_ERROR");163 }else164 if (str == "transferAmountWarning"){165 changeScreen("OutOfService");166 logEvent(str,"TRANSFER_AMOUNT_WARNING");167 }else168 if (str == "bcoPasswordChangeError"){169 changeScreen("OutOfService");170 logEvent(str,"BCO_PASSCHANGE_ERROR");171 }else172 if (str == "comPasswordChangeError"){173 changeScreen("OutOfService");174 logEvent(str,"COM_PASSCHANGE_ERROR");175 }176177178179}180181182183function logEvent(msg,msg2){184 try{185 window.external.Document.Log("Custom Script","INFO",msg,msg2,kioskCredential,kioskLoginType,kioskCountry);186 }187 catch(e){188 //alert(e.description);189 } ...

Full Screen

Full Screen

AbstractLoggingMonitor.js

Source:AbstractLoggingMonitor.js Github

copy

Full Screen

...7 // ABSTRACT METHODS.8 // ---9 10 // I log the given Circuit Breaker state event.11 logEvent( eventType, eventData ) {12 throw( new Error( "logEvent() is an abstract method and must be overridden by a concrete class." ) );13 }14 // ---15 // PUBLIC METHODS.16 // ---17 // I log the point at which the Circuit Breaker state moves from opened to closed.18 logClosed( stateSnapshot ) {19 20 this.logEvent( "closed", { stateSnapshot } );21 }22 // I log the point at which the execution is accepted by the state of the Circuit 23 // Breaker and the underlying command is about to be invoked.24 logExecute( stateSnapshot ) {25 26 this.logEvent( "execute", { stateSnapshot } );27 }28 // I log the point at which the request has entered the Circuit Breaker but has not29 // yet been approved for execution.30 logEmit( stateSnapshot ) {31 32 this.logEvent( "emit", { stateSnapshot } );33 }34 // I log the point at which the execution has ended in error. This only accounts for35 // non-Circuit Breaker errors (see, logTimeout() and logShortCircuited() events).36 logFailure( stateSnapshot, duration, error ) {37 38 this.logEvent( "failure", { stateSnapshot, duration, error } );39 }40 // I log the point at which a non-successful execution (due to error, timeout, or41 // short-circuiting) is being evaluated for a fallback response.42 logFallbackEmit( stateSnapshot ) {43 44 this.logEvent( "fallbackEmit", { stateSnapshot } );45 }46 // I log the point at which an existing fallback function resolved in error.47 logFallbackFailure( stateSnapshot, error ) {48 49 this.logEvent( "fallbackFailure", { stateSnapshot, error } );50 }51 // I log the point at which a failed execution has no fallback defined.52 logFallbackMissing( stateSnapshot ) {53 54 this.logEvent( "fallbackMissing", { stateSnapshot } );55 }56 // I log the point at which a fallback value has successfully stood-in for a failed 57 // or bypassed execution.58 logFallbackSuccess( stateSnapshot ) {59 60 this.logEvent( "fallbackSuccess", { stateSnapshot } );61 }62 // I log the point at which the Circuit Breaker state moves from closed to opened.63 logOpened( stateSnapshot ) {64 65 this.logEvent( "opened", { stateSnapshot } );66 }67 // I log the point at which an execution is bypassed because the Circuit Breaker is68 // currently in an opened state.69 logShortCircuited( stateSnapshot, error ) {70 71 this.logEvent( "shortCircuited", { stateSnapshot, error } );72 }73 // I log the point at which an execution has resolved successfully.74 logSuccess( stateSnapshot, duration ) {75 76 this.logEvent( "success", { stateSnapshot, duration } );77 }78 // I log the point at which a long-running execution has been explicitly timed-out79 // in error.80 logTimeout( stateSnapshot, duration, error ) {81 82 this.logEvent( "timeout", { stateSnapshot, duration, error } );83 }84 85 // ---86 // STATIC METHODS.87 // ---88 // I create a concrete implementation of the Abstract Logging Monitor, using the 89 // given Function as the logEvent() override.90 static usingFunction( logEvent ) {91 var monitor = new AbstractLoggingMonitor();92 // Override the abstract method, completing the implementation.93 monitor.logEvent = logEvent;94 return( monitor );95 }96}97// ----------------------------------------------------------------------------------- //98// ----------------------------------------------------------------------------------- //...

Full Screen

Full Screen

events.js

Source:events.js Github

copy

Full Screen

...5 maxZoom: 19,6 attribution:7 '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',8}).addTo(map);9function logEvent(e) {10 console.log(e);11}12map.on('pm:drawstart', function (e) {13 logEvent(e);14 var layer = e.workingLayer;15 layer.on('pm:vertexadded', logEvent);16 layer.on('pm:snapdrag', logEvent);17 layer.on('pm:snap', logEvent);18 layer.on('pm:unsnap', logEvent);19 layer.on('pm:centerplaced', logEvent);20});21map.on('pm:drawend', logEvent);22map.on('pm:create', function (e) {23 logEvent(e);24 var layer = e.layer;25 map.pm.disableDraw();26 layer.pm.enable({27 allowSelfIntersection: false,28 });29 //Edit Event30 layer.on('pm:edit', logEvent);31 layer.on('pm:update', logEvent);32 layer.on('pm:enable', logEvent);33 layer.on('pm:disable', logEvent);34 layer.on('pm:vertexadded', logEvent);35 layer.on('pm:vertexremoved', logEvent);36 layer.on('pm:markerdragstart', logEvent);37 layer.on('pm:markerdrag', logEvent);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...4 },5 onDeviceReady: function() {6 window.indoorPositioning.setConfiguration(7 configuration,8 () => this.logEvent("Successfully set configuration"),9 error =>10 this.logEvent("Error while setting configuration: " + error)11 );12 if (venueData) {13 window.indoorPositioning.setVenueData(14 venueData,15 () => this.logEvent("Successfully set venue data"),16 error =>17 this.logEvent("Error while setting venue data: " + error)18 ); 19 }20 window.indoorPositioning.start(21 () => this.logEvent("Started successfully"),22 error => this.logEvent("Error while starting: " + error)23 );24 setInterval(25 () => window.indoorPositioning.getLocation(26 this.updateLocation,27 error => this.logEvent("Error while getting location: " + error)28 ),29 200030 );31 setInterval(32 () => window.indoorPositioning.getError(33 this.updateError,34 error => this.logEvent("Error while getting error: " + error)35 ),36 200037 );38 },39 logEvent: function(description) {40 var sdkEventsElement = document.getElementById("sdk-events");41 var eventElement = document.createElement("li");42 eventElement.innerText = description;43 sdkEventsElement.appendChild(eventElement);44 },45 updateError: function(error) {46 document.getElementById("error").innerText = error;47 },48 updateLocation: function(location) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { it, expect } = require('@playwright/test');2it('should log event', async ({ page }) => {3 await page.evaluate(() => window.logEvent('my-event', { my: 'payload' }));4 await page.waitForTimeout(2000);5 expect(true).toBe(true);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { logEvent } = require('@playwright/test');2logEvent({ name: 'MyEvent', value: 'MyValue' });3const { logEvent } = require('playwright-log-event');4logEvent({ name: 'MyEvent', value: 'MyValue' });5const { test, expect } = require('@playwright/test');6const { logEvent } = require('playwright-log-event');7test('My Test', async ({ page }) => {8 logEvent({ name: 'Playwright', value: 'Page Loaded' });9 expect(await page.innerText('.navbar__title')).toBe('Playwright');10});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { logEvent } = require('@playwright/test/lib/logger');2logEvent({ name: 'custom-event', message: 'Custom Event Message' });3const { logEvent } = require('@playwright/test/lib/logger');4logEvent({ name: 'custom-event', message: 'Custom Event Message', metadata: { foo: 'bar' } });5const { logEvent } = require('@playwright/test/lib/logger');6logEvent({ name: 'custom-event', message: 'Custom Event Message', category: 'custom-category' });7const { logEvent } = require('@playwright/test/lib/logger');8logEvent({ name: 'custom-event', message: 'Custom Event Message', severity: 'info' });9const { logEvent } = require('@playwright/test/lib/logger');10logEvent({ name: 'custom-event', message: 'Custom Event Message', timestamp: '2021-09-01T00:00:00.000Z' });11### `logEvent(options)`

Full Screen

Using AI Code Generation

copy

Full Screen

1const { logEvent } = require('@playwright/test/lib/utils/logger');2logEvent('My Event', 'My Event Data');3const { test } = require('@playwright/test');4test('basic test', async ({ page }) => {5 const title = page.locator('text=Get started');6 await title.click();7});

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful