Best JavaScript code snippet using nightwatch
NamedColors.js
Source:NamedColors.js
1import { ConsoleColor } from "./ConsoleColor.js";2export class NamedColors {3}4NamedColors.AliceBlue = new ConsoleColor("#F0F8FF");5NamedColors.AntiqueWhite = new ConsoleColor("#FAEBD7");6NamedColors.Aqua = new ConsoleColor("#00FFFF");7NamedColors.Aquamarine = new ConsoleColor("#7FFFD4");8NamedColors.Azure = new ConsoleColor("#F0FFFF");9NamedColors.Beige = new ConsoleColor("#F5F5DC");10NamedColors.Bisque = new ConsoleColor("#FFE4C4");11NamedColors.Black = new ConsoleColor("#000000");12NamedColors.BlanchedAlmond = new ConsoleColor("#FFEBCD");13NamedColors.Blue = new ConsoleColor("#0000FF");14NamedColors.BlueViolet = new ConsoleColor("#8A2BE2");15NamedColors.Brown = new ConsoleColor("#A52A2A");16NamedColors.BurlyWood = new ConsoleColor("#DEB887");17NamedColors.CadetBlue = new ConsoleColor("#5F9EA0");18NamedColors.Chartreuse = new ConsoleColor("#7FFF00");19NamedColors.Chocolate = new ConsoleColor("#D2691E");20NamedColors.Coral = new ConsoleColor("#FF7F50");21NamedColors.CornflowerBlue = new ConsoleColor("#6495ED");22NamedColors.Cornsilk = new ConsoleColor("#FFF8DC");23NamedColors.Crimson = new ConsoleColor("#DC143C");24NamedColors.Cyan = new ConsoleColor("#00FFFF");25NamedColors.DarkBlue = new ConsoleColor("#00008B");26NamedColors.DarkCyan = new ConsoleColor("#008B8B");27NamedColors.DarkGoldenRod = new ConsoleColor("#B8860B");28NamedColors.DarkGray = new ConsoleColor("#A9A9A9");29NamedColors.DarkGrey = new ConsoleColor("#A9A9A9");30NamedColors.DarkGreen = new ConsoleColor("#006400");31NamedColors.DarkKhaki = new ConsoleColor("#BDB76B");32NamedColors.DarkMagenta = new ConsoleColor("#8B008B");33NamedColors.DarkOliveGreen = new ConsoleColor("#556B2F");34NamedColors.DarkOrange = new ConsoleColor("#FF8C00");35NamedColors.DarkOrchid = new ConsoleColor("#9932CC");36NamedColors.DarkRed = new ConsoleColor("#8B0000");37NamedColors.DarkSalmon = new ConsoleColor("#E9967A");38NamedColors.DarkSeaGreen = new ConsoleColor("#8FBC8F");39NamedColors.DarkSlateBlue = new ConsoleColor("#483D8B");40NamedColors.DarkSlateGray = new ConsoleColor("#2F4F4F");41NamedColors.DarkSlateGrey = new ConsoleColor("#2F4F4F");42NamedColors.DarkTurquoise = new ConsoleColor("#00CED1");43NamedColors.DarkViolet = new ConsoleColor("#9400D3");44NamedColors.DeepPink = new ConsoleColor("#FF1493");45NamedColors.DeepSkyBlue = new ConsoleColor("#00BFFF");46NamedColors.DimGray = new ConsoleColor("#696969");47NamedColors.DimGrey = new ConsoleColor("#696969");48NamedColors.DodgerBlue = new ConsoleColor("#1E90FF");49NamedColors.FireBrick = new ConsoleColor("#B22222");50NamedColors.FloralWhite = new ConsoleColor("#FFFAF0");51NamedColors.ForestGreen = new ConsoleColor("#228B22");52NamedColors.Fuchsia = new ConsoleColor("#FF00FF");53NamedColors.Gainsboro = new ConsoleColor("#DCDCDC");54NamedColors.GhostWhite = new ConsoleColor("#F8F8FF");55NamedColors.Gold = new ConsoleColor("#FFD700");56NamedColors.GoldenRod = new ConsoleColor("#DAA520");57NamedColors.Gray = new ConsoleColor("#808080");58NamedColors.Grey = new ConsoleColor("#808080");59NamedColors.Green = new ConsoleColor("#008000");60NamedColors.GreenYellow = new ConsoleColor("#ADFF2F");61NamedColors.HoneyDew = new ConsoleColor("#F0FFF0");62NamedColors.HotPink = new ConsoleColor("#FF69B4");63NamedColors.IndianRed = new ConsoleColor("#CD5C5C");64NamedColors.Indigo = new ConsoleColor("#4B0082");65NamedColors.Ivory = new ConsoleColor("#FFFFF0");66NamedColors.Khaki = new ConsoleColor("#F0E68C");67NamedColors.Lavender = new ConsoleColor("#E6E6FA");68NamedColors.LavenderBlush = new ConsoleColor("#FFF0F5");69NamedColors.LawnGreen = new ConsoleColor("#7CFC00");70NamedColors.LemonChiffon = new ConsoleColor("#FFFACD");71NamedColors.LightBlue = new ConsoleColor("#ADD8E6");72NamedColors.LightCoral = new ConsoleColor("#F08080");73NamedColors.LightCyan = new ConsoleColor("#E0FFFF");74NamedColors.LightGoldenRodYellow = new ConsoleColor("#FAFAD2");75NamedColors.LightGray = new ConsoleColor("#D3D3D3");76NamedColors.LightGrey = new ConsoleColor("#D3D3D3");77NamedColors.LightGreen = new ConsoleColor("#90EE90");78NamedColors.LightPink = new ConsoleColor("#FFB6C1");79NamedColors.LightSalmon = new ConsoleColor("#FFA07A");80NamedColors.LightSeaGreen = new ConsoleColor("#20B2AA");81NamedColors.LightSkyBlue = new ConsoleColor("#87CEFA");82NamedColors.LightSlateGray = new ConsoleColor("#778899");83NamedColors.LightSlateGrey = new ConsoleColor("#778899");84NamedColors.LightSteelBlue = new ConsoleColor("#B0C4DE");85NamedColors.LightYellow = new ConsoleColor("#FFFFE0");86NamedColors.Lime = new ConsoleColor("#00FF00");87NamedColors.LimeGreen = new ConsoleColor("#32CD32");88NamedColors.Linen = new ConsoleColor("#FAF0E6");89NamedColors.Magenta = new ConsoleColor("#FF00FF");90NamedColors.Maroon = new ConsoleColor("#800000");91NamedColors.MediumAquaMarine = new ConsoleColor("#66CDAA");92NamedColors.MediumBlue = new ConsoleColor("#0000CD");93NamedColors.MediumOrchid = new ConsoleColor("#BA55D3");94NamedColors.MediumPurple = new ConsoleColor("#9370DB");95NamedColors.MediumSeaGreen = new ConsoleColor("#3CB371");96NamedColors.MediumSlateBlue = new ConsoleColor("#7B68EE");97NamedColors.MediumSpringGreen = new ConsoleColor("#00FA9A");98NamedColors.MediumTurquoise = new ConsoleColor("#48D1CC");99NamedColors.MediumVioletRed = new ConsoleColor("#C71585");100NamedColors.MidnightBlue = new ConsoleColor("#191970");101NamedColors.MintCream = new ConsoleColor("#F5FFFA");102NamedColors.MistyRose = new ConsoleColor("#FFE4E1");103NamedColors.Moccasin = new ConsoleColor("#FFE4B5");104NamedColors.NavajoWhite = new ConsoleColor("#FFDEAD");105NamedColors.Navy = new ConsoleColor("#000080");106NamedColors.OldLace = new ConsoleColor("#FDF5E6");107NamedColors.Olive = new ConsoleColor("#808000");108NamedColors.OliveDrab = new ConsoleColor("#6B8E23");109NamedColors.Orange = new ConsoleColor("#FFA500");110NamedColors.OrangeRed = new ConsoleColor("#FF4500");111NamedColors.Orchid = new ConsoleColor("#DA70D6");112NamedColors.PaleGoldenRod = new ConsoleColor("#EEE8AA");113NamedColors.PaleGreen = new ConsoleColor("#98FB98");114NamedColors.PaleTurquoise = new ConsoleColor("#AFEEEE");115NamedColors.PaleVioletRed = new ConsoleColor("#DB7093");116NamedColors.PapayaWhip = new ConsoleColor("#FFEFD5");117NamedColors.PeachPuff = new ConsoleColor("#FFDAB9");118NamedColors.Peru = new ConsoleColor("#CD853F");119NamedColors.Pink = new ConsoleColor("#FFC0CB");120NamedColors.Plum = new ConsoleColor("#DDA0DD");121NamedColors.PowderBlue = new ConsoleColor("#B0E0E6");122NamedColors.Purple = new ConsoleColor("#800080");123NamedColors.RebeccaPurple = new ConsoleColor("#663399");124NamedColors.Red = new ConsoleColor("#FF0000");125NamedColors.RosyBrown = new ConsoleColor("#BC8F8F");126NamedColors.RoyalBlue = new ConsoleColor("#4169E1");127NamedColors.SaddleBrown = new ConsoleColor("#8B4513");128NamedColors.Salmon = new ConsoleColor("#FA8072");129NamedColors.SandyBrown = new ConsoleColor("#F4A460");130NamedColors.SeaGreen = new ConsoleColor("#2E8B57");131NamedColors.SeaShell = new ConsoleColor("#FFF5EE");132NamedColors.Sienna = new ConsoleColor("#A0522D");133NamedColors.Silver = new ConsoleColor("#C0C0C0");134NamedColors.SkyBlue = new ConsoleColor("#87CEEB");135NamedColors.SlateBlue = new ConsoleColor("#6A5ACD");136NamedColors.SlateGray = new ConsoleColor("#708090");137NamedColors.SlateGrey = new ConsoleColor("#708090");138NamedColors.Snow = new ConsoleColor("#FFFAFA");139NamedColors.SpringGreen = new ConsoleColor("#00FF7F");140NamedColors.SteelBlue = new ConsoleColor("#4682B4");141NamedColors.Tan = new ConsoleColor("#D2B48C");142NamedColors.Teal = new ConsoleColor("#008080");143NamedColors.Thistle = new ConsoleColor("#D8BFD8");144NamedColors.Tomato = new ConsoleColor("#FF6347");145NamedColors.Turquoise = new ConsoleColor("#40E0D0");146NamedColors.Violet = new ConsoleColor("#EE82EE");147NamedColors.Wheat = new ConsoleColor("#F5DEB3");148NamedColors.White = new ConsoleColor("#FFFFFF");149NamedColors.WhiteSmoke = new ConsoleColor("#F5F5F5");150NamedColors.Yellow = new ConsoleColor("#FFFF00");...
common.js
Source:common.js
1const systemConfig = require('../systemConfig.js')2const dayjs = require('dayjs');3const dayjsCustomParseFormat = require('dayjs/plugin/customParseFormat');4dayjs.extend(dayjsCustomParseFormat);5const digitInWord = [6 'không', 'má»t', 'hai', 'ba', 'bá»n',7 'nÄm', 'sáu', 'bảy', 'tám', 'chÃn',8];9module.exports = {10 getCurrentTime: function () {11 return dayjs().format('YYYY-MM-DD HH:mm:ss');12 },13 getReadableIP: function (request) {14 let ip = request.headers['x-real-ip'];15 if (ip == null) {16 let parts = (request.connection.remoteAddress + '').split(':');17 return parts.pop();18 }19 return ip.toString();20 },21 sleep: function (ms) {22 return new Promise(function (resolve) {23 setTimeout(function () {24 resolve();25 }, ms);26 });27 },28 consoleLog: function (string, consoleColor, time) {29 if (consoleColor == null) {30 consoleColor = systemConfig.consoleColor;31 }32 if (time == null) {33 time = module.exports.getCurrentTime();34 }35 console.log(consoleColor + '%s\x1b[0m', time + ': ' + string);36 },37 consoleLogError: function (string, consoleColor, time) {38 if (consoleColor == null) {39 consoleColor = systemConfig.consoleColor;40 }41 if (time == null) {42 time = module.exports.getCurrentTime();43 }44 console.log(consoleColor + '\x1b[5m%s\x1b[0m', time + ': ' + string);45 },46 cloneObject: function (object) {47 let string = JSON.stringify(object);48 return JSON.parse(string);49 },50 isNumeric: function (n) {51 return !isNaN(parseFloat(n)) && isFinite(n);52 },53 numberToWordVN: function (input) {54 let number = parseInt(input);55 if (!module.exports.isNumeric(number)) {56 return '';57 }58 let unitArray = [59 'nghìn', 'triá»u', 'tá»·',60 ];61 let numberString = number.toLocaleString('vi-VN');62 let parts = numberString.split('.');63 let firstPart = parts.pop();64 let resultPart = [firstPartToWord(parts, firstPart)];65 for (let i = parts.length - 1; i >= 0; i--) {66 let aPart = parts[i];67 let word = partToWordVN(aPart);68 if (word == '') {69 continue;70 }71 let diff = parts.length - 1 - i;72 let over = Math.floor(diff / unitArray.length);73 let unit = [];74 for (let j = 0; j < over; j++) {75 unit.push('tá»·');76 }77 let mod = diff % unitArray.length;78 let aResultPart = word + ' ' + unitArray[mod];79 if (unit.length > 0) {80 aResultPart = aResultPart + ' ';81 }82 aResultPart = aResultPart + unit.join(' ');83 resultPart.push(aResultPart);84 }85 let result = resultPart.reverse().join(' ');86 return result;87 },88 validateEmail: function (input) {89 let re =90 /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;91 return re.test(String(input).toLowerCase());92 },93 checkNumericString: function (input) {94 for (let i = 0; i < input.length; i++) {95 if (!'0123456789'.includes(input[i])) {96 return false;97 }98 }99 return true;100 },101};102function firstPartToWord(parts, firstPart) {103 if (parts.length == 0 || firstPart == '000') {104 return partToWordVN(firstPart);105 }106 let oneOfFirstPart = firstPart[2];107 let tenOfFirstPart = firstPart[1];108 let hundredOfFirstPart = firstPart[0];109 if (tenOfFirstPart == 0 && hundredOfFirstPart == 0) {110 return 'lẻ ' + digitInWord[parseInt(oneOfFirstPart)];111 }112 return partToWordVN(firstPart);113};114function partToWordVN(part) {115 if (part.length == 1) {116 return oneDigitToWordVN(part);117 }118 if (part.length == 2) {119 return twoDigitToWordVN(part);120 }121 return threeDigitToWordVN(part);122};123function oneDigitToWordVN(input) {124 let one = input[0];125 return digitInWord[parseInt(one)];126};127function twoDigitToWordVN(input) {128 let one = input[1];129 let ten = input[0];130 let result = digitInWord[parseInt(ten)] + ' muÆ¡i';131 if (ten == 1) {132 result = 'mÆ°á»i';133 }134 if (one == 0) {135 return result;136 }137 if (one == 5) {138 return result + ' lÄm';139 }140 if (one == 1 && ten != 1) {141 return result + ' má»t';142 }143 return result + ' ' + digitInWord[parseInt(one)];144};145function threeDigitToWordVN(input) {146 if (input === '000') {147 return '';148 }149 let one = input[2];150 let ten = input[1];151 let hundred = input[0];152 let result = digitInWord[parseInt(hundred)] + ' trÄm';153 if (one == 0 && ten == 0) {154 return result;155 }156 if (ten == 0) {157 result = result + ' linh';158 result = result + ' ' + oneDigitToWordVN(one);159 } else {160 result = result + ' ' + twoDigitToWordVN(ten + one);161 }162 return result;...
generate.js
Source:generate.js
1/* eslint-disable no-console */2const prompts = require('prompts');3const fs = require('fs');4const path = require('path');5const component = require('./templates/component');6const container = require('./templates/container');7const layout = require('./templates/layout');8const view = require('./templates/view');9// Configs10const config = {11 outDir: path.resolve(__dirname, '../src/'),12 consoleColor: {13 success: '\x1b[32m%s\x1b[0m',14 error: '\x1b[31m%s\x1b[0m',15 title: '\x1b[4m%s\x1b[0m',16 },17};18const componentType = {19 component: 'components',20 layout: 'layouts',21 container: 'containers',22 view: 'views',23};24// State25let TYPE = '';26// Functions27const PromptType = async () => {28 await prompts({29 type: 'select',30 name: 'type',31 message: 'Choose type',32 choices: [33 {34 title: 'Component',35 description: 'Simple UI component',36 value: componentType.component,37 },38 {39 title: 'Layout',40 description: 'Layout UI component',41 value: componentType.layout,42 },43 {44 title: 'Container',45 description: 'State component',46 value: componentType.container,47 },48 {49 title: 'View',50 description: 'View component',51 value: componentType.view,52 },53 ],54 initial: 0,55 }).then(value => {56 TYPE = value.type;57 PromptName();58 });59};60const PromptName = async () => {61 await prompts({62 type: 'text',63 name: 'name',64 message: `Enter ${TYPE.slice(0, -1)} name:`,65 // validate: value => (value < 18 ? `Nightclub is 18+ only` : true),66 }).then(value => {67 checkIfComponentExists(value.name, TYPE).then(exists => {68 if (exists) {69 console.log(config.consoleColor.error, `${value.name} exists`);70 PromptName();71 } else {72 if (TYPE === componentType.component) {73 generateComponent(value.name);74 }75 if (TYPE === componentType.container) {76 generateContainer(value.name);77 }78 if (TYPE === componentType.layout) {79 generateLayout(value.name);80 }81 if (TYPE === componentType.view) {82 generateView(value.name);83 }84 }85 });86 });87};88const checkIfComponentExists = async (name, subdir) => {89 return fs.existsSync(`${config.outDir}/${subdir}/${name}`);90};91const generateComponent = name => {92 const dirPath = `${config.outDir}/${componentType.component}/${name}`;93 const filePath = `${dirPath}/${name}`;94 console.log(95 config.consoleColor.title,96 `src/${componentType.component}/${name}:`97 );98 fs.mkdirSync(dirPath);99 fs.writeFileSync(`${filePath}.tsx`, component.tsx(name));100 console.log(config.consoleColor.success, `+ ${name}.tsx`);101 fs.writeFileSync(`${filePath}.scss`, component.scss(name));102 console.log(config.consoleColor.success, `+ ${name}.scss`);103 fs.writeFileSync(`${dirPath}/index.ts`, component.index(name));104 console.log(config.consoleColor.success, `+ index.ts`);105};106const generateContainer = name => {107 const dirPath = `${config.outDir}/${componentType.container}/${name}`;108 const filePath = `${dirPath}/${name}`;109 console.log(110 config.consoleColor.title,111 `src/${componentType.container}/${name}:`112 );113 fs.mkdirSync(dirPath, { recursive: true });114 fs.writeFileSync(`${filePath}.container.tsx`, container.tsx(name));115 console.log(config.consoleColor.success, `+ ${name}.container.tsx`);116 fs.writeFileSync(`${dirPath}/index.ts`, container.index(`${name}.container`));117 console.log(config.consoleColor.success, `+ index.ts`);118};119const generateLayout = name => {120 const dirPath = `${config.outDir}/${componentType.layout}/${name}`;121 const filePath = `${dirPath}/${name}`;122 console.log(123 config.consoleColor.title,124 `src/${componentType.layout}/${name}:`125 );126 fs.mkdirSync(dirPath);127 fs.writeFileSync(`${filePath}.layout.tsx`, layout.tsx(name));128 console.log(config.consoleColor.success, `+ ${name}.layout.tsx`);129 fs.writeFileSync(`${filePath}.layout.scss`, layout.scss(name));130 console.log(config.consoleColor.success, `+ ${name}.layout.scss`);131 fs.writeFileSync(`${dirPath}/index.ts`, layout.index(name));132 console.log(config.consoleColor.success, `+ index.ts`);133};134const generateView = name => {135 const dirPath = `${config.outDir}/${componentType.view}/${name}`;136 const filePath = `${dirPath}/${name}`;137 console.log(138 config.consoleColor.title,139 `src/${componentType.view}/${name}:`140 );141 fs.mkdirSync(dirPath, { recursive: true });142 fs.writeFileSync(`${filePath}.view.tsx`, view.tsx(name));143 console.log(config.consoleColor.success, `+ ${name}.view.tsx`);144 fs.writeFileSync(`${dirPath}/index.ts`, view.index(name));145 console.log(config.consoleColor.success, `+ index.ts`);146};147// Init script...
OTA2B.js
Source:OTA2B.js
1var fs = require('fs');2var config = require('../../config');3var txt2json = require('../txt2json');4var checkOTAvalue = require('../checkOTAvalue');5var otaTransaction = require('../otaTransaction');6var wanchainLog = require('../wanchainLog');7function OTA2B(prompt, keythereum, keystoreStr) {8 let keystore = JSON.parse(keystoreStr)[1];9 console.log('you keystore: ', keystore);10 wanchainLog('Now to unlock your wallet, input your password', config.consoleColor.COLOR_FgGreen);11 prompt.get(require('../schema/keyPassword'), function (err, result) {12 wanchainLog('Waiting for unlock wallet....', config.consoleColor.COLOR_FgRed);13 let keyAObj = {version:keystore.version, crypto:keystore.crypto};14 let keyBObj = {version:keystore.version, crypto:keystore.crypto2};15 let privKeyA;16 let privKeyB;17 let address;18 let waddress;19 try {20 privKeyA = keythereum.recover(result.keyPassword, keyAObj);21 privKeyB = keythereum.recover(result.keyPassword, keyBObj);22 address = keystore.address;23 waddress = keystore.waddress;24 } catch (e) {25 wanchainLog('Password invalid', config.consoleColor.COLOR_FgRed);26 return;27 }28 wanchainLog('Your wallet has been unlocked. Would you want to send a transaction? (y[Y]/n[N])', config.consoleColor.COLOR_FgGreen);29 prompt.get(require('../schema/isTransaction'), function (err, result) {30 var theState = result.state.toLowerCase();31 switch (theState) {32 case 'y':33 let otaData = [];34 try {35 let otaDataStr = fs.readFileSync("./otaData/otaData.txt","utf8");36 let otaDataTotal = otaDataStr.split('\n');37 for (let i=0; i<otaDataTotal.length; i++) {38 if (otaDataTotal[i].length >0) {39 if(JSON.parse(otaDataTotal[i]).waddress === waddress) {40 otaData.push(otaDataTotal[i])41 }42 }43 }44 } catch (e) {45 wanchainLog('Not have otaData.', config.consoleColor.COLOR_FgRed);46 return;47 }48 if (otaData.length === 0) {49 wanchainLog('There is no transaction input to OTA.', config.consoleColor.COLOR_FgGreen);50 return;51 }52 let otaDataUndo;53 try {54 let otaDataStateStr = fs.readFileSync("./otaData/otaDataState.txt","utf8");55 let otaDataState = otaDataStateStr.split('\n');56 otaDataUndo = txt2json(otaData, otaDataState)[0];57 } catch (e) {58 otaDataUndo = txt2json(otaData)[0];59 }60 if (otaDataUndo.length === 0) {61 wanchainLog('There is no transaction input to OTA.', config.consoleColor.COLOR_FgGreen);62 return;63 } else {64 for (let i = 0; i<otaDataUndo.length; i++) {65 let index = i +1;66 wanchainLog(index + '. ' + 'ota: ' + otaDataUndo[i].ota + ' value: ' + otaDataUndo[i].value + '\n', config.consoleColor.COLOR_FgYellow);67 }68 }69 wanchainLog('Input ota ', config.consoleColor.COLOR_FgGreen);70 prompt.get(require('../schema/privacyAddr'), function (err, result) {71 let ota = result.waddress;72 let checkState = checkOTAvalue(ota, otaDataUndo);73 if (checkState[0]) {74 let value = checkState[1];75 wanchainLog('You select ota: ' + ota + ' value: ' + value, config.consoleColor.COLOR_FgRed);76 otaTransaction(ota, parseInt(value), privKeyA, privKeyB, address.slice(2))77 } else {78 wanchainLog('Value is 0.', config.consoleColor.COLOR_FgRed);79 }80 });81 break;82 case 'n':83 wanchainLog('Bye!', config.consoleColor.COLOR_FgGreen);84 break;85 }86 });87 });88}...
BaseLogger.js
Source:BaseLogger.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.BaseLogger = void 0;4var ConsoleColor_constant_1 = require("../constants/ConsoleColor.constant");5var BaseLogger = /** @class */ (function () {6 function BaseLogger() {7 this.logToConsole = function (log) {8 switch (log.type) {9 case "DEBUG":10 console.debug(ConsoleColor_constant_1.ConsoleColor.BgWhite + " " + ConsoleColor_constant_1.ConsoleColor.FgBlack, "[" + log.datetime.toLocaleString() + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "" + log.color, "[" + log.type + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "- " + log.message + "\r\n");11 if (log.stack) {12 console.debug("--Stack::");13 console.debug(log.stack);14 }15 break;16 case "LOG":17 console.log(ConsoleColor_constant_1.ConsoleColor.BgWhite + " " + ConsoleColor_constant_1.ConsoleColor.FgBlack, "[" + log.datetime.toLocaleString() + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "" + log.color, "[ " + log.type + " ]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "- " + log.message + "\r\n");18 if (log.stack) {19 console.log("--Stack::");20 console.log(log.stack);21 }22 break;23 case "ERROR":24 console.error(ConsoleColor_constant_1.ConsoleColor.BgWhite + " " + ConsoleColor_constant_1.ConsoleColor.FgBlack, "[" + log.datetime.toLocaleString() + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "" + log.color, "[" + log.type + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "- " + log.message + "\r\n");25 if (log.stack) {26 console.error("--Stack::");27 console.error(log.stack);28 }29 break;30 case "INFO":31 console.info(ConsoleColor_constant_1.ConsoleColor.BgWhite + " " + ConsoleColor_constant_1.ConsoleColor.FgBlack, "[" + log.datetime.toLocaleString() + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "" + log.color, "[ " + log.type + "]", "" + ConsoleColor_constant_1.ConsoleColor.Reset, "- " + log.message + "\r\n");32 if (log.stack) {33 console.info("--Stack::");34 console.info(log.stack);35 }36 break;37 }38 };39 }40 return BaseLogger;41}());...
mongo.js
Source:mongo.js
1const mongoose = require('mongoose')2const consoleColor = require('../helpers/consoleColor')3let previousQueryString = ''4const buildQueryString = ({5 host,6 port,7 user,8 password,9 database10}) => {11 host = host || 'localhost'12 port = port || '27017'13 password = password || ''14 let authenticationString = (user && password) ? `${user}:${password}@` : ''15 if (!database) throw Error('Should specify a databse which you want to connect')16 return `mongodb://${authenticationString}${host}:${port}/${database}`17}18module.exports = function connectMongo(options) {19 return new Promise((res, rej) => {20 console.log(consoleColor('yellow'), 'Connecting to mongo...', consoleColor('white'))21 let queryString = buildQueryString(options)22 if (mongoose.connection.readyState == 1 && previousQueryString === queryString) {23 console.log(consoleColor('green'), "Connected to mongo Successfully!", consoleColor('white'));24 return res(mongoose)25 }26 let opt = options.options ? options.options : {27 useNewUrlParser: true,28 useCreateIndex: true,29 poolSize: 2030 }31 mongoose.connect(queryString, opt);32 const db = mongoose.connection33 db.once('open', () => {34 console.log(consoleColor('green'), "Connected to mongo Successfully!", consoleColor('white'));35 previousQueryString = queryString36 res(mongoose)37 })38 db.on('error', (er) => {39 console.log(consoleColor('red'), 'Connection to mongo error!', consoleColor('white'))40 rej(er)41 })42 })...
mysql.js
Source:mysql.js
1const knex = require('knex');2const consoleColor = require('../helpers/consoleColor')3const testconfig = {4 client: 'mysql',5 connection: {6 host: 'localhost',7 port: '8889',8 user: 'root',9 password: '123',10 database: 'newpost_v2db'11 }12}13/**14 * Returns promise that when resolves return15 * instance of knex connected to database16 *17 * @param {*} options18 */19module.exports = function connectMysql(options) {20 return new Promise((res, rej) => {21 console.log(consoleColor('yellow'), 'Connecting to mysql...', consoleColor('white'))22 let sqlClient = knex(options)23 sqlClient.raw('select 1+1 as result')24 .then(() => {25 console.log(consoleColor('green'), 'Connected to mysql successfully!', consoleColor('white'))26 res(sqlClient)27 })28 .catch((er) => {29 console.log(consoleColor('red'), 'Error connecting to mysql!', consoleColor('white'))30 console.log(consoleColor('red'), er, consoleColor('white'))31 rej(er)32 })33 })...
prototyping.js
Source:prototyping.js
1var consoleColor={2 red : '\033[31m',3 blue : '\033[34m',4 green: '\033[32m',5 purple: '\033[35m',6 brown: '\033[33m',7 cyan: '\033[36m',8 reset : '\033[0m'9}1011exports.addProto=function(){12 String.prototype.red=function(){13 return consoleColor.red + this + consoleColor.reset;14 }15 String.prototype.blue=function(){16 return consoleColor.blue + this + consoleColor.reset;17 }18 String.prototype.green=function(){19 return consoleColor.green + this + consoleColor.reset;20 }21 String.prototype.purple=function(){22 return consoleColor.purple + this + consoleColor.reset;23 }24 String.prototype.cyan=function(){25 return consoleColor.cyan + this + consoleColor.reset;26 }
...
Using AI Code Generation
1var color = require('colors');2module.exports = {3 'Demo test Google' : function (browser) {4 .waitForElementVisible('body', 1000)5 .setValue('input[type=text]', 'nightwatch')6 .waitForElementVisible('button[name=btnG]', 1000)7 .click('button[name=btnG]')8 .pause(1000)9 .assert.containsText('#main', 'Night Watch')10 .end();11 }12};13{14 "selenium" : {15 "cli_args" : {16 }17 },18 "test_settings" : {19 "default" : {20 "screenshots" : {21 },22 "desiredCapabilities": {23 }24 },25 "chrome" : {26 "desiredCapabilities": {27 }28 }29 }30}31{32 "scripts": {33 },34 "dependencies": {
Using AI Code Generation
1module.exports = {2 'Console Color Test' : function (client) {3 .consoleColor('log', 'This is a log message')4 .consoleColor('warn', 'This is a warn message')5 .consoleColor('error', 'This is an error message')6 .consoleColor('info', 'This is an info message')7 .end();8 }9};10{11 "selenium" : {
Using AI Code Generation
1module.exports = {2 'Console Color': function (browser) {3 .consoleColor('log', 'This is a log message')4 .consoleColor('info', 'This is an info message')5 .consoleColor('warn', 'This is a warning message')6 .consoleColor('error', 'This is an error message')7 .end();8 }9};10MIT © [Amit Kumar](
Using AI Code Generation
1module.exports = {2 'ConsoleColor test': function (client) {3 .consoleColor('log', 'Hello World')4 .end();5 }6};7module.exports = {8 test_settings: {9 default: {10 globals: {11 my_global_method: function () {12 console.log('test');13 }14 }15 }16 }17};18module.exports = {19 'Custom global test': function (client) {20 .perform(function () {21 console.log(client.globals.my_global_var);22 client.globals.my_global_method();23 })24 .end();25 }26};27module.exports = {28 test_settings: {29 default: {30 globals: {31 my_global_method: function () {32 console.log('test');33 }34 }35 }36 }37};38module.exports = {39 'Custom global test': function (client) {40 .perform(function () {41 console.log(client.globals.my_global_var);42 client.globals.my_global_method();43 })44 .end();45 }46};47module.exports = {48 test_settings: {49 default: {50 globals: {51 my_global_method: function () {52 console.log('test');53 }54 }55 }56 }57};58module.exports = {59 'Custom global test': function (client) {60 .perform(function () {
Using AI Code Generation
1var ConsoleColor = require('nightwatch-console-color');2module.exports = {3 'Test Console Color' : function (client) {4 var consoleColor = new ConsoleColor(client);5 consoleColor.log('This is a log message', 'blue');6 consoleColor.log('This is a log message', 'red');7 consoleColor.log('This is a log message', 'green');8 consoleColor.log('This is a log message', 'yellow');9 consoleColor.log('This is a log message', 'magenta');10 consoleColor.log('This is a log message', 'cyan');11 consoleColor.log('This is a log message', 'grey');12 consoleColor.log('This is a log message', 'white');13 consoleColor.log('This is a log message', 'black');14 consoleColor.log('This is a log message', 'rainbow');15 consoleColor.log('This is a log message', 'zebra');16 consoleColor.log('This is a log message', 'america');17 consoleColor.log('This is a log
Using AI Code Generation
1module.exports = {2 'Console Color Test': function (browser) {3 .url(browser.launchUrl)4 .consoleColor('log', 'Hello World')5 .end();6 }7};
Using AI Code Generation
1var test = require('nightwatch').test;2var assert = require('nightwatch').assert;3var colors = require('colors');4test('test', function(client) {5 .waitForElementVisible('body', 1000)6 .assert.title('Google')7 .end();8});9test('test', function(client) {10 .waitForElementVisible('body', 1000)11 .assert.title('Google')12 .end();13});14module.exports = {15 selenium: {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!