How to use inspectObject method in Nightwatch

Best JavaScript code snippet using nightwatch

debug.js

Source:debug.js Github

copy

Full Screen

1/* debug.js */2define ([3 '1401/system/screen' 4], function ( 5 SCREEN6) {7 var DBGOUT = true;8 var GLOBAL = true;9/** Debug *******************************************************************\10 The Debug object implements utilities for debugging and documenting.11 It will eventually implement an on-screen console, but right now it's12 just a stub for some documentation routines.13/** MODULE DECLARATION ******************************************************/14 var API = {};15 API.name = "debug";16 var m_watching = {};17/// INSPECTION ROUTINES //////////////////////////////////////////////////////18/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19/*/ InspectModule() prints a list of public properties and methods for each20 require module that contains the passed string. It returns a string, so21 you will have to console.log() to see the output.22/*/ API.InspectModule = function ( str ) {23 var rm = require.s.contexts._.defined;24 var mlist = [];25 var base = '1401/';26 if (str===undefined) str = base;27 str = (typeof str =='string') ? str : base;28 Object.keys(rm).forEach(function(key){29 var name = key.toString();30 if (name.indexOf(str)>=0) {31 mlist.push(key);32 }33 });34 var out = '\n';35 for (var i=0;i<mlist.length;i++) {36 var objName = mlist[i];37 out += objName+'\n';38 if (str!==base) {39 out+= "-----\n";40 var mod = rm[objName];41 out += m_DumpObj(mod);42 out += '\n';43 }44 }45 if (mlist.length) {46 console.log(out);47 return mlist.length + ' modules listed';48 } else 49 return "module " +str.bracket()+" not found";50 };51/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52/*/ InspectObject() accepts an object and a label, and prints a list of53 all the methods and properties in it. It returns a string, so you will54 have to console.log() to see the output.55/*/ API.InspectObject = function ( obj, depth ) {56 if (!obj) return "Must pass an object or 1401 watched object key string";57 var out = "";58 // handle command line calls 59 switch (typeof obj) {60 case 'object':61 case 'function': 62 break;63 case 'string':64 // see if string is a watched object stored in debugger65 var globj = m_watching[obj]; 66 if (!globj) {67 out = "pass object or 1401 watched object key";68 if (Object.keys(m_watching).length) {69 out += ' (strings listed below):\n';70 Object.keys(m_watching).forEach(function(key){71 out+="\t";72 out+=key;73 out+="\n";74 });75 }76 return out;77 } else {78 return this.InspectObject(globj);79 }80 break;81 default:82 return "must pass object or function, not "+(typeof obj);83 }84 // handle recursive scan85 depth = depth || 0;86 var label = obj.constructor.name || '(anonymous object)';87 var indent = "";88 for (var i=0;i<=depth;i++) indent+='\t';89 out+= label+'\n';90 out+= "\n";91 out += m_DumpObj(obj, depth+1);92 var proto = Object.getPrototypeOf(obj);93 if (proto) {94 out += "\n"+indent+"IN PROTO: ";95 out += this.InspectObject(proto,depth+1);96 out += "\n";97 }98 if (depth===0) out = '\n'+out;99 console.log(out);100 return obj;101 };102/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -103/*/ Use to add an instance of something temporarilyl inspectable by104 console InspectObject(). Useful for gaining access to certain objects105 that are buried inside a module, such as singleton instances like106 1401/objects/viewport107/*/ API.AddWatch = function ( key, obj ) {108 if (typeof key!=='string') {109 return "key must be a string";110 }111 key = key.toLowerCase();112 var exists = m_watching[key];113 if (exists) console.warn ("AddWatch:",key,"redefined");114 m_watching[key]=obj;115 console.info("AddWatch: defined new debug object key",key.bracket(),obj);116 };117/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -118/*/ Append a <div>msg</div> to the #debug div. Can be overridden by adding119 selector argument120/*/ API.Out = function ( msg, escape_msg, selector ) {121 m_DebugOut( msg, escape_msg, selector );122 };123/** SUPPORTING FUNCTIONS ****************************************************/124/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -125/*/ Support function for InspectModule() and InspectObject()126 Also checks m_watching array127/*/ function m_DumpObj ( obj, depth ) {128 var indent = "";129 for (var i=0;i<depth;i++) indent+='\t';130 var str = "";131 Object.keys(obj).forEach(function(key){132 var prop = obj[key];133 var type = typeof prop;134 str += indent;135 str += type + '\t'+key;136 switch (type) {137 case 'function':138 var regexp = /function.*\(([^)]*)\)/;139 var args = regexp.exec(prop.toString());140 str+= ' ('+args[1]+')'; 141 break;142 default:143 break;144 }145 str += '\n';146 }); 147 return str;148 }149/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -150/*/ Debugger window text output151/*/ function m_DebugOut ( msg, escape_msg, selector ) {152 selector = selector || SCREEN.Debug;153 var $dbg = $(selector);154 if (Object.prototype.toString.call($dbg)==='[object Array]') {155 $dbg = $dbg[0]; // get first matching element156 }157 if (escape_msg) {158 var e = document.createElement('div');159 var t = document.createTextNode(msg);160 e.appendChild(t);161 $dbg.append(e);162 } else {163 $dbg.append('<div>'+msg+'</div>');164 }165 }166/** GLOBAL HOOKS *************************************************************/167 if (GLOBAL) {168 window.InspectModule = API.InspectModule;169 window.InspectObject = API.InspectObject;170 window.DBG_Out = function ( msg, selector ) {171 API.Out(msg,false, selector);172 };173 window.DBG_OutClean = function ( msg, selector ) {174 API.Out(msg,true,selector);175 };176 }177/** RETURN MODULE ************************************************************/178 return API;...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...34 const { records, pagination, searchParams } = storeRef;35 // console.log(storeRef);36 // const [, forceUpdate] = useReducer((x) => x + 1, 0);37 const demoList = [38 { label: 'config信息', action: () => inspectObject(config) },39 {40 label: '更新config',41 action: async () => {42 const newStuff = await updateConfig([43 () => {44 return new Promise((resolve) => {45 setTimeout(() => {46 resolve({ newEnum: { a: 1, b: 2 } });47 }, 200);48 });49 },50 ]);51 Modal.info({52 content: (53 <span>54 config 已更新,插入内容:<pre>{JSON.stringify(newStuff, null, 2)}</pre>55 </span>56 ),57 });58 },59 },60 {61 label: 'recordModel相关信息',62 action: () => inspectObject({ idFieldName, nameFieldName, StoreNsTitle }),63 },64 { label: '当前查询参数', action: () => inspectObject(searchParams) },65 { label: '当前分页信息', action: () => inspectObject(pagination) },66 { label: '列表数据', action: () => inspectObject(records) },67 {68 label: '闪烁首行',69 action: () => records.length && blinkRecordById(getRecordId(records[0])),70 extraProps: {71 disabled: !records.length,72 },73 },74 {75 label: '编辑首行',76 action: () => records.length && showRecordForm(records[0]),77 extraProps: {78 disabled: !records.length,79 },80 },81 { label: '弹出新建', action: () => showEmptyRecordForm() },82 { label: '查询[name=10]', action: () => goSearch({ name: '10' }) },83 { label: '查询刷新', action: () => reloadSearch() },84 { label: `查询中: ${searchLoading}`, action: () => {} },85 {86 label: '动作计数',87 action: () => {88 const modal = Modal.info({ content: '' });89 const updateCount = () => {90 modal.update({91 title: '动作计数',92 content: (93 <div>94 <p>A+B: {getActionCount(['actA', 'actB'])}</p>95 <p>A: {getActionCount('actA')}</p>96 <p>B: {getActionCount('actB')}</p>97 </div>98 ),99 });100 };101 increaseActionCount('actA');102 increaseActionCount('actB');103 setTimeout(() => {104 updateCount();105 }, 0);106 setTimeout(() => {107 decreaseActionCount('actA');108 updateCount();109 }, 1000);110 setTimeout(() => {111 decreaseActionCount('actB');112 updateCount();113 }, 2000);114 },115 },116 {117 label: `请求接口`,118 action: async () => {119 callService({120 serviceTitle: `自定义动作`,121 serviceFunction: customAction,122 serviceParams: [{ cmd: 'Just say hi', isErrReq: true }],123 });124 },125 },126 {127 label: `获取记录[id=11]`,128 action: () => {129 getRecord({ [idFieldName]: 11 }).then((record) => {130 inspectObject(record);131 });132 },133 },134 {135 label: `获取记录[id=12,13]`,136 action: () => {137 getRecordMapByIdList([12, 13]).then((record) => {138 inspectObject(record);139 });140 },141 },142 {143 label: `选中首行`,144 action: () => {145 toggleChecked(records[0], true);146 },147 },148 {149 label: `选中本页`,150 action: () => {151 toggleChecked(records, true);152 },153 },154 {155 label: `清空选中`,156 action: () => {157 clearChecked();158 },159 },160 {161 label: `已选取`,162 action: () => {163 inspectObject(checkedList);164 },165 },166 ];167 return (168 <>169 <Card className={styles.container}>170 {demoList.map(({ label, action, extraProps }) => (171 // eslint-disable-next-line react/no-array-index-key172 <Card.Grid hoverable={false} key={label}>173 <Button type="primary" onClick={action} {...extraProps}>174 {label}175 </Button>176 </Card.Grid>177 ))}...

Full Screen

Full Screen

inspectObject.test.js

Source:inspectObject.test.js Github

copy

Full Screen

1const { test } = require('ava')2const inspectObject = require('../lib/inspectObject')3test('fetch', t => {4 const value = inspectObject('/this/is/true', {5 this: {6 is: {7 true: 'yes'8 }9 }10 });11 return t.is(value, 'yes')12})13test('update', t => {14 const obj = {15 this: {16 is: {17 true: 'yes'18 }19 }20 };21 inspectObject('/this/is/true', obj, {22 type: 'upd',23 payload: false24 });25 return t.falsy(obj.this.is.true)26})27test('del', t => {28 const obj = {29 this: {30 is: {31 true: 'yes'32 },33 I_AM_STILL_HERE: undefined34 }35 };36 inspectObject('/this/is/true', obj, {37 type: 'del'38 });39 return t.deepEqual(obj, {40 this: {41 I_AM_STILL_HERE: undefined42 }43 })44})45test('fetch.Array', t => {46 const obj = {47 this: {48 is: {49 true: 'yes'50 }51 },52 list: [53 {54 _id: 1234,55 text: 'cat'56 },57 {58 _id: 2466,59 text: 'water'60 }61 ]62 };63 64 const result = inspectObject('/list/_id', obj)65 return t.is(result.length, 2)66})67test('update.Object.newProp', t => {68 const obj = {69 this: {70 is: {71 true: 'yes'72 }73 },74 list: [75 {76 _id: 1234,77 text: 'cat'78 },79 {80 _id: 2466,81 text: 'water'82 }83 ]84 }85 inspectObject('/this/stuff', obj, {86 type: 'upd',87 payload: {88 dummy_data: true,89 other: {90 stuff: {91 that: 'might',92 be: {93 useful: false94 }95 }96 }97 }98 })99 return t.deepEqual(inspectObject('/this/stuff', obj), {100 dummy_data: true,101 other: {102 stuff: {103 that: 'might',104 be: {105 useful: false106 }107 }108 }109 })110})111test('update.Arrays.newProp', t => {112 const obj = {113 list: [114 {115 _id: 1234,116 text: 'cat'117 },118 {119 _id: 5678,120 text: 'frog'121 }122 ]123 }124 inspectObject('/list/_id/5678/:speak', obj, {125 type: 'upd',126 payload: 'ribit'127 })128 return t.is(obj.list[1].speak, 'ribit')129})130test('update.Object.newProp', t => {131 const obj = {132 1: true133 }134 inspectObject(['0'], obj, {135 type: 'upd',136 payload: false137 })138 return t.falsy(obj['0'])139})140test('update.Object.newProp', t => {141 const obj = {142 1: true,143 newProp: {144 stuff: undefined145 }146 }147 inspectObject(['0', 'maybe', 'this', 'will', 'work'], obj, {148 type: 'upd',149 payload: false150 })151 return t.falsy(obj['0'].maybe.this.will.work)152})153test('delete.Array', t => {154 const obj = {155 list: [156 {157 _id: 1234,158 text: 'cat',159 },160 {161 _id: 5678,162 text: 'frog'163 }164 ]165 }166 inspectObject('/list/_id/1234', obj, {167 type: 'del'168 })169 return t.deepEqual(obj.list, [170 {171 _id: 5678,172 text: 'frog'173 }174 ])175})176test('delete.Array.prop', t => {177 const obj = {178 list: [179 {180 _id: 1234,181 text: 'cat',182 speak: 'meow'183 },184 {185 _id: 5678,186 text: 'frog',187 speak: 'ribit'188 }189 ]190 }191 inspectObject('/list/_id/', obj, {192 type: 'del'193 })194 return t.deepEqual(obj.list, [195 {196 text: 'cat',197 speak: 'meow'198 },199 {200 text: 'frog',201 speak: 'ribit'202 }203 ])...

Full Screen

Full Screen

utils.test.js

Source:utils.test.js Github

copy

Full Screen

...25test('inspectString outputs string representing input.', () => {26 expect(λ.inspectString('a')).toBe('\'a\'');27});28test('inspectObject outputs string representing input.', () => {29 expect(λ.inspectObject({a: 'b'})).toBe('{a: \'b\'}');30 expect(λ.inspectObject({inspect: () => 'inspected'})).toBe('inspected');31});32test('deepInspect outputs inspectObject if input is an object.', () => {33 expect(λ.deepInspect({a: 'b'})).toBe(λ.inspectObject({a: 'b'}));34 expect(λ.deepInspect({inspect: () => 'inspected'})).toBe(λ.inspectObject({inspect: () => 'inspected'}));35});36test('deepInspect outputs inspectFunction if input is a function.', () => {37 function namedFunction() {38 return null;39 }40 expect(λ.deepInspect(() => 'b')).toBe(λ.inspectFunction(() => 'b'));41 expect(λ.deepInspect(namedFunction)).toBe(λ.inspectFunction(namedFunction));42});43test('deepInspect outputs inspectArray if input is an array.', () => {44 function namedFunction() {45 return null;46 }47 expect(λ.deepInspect([1, 'a'])).toBe(λ.inspectArray([1, 'a']));48 expect(λ.deepInspect([namedFunction, 'a'])).toBe(λ.inspectArray([namedFunction, 'a']));...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...53 ? inspectFunction(a)54 : isArray(a)55 ? inspectArray(a)56 : isObject(a)57 ? inspectObject(a)58 : isString(a)59 ? inspectString(a)...

Full Screen

Full Screen

logger.server.js

Source:logger.server.js Github

copy

Full Screen

1import { inspect } from 'util';2function inspectObject(object) {3 return inspect(object, {4 colors: true,5 });6}7function singleLine(str) {8 return str.replace(/\s+/g, ' ');9}10const actionFormatters = {11 // This is used at feature/apollo branch, but it can help you when implementing Apollo12 APOLLO_QUERY_INIT: a =>13 `queryId:${a.queryId} variables:${inspectObject(a.variables)}\n ${singleLine(a.queryString)}`,14 APOLLO_QUERY_RESULT: a =>15 `queryId:${a.queryId}\n ${singleLine(inspectObject(a.result))}`,16 APOLLO_QUERY_STOP: a =>17 `queryId:${a.queryId}`,18};19// Server side redux action logger20export default function createLogger() {21 // eslint-disable-next-line no-unused-vars22 return store => next => (action) => {23 let formattedPayload = '';24 const actionFormatter = actionFormatters[action.type];25 if (typeof actionFormatter === 'function') {26 formattedPayload = actionFormatter(action);27 } else if (action.toString !== Object.prototype.toString) {28 formattedPayload = action.toString();29 } else if (typeof action.payload !== 'undefined') {30 formattedPayload = inspectObject(action.payload);31 } else {32 formattedPayload = inspectObject(action);33 }34 console.log(` * ${action.type}: ${formattedPayload}`); // eslint-disable-line no-console35 return next(action);36 };...

Full Screen

Full Screen

log.js

Source:log.js Github

copy

Full Screen

...13 // Note: strings are returned verbatim since getting the extra quotes are unneeded in most cases.14 if (isString(obj)) {15 return obj16 }17 return inspectObject(obj)18 })19 console.log(objStrings.join(' '))20}21/** Runs inspectObject() on multiple items. */22const inspect = (...objs) => {23 return objs.map(obj => inspectObject(obj))24}25/** Returns a dump of the contents of an object. */26const inspectObject = (obj, opts = {}) => {27 return util.inspect(obj, { colors: true, depth: logDepth, maxArrayLength: logMaxLength, breakLength: 120, ...opts })28}29/** Exits the program with a return code. */30const exit = exitCode => {31 process.exit(exitCode)32}33/** Exits the program with an error. */34const die = (...objs) => {35 if (objs.length) {36 log(`${getProgName()}:`, ...segments)37 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Demo test Google' : function (browser) {3 .waitForElementVisible('body', 1000)4 .setValue('input[type=text]', 'nightwatch')5 .waitForElementVisible('button[name=btnG]', 1000)6 .click('button[name=btnG]')7 .pause(1000)8 .assert.containsText('#main', 'Night Watch')9 .end();10 }11};12module.exports = {13 url : function() {14 return this.api.launchUrl;15 },16 elements : {17 },18 commands : [{19 submit : function() {20 .waitForElementVisible('@body', 1000)21 .setValue('@searchInput', 'nightwatch')22 .waitForElementVisible('@searchBtn', 1000)23 .click('@searchBtn')24 .api.pause(1000);25 }26 }]27};

Full Screen

Using AI Code Generation

copy

Full Screen

1this.demoTest = function (browser) {2 .waitForElementVisible('body', 1000)3 .assert.title('Google')4 .assert.visible('input[type=text]')5 .setValue('input[type=text]', 'rembrandt van rijn')6 .waitForElementVisible('button[name=btnG]', 1000)7 .click('button[name=btnG]')8 .pause(1000)9 .assert.containsText('#main', 'Rembrandt - Wikipedia')10 .end();11};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Demo test Nightwatch' : function (browser) {3 .waitForElementVisible('body', 1000)4 .setValue('input[type=text]', 'nightwatch')5 .waitForElementVisible('button[name=btnG]', 1000)6 .click('button[name=btnG]')7 .pause(1000)8 .assert.containsText('#main', 'Night Watch')9 .end();10 }11};12{13 "test_settings" : {14 "default" : {15 "screenshots" : {16 },17 "desiredCapabilities": {18 }19 }20 }21}22module.exports = {23};24module.exports = {25 elements: {26 searchBox: {27 },28 searchButton: {29 }30 }31};32module.exports = {33 commands: [{34 searchFor: function (term) {35 .setValue('@searchBox', term)36 .click('@searchButton');37 }38 }]39};40module.exports = {41 commands: [{42 searchFor: function (term) {43 .setValue('@searchBox', term)

Full Screen

Using AI Code Generation

copy

Full Screen

1exports.command = function (object, callback) {2 var client = this;3 client.execute(function (object) {4 return inspectObject(object);5 }, [object], function (result) {6 if (typeof callback === "function") {7 callback.call(client, result);8 }9 });10 return this;11};12browser.inspectObject(object, function (result) {13 console.log(result.value);14});15browser.inspectObject(object, function (result) {16 console.log(result.value);17});18client.inspectObject(object, function (result) {19 console.log(result.value);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var inspectObject = require('nightwatch/lib/api/util/inspectObject.js');2module.exports = {3 'test inspectObject' : function (browser) {4 var obj = {5 c: {6 }7 };8 inspectObject(obj);9 }10};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'test inspectObject': function(browser) {3 var obj = {4 };5 browser.inspectObject(obj);6 }7};8module.exports = {9 'test inspectValue': function(browser) {10 var value = 25;11 browser.inspectValue(value);12 }13};14module.exports = {15 'test log': function(browser) {16 var value = 25;17 browser.log(value);18 }19};20module.exports = {21 'test pause': function(browser) {22 browser.pause(5000);23 }24};25module.exports = {26 'test saveScreenshot': function(browser) {27 browser.saveScreenshot('test.png', function() {28 });29 }30};31module.exports = {32 'test setCookie': function(browser) {33 browser.setCookie({34 }, function() {35 });36 }37};38module.exports = {39 'test setWindowSize': function(browser) {40 browser.setWindowSize(800, 600, function() {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nightwatch 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