How to use registerGlobal method in Protractor

Best JavaScript code snippet using protractor

Player.js

Source:Player.js Github

copy

Full Screen

1/**2 * Used to create player entities prior to reading the rest of a map,3 * all other initialization must be done after loading map (terrain/entities).4 * DO NOT use other components here, as they may fail unpredictably.5 * settings is the object containing settings for this map.6 * newPlayers if true will remove old player entities or add new ones until7 * the new number of player entities is obtained8 * (used when loading a map or when Atlas changes the number of players).9 */10function LoadPlayerSettings(settings, newPlayers)11{12 var playerDefaults = Engine.ReadJSONFile("simulation/data/settings/player_defaults.json").PlayerData;13 // Default settings14 if (!settings)15 settings = {};16 // Add gaia to simplify iteration17 // (if gaia is not already the first civ such as when called from Atlas' ActorViewer)18 if (settings.PlayerData && settings.PlayerData[0] &&19 (!settings.PlayerData[0].Civ || settings.PlayerData[0].Civ != "gaia"))20 settings.PlayerData.unshift(null);21 var playerData = settings.PlayerData;22 23 // Disable the AIIinterface when no AI players are present24 if (playerData && !playerData.some(v => v && !!v.AI))25 Engine.QueryInterface(SYSTEM_ENTITY, IID_AIInterface).Disable();26 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);27 var numPlayers = cmpPlayerManager.GetNumPlayers();28 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);29 // Remove existing players or add new ones30 if (newPlayers)31 {32 var settingsNumPlayers = 9; // default 8 players + gaia33 if (playerData)34 settingsNumPlayers = playerData.length; // includes gaia (see above)35 else36 warn("Player.js: Setup has no player data - using defaults");37 while (settingsNumPlayers > numPlayers)38 {39 // Add player entity to engine40 var entID = Engine.AddEntity(GetPlayerTemplateName(getSetting(playerData, playerDefaults, numPlayers, "Civ")));41 var cmpPlayer = Engine.QueryInterface(entID, IID_Player);42 if (!cmpPlayer)43 throw new Error("Player.js: Error creating player entity " + numPlayers);44 cmpPlayerManager.AddPlayer(entID);45 ++numPlayers;46 }47 while (settingsNumPlayers < numPlayers)48 {49 cmpPlayerManager.RemoveLastPlayer();50 --numPlayers;51 }52 }53 // Even when no new player, we must check the template compatibility as player template may be civ dependent54 for (var i = 0; i < numPlayers; ++i)55 {56 var template = GetPlayerTemplateName(getSetting(playerData, playerDefaults, i, "Civ"));57 var entID = cmpPlayerManager.GetPlayerByID(i);58 if (cmpTemplateManager.GetCurrentTemplateName(entID) === template)59 continue;60 // We need to recreate this player to have the right template61 entID = Engine.AddEntity(template);62 cmpPlayerManager.ReplacePlayer(i, entID);63 }64 // Initialize the player data65 for (var i = 0; i < numPlayers; ++i)66 {67 let cmpPlayer = QueryPlayerIDInterface(i);68 cmpPlayer.SetName(getSetting(playerData, playerDefaults, i, "Name"));69 cmpPlayer.SetCiv(getSetting(playerData, playerDefaults, i, "Civ"));70 var color = getSetting(playerData, playerDefaults, i, "Color");71 cmpPlayer.SetColor(color.r, color.g, color.b);72 // Special case for gaia73 if (i == 0)74 {75 // Gaia should be its own ally.76 cmpPlayer.SetAlly(0);77 // Gaia is everyone's enemy78 for (var j = 1; j < numPlayers; ++j)79 cmpPlayer.SetEnemy(j);80 continue;81 }82 // Note: this is not yet implemented but I leave it commented to highlight it's easy83 // If anyone ever adds handicap.84 //if (getSetting(playerData, playerDefaults, i, "GatherRateMultiplier") !== undefined)85 // cmpPlayer.SetGatherRateMultiplier(getSetting(playerData, playerDefaults, i, "GatherRateMultiplier"));86 if (getSetting(playerData, playerDefaults, i, "PopulationLimit") !== undefined)87 cmpPlayer.SetMaxPopulation(getSetting(playerData, playerDefaults, i, "PopulationLimit"));88 if (getSetting(playerData, playerDefaults, i, "Resources") !== undefined)89 cmpPlayer.SetResourceCounts(getSetting(playerData, playerDefaults, i, "Resources"));90 if (getSetting(playerData, playerDefaults, i, "StartingTechnologies") !== undefined)91 cmpPlayer.SetStartingTechnologies(getSetting(playerData, playerDefaults, i, "StartingTechnologies"));92 if (getSetting(playerData, playerDefaults, i, "DisabledTechnologies") !== undefined)93 cmpPlayer.SetDisabledTechnologies(getSetting(playerData, playerDefaults, i, "DisabledTechnologies"));94 let disabledTemplates = [];95 if (settings.DisabledTemplates !== undefined)96 disabledTemplates = settings.DisabledTemplates;97 if (getSetting(playerData, playerDefaults, i, "DisabledTemplates") !== undefined)98 disabledTemplates = disabledTemplates.concat(getSetting(playerData, playerDefaults, i, "DisabledTemplates"));99 if (disabledTemplates.length)100 cmpPlayer.SetDisabledTemplates(disabledTemplates);101 if (settings.DisableSpies)102 {103 cmpPlayer.AddDisabledTechnology("unlock_spies");104 cmpPlayer.AddDisabledTemplate("special/spy");105 }106 // If diplomacy explicitly defined, use that; otherwise use teams107 if (getSetting(playerData, playerDefaults, i, "Diplomacy") !== undefined)108 cmpPlayer.SetDiplomacy(getSetting(playerData, playerDefaults, i, "Diplomacy"));109 else110 {111 // Init diplomacy112 var myTeam = getSetting(playerData, playerDefaults, i, "Team");113 // Set all but self as enemies as SetTeam takes care of allies114 for (var j = 0; j < numPlayers; ++j)115 {116 if (i == j)117 cmpPlayer.SetAlly(j);118 else119 cmpPlayer.SetEnemy(j);120 }121 cmpPlayer.SetTeam(myTeam === undefined ? -1 : myTeam);122 }123 cmpPlayer.SetFormations(124 getSetting(playerData, playerDefaults, i, "Formations") ||125 Engine.ReadJSONFile("simulation/data/civs/" + cmpPlayer.GetCiv() + ".json").Formations);126 var startCam = getSetting(playerData, playerDefaults, i, "StartingCamera");127 if (startCam !== undefined)128 cmpPlayer.SetStartingCamera(startCam.Position, startCam.Rotation);129 }130 // NOTE: We need to do the team locking here, as otherwise131 // SetTeam can't ally the players.132 if (settings.LockTeams)133 for (let i = 0; i < numPlayers; ++i)134 QueryPlayerIDInterface(i).SetLockTeams(true);135 // Disable the AIIinterface when no AI players are present136 if (playerData && !playerData.some(v => v && !!v.AI))137 Engine.QueryInterface(SYSTEM_ENTITY, IID_AIInterface).Disable();138}139// Get a setting if it exists or return default140function getSetting(settings, defaults, idx, property)141{142 if (settings && settings[idx] && (property in settings[idx]))143 return settings[idx][property];144 // Use defaults145 if (defaults && defaults[idx] && (property in defaults[idx]))146 return defaults[idx][property];147 return undefined;148}149function GetPlayerTemplateName(civ)150{151 let path = "special/player/player";152 if (Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).TemplateExists(path + "_" + civ))153 return path + "_" + civ;154 return path;155}156/**157 * Similar to Engine.QueryInterface but applies to the player entity158 * that owns the given entity.159 * iid is typically IID_Player.160 */161function QueryOwnerInterface(ent, iid = IID_Player)162{163 var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);164 if (!cmpOwnership)165 return null;166 var owner = cmpOwnership.GetOwner();167 if (owner == INVALID_PLAYER)168 return null;169 return QueryPlayerIDInterface(owner, iid);170}171/**172 * Similar to Engine.QueryInterface but applies to the player entity173 * with the given ID number.174 * iid is typically IID_Player.175 */176function QueryPlayerIDInterface(id, iid = IID_Player)177{178 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);179 var playerEnt = cmpPlayerManager.GetPlayerByID(id);180 if (!playerEnt)181 return null;182 return Engine.QueryInterface(playerEnt, iid);183}184/**185 * Similar to Engine.QueryInterface but first checks if the entity186 * mirages the interface.187 */188function QueryMiragedInterface(ent, iid)189{190 var cmp = Engine.QueryInterface(ent, IID_Mirage);191 if (cmp && !cmp.Mirages(iid))192 return null;193 else if (!cmp)194 cmp = Engine.QueryInterface(ent, iid);195 return cmp;196}197/**198 * Similar to Engine.QueryInterface, but checks for all interfaces199 * implementing a builder list (currently Foundation and Repairable)200 * TODO Foundation and Repairable could both implement a BuilderList component201 */202function QueryBuilderListInterface(ent)203{204 return Engine.QueryInterface(ent, IID_Foundation) || Engine.QueryInterface(ent, IID_Repairable);205}206/**207 * Returns true if the entity 'target' is owned by an ally of208 * the owner of 'entity'.209 */210function IsOwnedByAllyOfEntity(entity, target)211{212 return IsOwnedByEntityHelper(entity, target, "IsAlly");213}214function IsOwnedByMutualAllyOfEntity(entity, target)215{216 return IsOwnedByEntityHelper(entity, target, "IsMutualAlly");217}218function IsOwnedByEntityHelper(entity, target, check)219{220 // Figure out which player controls us221 let owner = 0;222 let cmpOwnership = Engine.QueryInterface(entity, IID_Ownership);223 if (cmpOwnership)224 owner = cmpOwnership.GetOwner();225 // Figure out which player controls the target entity226 let targetOwner = 0;227 let cmpOwnershipTarget = Engine.QueryInterface(target, IID_Ownership);228 if (cmpOwnershipTarget)229 targetOwner = cmpOwnershipTarget.GetOwner();230 let cmpPlayer = QueryPlayerIDInterface(owner);231 return cmpPlayer && cmpPlayer[check](targetOwner);232}233/**234 * Returns true if the entity 'target' is owned by player235 */236function IsOwnedByPlayer(player, target)237{238 var cmpOwnershipTarget = Engine.QueryInterface(target, IID_Ownership);239 return cmpOwnershipTarget && player == cmpOwnershipTarget.GetOwner();240}241function IsOwnedByGaia(target)242{243 return IsOwnedByPlayer(0, target);244}245/**246 * Returns true if the entity 'target' is owned by an ally of player247 */248function IsOwnedByAllyOfPlayer(player, target)249{250 return IsOwnedByHelper(player, target, "IsAlly");251}252function IsOwnedByMutualAllyOfPlayer(player, target)253{254 return IsOwnedByHelper(player, target, "IsMutualAlly");255}256function IsOwnedByNeutralOfPlayer(player,target)257{258 return IsOwnedByHelper(player, target, "IsNeutral");259}260function IsOwnedByEnemyOfPlayer(player, target)261{262 return IsOwnedByHelper(player, target, "IsEnemy");263}264function IsOwnedByHelper(player, target, check)265{266 let targetOwner = 0;267 let cmpOwnershipTarget = Engine.QueryInterface(target, IID_Ownership);268 if (cmpOwnershipTarget)269 targetOwner = cmpOwnershipTarget.GetOwner();270 let cmpPlayer = QueryPlayerIDInterface(player);271 return cmpPlayer && cmpPlayer[check](targetOwner);272}273Engine.RegisterGlobal("LoadPlayerSettings", LoadPlayerSettings);274Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface);275Engine.RegisterGlobal("QueryPlayerIDInterface", QueryPlayerIDInterface);276Engine.RegisterGlobal("QueryMiragedInterface", QueryMiragedInterface);277Engine.RegisterGlobal("QueryBuilderListInterface", QueryBuilderListInterface);278Engine.RegisterGlobal("IsOwnedByAllyOfEntity", IsOwnedByAllyOfEntity);279Engine.RegisterGlobal("IsOwnedByMutualAllyOfEntity", IsOwnedByMutualAllyOfEntity);280Engine.RegisterGlobal("IsOwnedByPlayer", IsOwnedByPlayer);281Engine.RegisterGlobal("IsOwnedByGaia", IsOwnedByGaia);282Engine.RegisterGlobal("IsOwnedByAllyOfPlayer", IsOwnedByAllyOfPlayer);283Engine.RegisterGlobal("IsOwnedByMutualAllyOfPlayer", IsOwnedByMutualAllyOfPlayer);284Engine.RegisterGlobal("IsOwnedByNeutralOfPlayer", IsOwnedByNeutralOfPlayer);...

Full Screen

Full Screen

semantic-core.js

Source:semantic-core.js Github

copy

Full Screen

...40 SemanticCore.onStartup = function(cb) {41 // Register config directives42 var pluginService = new PluginService();43 // CSS directives44 pb.TemplateService.registerGlobal('semantic_core_simpletextrotator_css_src', function(flag, cb) {45 pluginService.getSetting('simpletextrotator_css_src', 'semantic-core', function(err, simpletextrotator_css_src) {46 cb(err, simpletextrotator_css_src);47 });48 });49 pb.TemplateService.registerGlobal('semantic_core_et_line_font_css_src', function(flag, cb) {50 pluginService.getSetting('et_line_font_css_src', 'semantic-core', function(err, etLineFontCSS) {51 cb(err, etLineFontCSS);52 });53 });54 pb.TemplateService.registerGlobal('semantic_core_magnific_popup_css_src', function(flag, cb) {55 pluginService.getSetting('magnific_popup_css_src', 'semantic-core', function(err, magnific_popup_css_src) {56 cb(err, magnific_popup_css_src);57 });58 });59 pb.TemplateService.registerGlobal('semantic_core_flexslider_css_src', function(flag, cb) {60 pluginService.getSetting('flexslider_css_src', 'semantic-core', function(err, flexslider_css_src) {61 cb(err, flexslider_css_src);62 });63 });64 pb.TemplateService.registerGlobal('semantic_core_animate_css_src', function(flag, cb) {65 pluginService.getSetting('animate_css_src', 'semantic-core', function(err, animate_css_src) {66 cb(err, animate_css_src);67 });68 });69 pb.TemplateService.registerGlobal('semantic_core_style_css_src', function(flag, cb) {70 pluginService.getSetting('style_css_src', 'semantic-core', function(err, style_css_src) {71 cb(err, style_css_src);72 });73 });74 pb.TemplateService.registerGlobal('semantic_core_custom_css_src', function(flag, cb) {75 pluginService.getSetting('custom_css_src', 'semantic-core', function(err, custom_css_src) {76 cb(err, custom_css_src);77 });78 });79 // JS directives80 pb.TemplateService.registerGlobal('semantic_core_YTPlayer_js_src', function(flag, cb) {81 pluginService.getSetting('YTPlayer_js_src', 'semantic-core', function(err, YTPlayer_js_src) {82 cb(err, YTPlayer_js_src);83 });84 });85 pb.TemplateService.registerGlobal('semantic_core_appear_js_src', function(flag, cb) {86 pluginService.getSetting('appear_js_src', 'semantic-core', function(err, appear_js_src) {87 cb(err, appear_js_src);88 });89 });90 pb.TemplateService.registerGlobal('semantic_core_simple_text_rotator_js_src', function(flag, cb) {91 pluginService.getSetting('simple_text_rotator_js_src', 'semantic-core', function(err, simple_text_rotator_js_src) {92 cb(err, simple_text_rotator_js_src);93 });94 });95 pb.TemplateService.registerGlobal('semantic_core_jq_bootstrap_validation_js_src', function(flag, cb) {96 pluginService.getSetting('jq_bootstrap_validation_js_src', 'semantic-core', function(err, jq_bootstrap_validation_js_src) {97 cb(err, jq_bootstrap_validation_js_src);98 });99 });100 pb.TemplateService.registerGlobal('semantic_core_gmaps_api_js_src', function(flag, cb) {101 pluginService.getSetting('gmaps_api_js_src', 'semantic-core', function(err, gmaps_api_js_src) {102 cb(err, gmaps_api_js_src);103 });104 });105 pb.TemplateService.registerGlobal('semantic_core_gmaps_custom_js_src', function(flag, cb) {106 pluginService.getSetting('gmaps_custom_js_src', 'semantic-core', function(err, gmaps_custom_js_src) {107 cb(err, gmaps_custom_js_src);108 });109 });110 pb.TemplateService.registerGlobal('semantic_core_isotope_js_src', function(flag, cb) {111 pluginService.getSetting('isotope_js_src', 'semantic-core', function(err, isotope_js_src) {112 cb(err, isotope_js_src);113 });114 });115 pb.TemplateService.registerGlobal('semantic_core_images_loaded_js_src', function(flag, cb) {116 pluginService.getSetting('images_loaded_js_src', 'semantic-core', function(err, images_loaded_js_src) {117 cb(err, images_loaded_js_src);118 });119 });120 pb.TemplateService.registerGlobal('semantic_core_jquery_flexislider_js_src', function(flag, cb) {121 pluginService.getSetting('jquery_flexislider_js_src', 'semantic-core', function(err, jquery_flexislider_js_src) {122 cb(err, jquery_flexislider_js_src);123 });124 });125 pb.TemplateService.registerGlobal('semantic_core_jquery_magnific_popup_js_src', function(flag, cb) {126 pluginService.getSetting('jquery_magnific_popup_js_src', 'semantic-core', function(err, jquery_magnific_popup_js_src) {127 cb(err, jquery_magnific_popup_js_src);128 });129 });130 pb.TemplateService.registerGlobal('semantic_core_jquery_fitvids_js_src', function(flag, cb) {131 pluginService.getSetting('jquery_fitvids_js_src', 'semantic-core', function(err, jquery_fitvids_js_src) {132 cb(err, jquery_fitvids_js_src);133 });134 });135 pb.TemplateService.registerGlobal('semantic_core_smoothscroll_js_src', function(flag, cb) {136 pluginService.getSetting('smoothscroll_js_src', 'semantic-core', function(err, smoothscroll_js_src) {137 cb(err, smoothscroll_js_src);138 });139 });140 pb.TemplateService.registerGlobal('semantic_core_wow_js_src', function(flag, cb) {141 pluginService.getSetting('wow_js_src', 'semantic-core', function(err, wow_js_src) {142 cb(err, wow_js_src);143 });144 });145 pb.TemplateService.registerGlobal('semantic_core_contact_js_src', function(flag, cb) {146 pluginService.getSetting('contact_js_src', 'semantic-core', function(err, contact_js_src) {147 cb(err, contact_js_src);148 });149 });150 pb.TemplateService.registerGlobal('semantic_core_custom_js_src', function(flag, cb) {151 pluginService.getSetting('custom_js_src', 'semantic-core', function(err, custom_js_src) {152 cb(err, custom_js_src);153 });154 });155 cb(null, true);156 };157 /**158 * Called when the application is gracefully shutting down. No guarantees are159 * provided for how much time will be provided the plugin to shut down.160 *161 * @param cb A callback that must be called upon completion. cb(Error, Boolean).162 * The result should be TRUE on success and FALSE on failure163 */164 SemanticCore.onShutdown = function(cb) {...

Full Screen

Full Screen

autoload.js

Source:autoload.js Github

copy

Full Screen

...4this.registeredGlobalsAutoloader = registeredGlobalsAutoloader;5this.scrapeRegisterGlobalSymbols = scrapeRegisterGlobalSymbols;6this.stripComments = stripComments;7/**8 * Typical autoloader. Takes a path and searches for `registerGlobal()` calls in .js files. More9 * specialized autoloaders can be built from this example, but this should be enough for the simple10 * global case.11 */12function registeredGlobalsAutoloader(require) {13 registerGlobal(registerGlobal);14 return {15 pattern: /\.js$/,16 require: function(path) {17 require(path.replace(/\.js$/, ''));18 },19 parse: scrapeRegisterGlobalSymbols,20 scope: global,21 };22}23/**24 * Very naive comment stripping. Extremely buggy, undependable, untested, and flawed by design.25 */26function stripComments(source) {27 return source.replace(/(?:\/{2}.*$)|\/\*[^]*?\*\//gm, '');28}29/**30 * Discover all globals registered via registerGlobal() in a file. This can detect calls of the31 * following patterns:32 *33 * registerGlobal(MyGlobal);34 * registerGlobal("MyGlobal", { ... });35 * registerGlobal(function MyGlobal() { ... });36 *37 * Don't do bullshit like this:38 *39 * for (var ii in globals) {40 * registerGlobal(globals[ii]);41 * }42 */43function scrapeRegisterGlobalSymbols(source, path) {44 // Don't find globals in this file45 if (source.indexOf("this indexOf() call will find itself") !== -1) {46 return [];47 }48 // Find all registerGlobal() calls in this source49 source = stripComments(source);50 var rx = /registerGlobal\((?: *function *)?["']?([a-zA-Z0-9$_]+) *(?:["']?|\)|,)/g;51 var symbols = [];52 for (var match = rx.exec(source); match !== null; match = rx.exec(source)) {53 symbols.push(match[1]);54 }55 // Make sure we didn't miss any registerGlobal()'s56 var count = 0;57 rx = /registerGlobal/g;58 match = rx.exec(source);59 while (match !== null) {60 ++count;61 match = rx.exec(source);62 }63 if (count !== symbols.length) {64 throw new Error('Failed to autoload ' + path + ':\n[' + symbols.join(',') + ']');65 }66 return symbols;67}68/**69 * Bring an object or function into global scope. If defining a function, this can take only one70 * argument. In that case, the function's `name` property becomes the name of the global symbol.71 */72function registerGlobal(name, fn) {73 if (arguments.length === 1) {74 if (name instanceof Function) {75 fn = name;76 name = fn.name;77 } else {78 throw new TypeError('Must specify name with non-Function');79 }80 }81 global[name] = fn;82}83/**84 * Traverse source code and install autoload hooks.85 *86 * `loaders` is an array of objects with the following properties:...

Full Screen

Full Screen

commentStep.js

Source:commentStep.js Github

copy

Full Screen

1const event = require('../event');2const recorder = require('../recorder');3const { MetaStep } = require('../step');4let currentCommentStep;5const defaultGlobalName = '__';6/**7 * Add descriptive nested steps for your tests:8 *9 * ```js10 * Scenario('project update test', async (I) => {11 * __`Given`;12 * const projectId = await I.have('project');13 *14 * __`When`;15 * projectPage.update(projectId, { title: 'new title' });16 *17 * __`Then`;18 * projectPage.open(projectId);19 * I.see('new title', 'h1');20 * })21 * ```22 * Steps prefixed with `__` will be printed as nested steps in `--steps` output:23 *24 * ```25 * Given26 * I have "project"27 * When28 * projectPage update29 * Then30 * projectPage open31 * I see "new title", "h1"32 * ```33 *34 * Also those steps will be exported to allure reports.35 *36 * This plugin can be used37 *38 * ### Config39 *40 * * `enabled` - (default: false) enable a plugin41 * * `regusterGlobal` - (default: false) register `__` template literal function globally. You can override function global name by providing a name as a value.42 *43 * ### Examples44 *45 * Registering `__` globally:46 *47 * ```js48 * plugins: {49 * commentStep: {50 * enabled: true,51 * registerGlobal: true52 * }53 * }54 * ```55 *56 * Registering `Step` globally:57 * ```js58 * plugins: {59 * commentStep: {60 * enabled: true,61 * registerGlobal: 'Step'62 * }63 * }64 * ```65 *66 * Using only local function names:67 * ```js68 * plugins: {69 * commentStep: {70 * enabled: true71 * }72 * }73 * ```74 * Then inside a test import a comment function from a plugin.75 * For instance, you can prepare Given/When/Then functions to use them inside tests:76 *77 * ```js78 * // inside a test79 * const step = codeceptjs.container.plugins('commentStep');80 *81 * const Given = () => step`Given`;82 * const When = () => step`When`;83 * const Then = () => step`Then`;84 * ```85 *86 * Scenario('project update test', async (I) => {87 * Given();88 * const projectId = await I.have('project');89 *90 * When();91 * projectPage.update(projectId, { title: 'new title' });92 *93 * Then();94 * projectPage.open(projectId);95 * I.see('new title', 'h1');96 * });97 * ```98 */99module.exports = function (config) {100 event.dispatcher.on(event.test.started, (test) => {101 currentCommentStep = null;102 });103 event.dispatcher.on(event.step.started, (step) => {104 if (currentCommentStep) {105 const metaStep = getRootMetaStep(step);106 metaStep.metaStep = currentCommentStep;107 }108 });109 if (config.registerGlobal) {110 if (config.registerGlobal === true) {111 config.registerGlobal = defaultGlobalName;112 }113 global[config.registerGlobal] = setCommentString;114 }115 return setCommentString;116};117function getRootMetaStep(step) {118 if (step.metaStep) return getRootMetaStep(step.metaStep);119 return step;120}121function setCommentString(string) {122 recorder.add('set comment metastep', () => {123 currentCommentStep = new MetaStep(String.raw(string), '');124 });...

Full Screen

Full Screen

deploy-commands.js

Source:deploy-commands.js Github

copy

Full Screen

1// Run this file to register slash commands2// Set registerGlobal to true to register for all guilds (can take and hour)3const { REST } = require('@discordjs/rest');4const { Routes } = require('discord-api-types/v9');5const { clientId, guildId, token } = require('./config.json');6const fs = require('fs');7// Change this to true to make slash commands globally avaliable instead of only8// in guildId9const registerGlobal = false;10const commands = [];11const commandFiles = fs.readdirSync('./commands')12 .filter(file => file.endsWith('.js'));13for (const file of commandFiles) {14 const command = require(`./commands/${file}`);15 commands.push(command.data.toJSON());16}17const rest = new REST({ version: '9' }).setToken(token);18// This ridculous looking code is called an IIFE19// Used as a shortcut for running some async code in a sync function20(async () => {21 try {22 console.log('Started refreshing application (/) commands.');23 console.log(`registerGlobal: ${registerGlobal}`);24 if (registerGlobal) {25 await rest.put(26 Routes.applicationCommands(clientId),27 { body: commands },28 );29 }30 else {31 await rest.put(32 Routes.applicationGuildCommands(clientId, guildId),33 { body: commands },34 );35 }36 console.log('Successfully reloaded application (/) commands.');37 }38 catch (error) {39 console.error(error);40 }41})();42/*43// Run this file to register slash commands44// Set registerGlobal to true to register for all guilds (can take and hour)45const { SlashCommandBuilder } = require('@discordjs/builders');46const { REST } = require('@discordjs/rest');47const { Routes } = require('discord-api-types/v9');48const { clientId, guildId, token } = require('./config.json');49// Change this to true to make slash commands globally avaliable instead of only50// in guildId51const registerGlobal = false;52// The slash commands to register53const commands = [54 new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),55 new SlashCommandBuilder().setName('server').setDescription('Replies server info!'),56 new SlashCommandBuilder().setName('user').setDescription('Replies user info!'),57]58 .map(command => command.toJSON());59const rest = new REST({ version: '9' }).setToken(token);60if (registerGlobal) {61 rest.put(Routes.applicationCommands(clientId), { body: commands })62 .then(() => console.log('Successfully registered application commands. Please wait one hour to take effect.'))63 .catch(console.error);64}65else {66 rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })67 .then(() => console.log('Successfully registered application commands.'))68 .catch(console.error);69}...

Full Screen

Full Screen

loader.js

Source:loader.js Github

copy

Full Screen

1"use strict"2 // global key for user preferred registration3var REGISTRATION_KEY = '@@any-promise/REGISTRATION',4 // Prior registration (preferred or detected)5 registered = null6/**7 * Registers the given implementation. An implementation must8 * be registered prior to any call to `require("any-promise")`,9 * typically on application load.10 *11 * If called with no arguments, will return registration in12 * following priority:13 *14 * For Node.js:15 *16 * 1. Previous registration17 * 2. global.Promise if node.js version >= 0.1218 * 3. Auto detected promise based on first sucessful require of19 * known promise libraries. Note this is a last resort, as the20 * loaded library is non-deterministic. node.js >= 0.12 will21 * always use global.Promise over this priority list.22 * 4. Throws error.23 *24 * For Browser:25 *26 * 1. Previous registration27 * 2. window.Promise28 * 3. Throws error.29 *30 * Options:31 *32 * Promise: Desired Promise constructor33 * global: Boolean - Should the registration be cached in a global variable to34 * allow cross dependency/bundle registration? (default true)35 */36module.exports = function(root, loadImplementation){37 return function register(implementation, opts){38 implementation = implementation || null39 opts = opts || {}40 // global registration unless explicitly {global: false} in options (default true)41 var registerGlobal = opts.global !== false;42 // load any previous global registration43 if(registered === null && registerGlobal){44 registered = root[REGISTRATION_KEY] || null45 }46 if(registered !== null47 && implementation !== null48 && registered.implementation !== implementation){49 // Throw error if attempting to redefine implementation50 throw new Error('any-promise already defined as "'+registered.implementation+51 '". You can only register an implementation before the first '+52 ' call to require("any-promise") and an implementation cannot be changed')53 }54 if(registered === null){55 // use provided implementation56 if(implementation !== null && typeof opts.Promise !== 'undefined'){57 registered = {58 Promise: opts.Promise,59 implementation: implementation60 }61 } else {62 // require implementation if implementation is specified but not provided63 registered = loadImplementation(implementation)64 }65 if(registerGlobal){66 // register preference globally in case multiple installations67 root[REGISTRATION_KEY] = registered68 }69 }70 return registered71 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...39};40exports.Command = require('selenium-webdriver/lib/command').Command;41exports.CommandName = require('selenium-webdriver/lib/command').Name;42Object.defineProperty(exports, 'protractor', { get: function () { return global['protractor']; } });43function registerGlobal(name) {44 Object.defineProperty(exports, name, { get: function () { return exports.protractor ? exports.protractor[name] : undefined; } });45}46registerGlobal('browser');47registerGlobal('$');48registerGlobal('$$');49registerGlobal('element');50registerGlobal('By');51registerGlobal('by');...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

...17 root[key] = deps[key];18 });19}2021registerGlobal(window, {22 vue: Vue,23 HelloWorld: HelloWorld24})25 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2protractor.browser.driver.manage().window().maximize();3protractor.browser.getTitle().then(function(title) {4 console.log('Title is: ' + title);5});6var webdriver = require('selenium-webdriver');7webdriver.promise.USE_PROMISE_MANAGER = false;8webdriver.promise.controlFlow().on('uncaughtException', function(e) {9});10webdriver.promise.controlFlow().on('unhandledRejection', function(e) {11});12webdriver.promise.controlFlow().on('rejectionHandled', function(e) {13});14webdriver.promise.controlFlow().on('scheduled', function(e) {15});16webdriver.promise.controlFlow().on('complete', function(e) {17});18webdriver.promise.controlFlow().on('idle', function(e) {19});20webdriver.promise.controlFlow().on('active', function(e) {21});22webdriver.promise.controlFlow().on('timeout', function(e) {23});24webdriver.promise.controlFlow().on('cancelled', function(e) {25});26webdriver.promise.controlFlow().on('stopped', function(e) {27});28webdriver.promise.controlFlow().on('reset', function(e) {29});30var jasmine = require('jasmine');31jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(console.log));32jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));33var jasmine2 = require('jasmine2');34jasmine2.getEnv().addReporter(new jasmine2.ConsoleReporter(console.log));35jasmine2.getEnv().addReporter(new jasmine2.JUnitXmlReporter('xmloutput', true, true));36var chai = require('chai');37chai.should();38chai.expect();39chai.assert();40var mocha = require('mocha');41mocha.setup('bdd');42var mocha2 = require('mocha2

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2protractor.browser.driver.manage().window().maximize();3protractor.browser.getTitle().then(function(title) {4 console.log(title);5});6browser.driver.manage().window().maximize();7browser.getTitle().then(function(title) {8 console.log(title);9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var browser = protractor.browser;3var ptor = protractor.getInstance();4ptor.registerGlobal('globalVar', 'globalValue');5ptor.registerGlobal('globalVar2', 'globalValue2');6describe('test', function() {7 it('test', function() {8 expect(globalVar).toBe('globalValue');9 expect(globalVar2).toBe('globalValue2');10 });11});12exports.config = {13 onPrepare: function() {14 var protractor = require('protractor');15 var ptor = protractor.getInstance();16 ptor.registerGlobal('globalVar', 'globalValue');17 ptor.registerGlobal('globalVar2', 'globalValue2');18 }19}20describe('test', function() {21 beforeAll(function() {22 var protractor = require('protractor');23 var ptor = protractor.getInstance();24 ptor.registerGlobal('globalVar', 'globalValue');25 ptor.registerGlobal('globalVar2', 'globalValue2');26 });27 it('test', function() {28 expect(globalVar).toBe('globalValue');29 expect(globalVar2).toBe('globalValue2');30 });31});32describe('test', function() {33 before(function() {34 var protractor = require('protractor');35 var ptor = protractor.getInstance();36 ptor.registerGlobal('globalVar', 'globalValue');

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var ptor = protractor.getInstance();3ptor.registerGlobal('myGlobal', function() {4 return 'value';5});6var myGlobal = global.myGlobal;7var protractor = require('protractor');8var ptor = protractor.getInstance();9ptor.registerGlobal('myGlobal', function() {10 return 'value';11});12var myGlobal = ptor.getRegisteredGlobal('myGlobal');

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var browser = protractor.browser;3browser.driver.manage().window().maximize();4browser.sleep(5000);5browser.driver.quit();6var protractor = require('protractor');7var browser = protractor.browser;8browser.driver.manage().window().maximize();9browser.sleep(5000);10browser.driver.quit();11var protractor = require('protractor');12var browser = protractor.browser;13browser.driver.manage().window().maximize();14browser.sleep(5000);15browser.driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var ptor = protractor.getInstance();3var global = ptor.registerGlobal('global', function() {4 return {5 };6});7var name = global.name;8var age = global.age;9console.log(name);10console.log(age);11var protractor = require('protractor');12var ptor = protractor.getInstance();13var module = ptor.registerModule('module', function() {14 return {15 };16});17var name = module.name;18var age = module.age;19console.log(name);20console.log(age);21var protractor = require('protractor');22var ptor = protractor.getInstance();23var module = ptor.registerModule('module', function() {24 return {25 };26});27var name = module.name;28var age = module.age;29console.log(name);30console.log(age);31var protractor = require('protractor');32var ptor = protractor.getInstance();33var module = ptor.registerModule('module', function() {34 return {35 };36});37var name = module.name;38var age = module.age;39console.log(name);40console.log(age);41var protractor = require('protractor');42var ptor = protractor.getInstance();43var module = ptor.registerModule('module', function() {44 return {45 };46});47var name = module.name;48var age = module.age;49console.log(name);50console.log(age);51var protractor = require('protractor');52var ptor = protractor.getInstance();53var module = ptor.registerModule('module', function() {54 return {

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var global = protractor.registerGlobal();3var using = require('jasmine-data-provider');4var data = require('./data.js');5describe('Protractor Demo App', function() {6 it('should have a title', function() {7 expect(browser.getTitle()).toEqual('Super Calculator');8 });9 global.testData = data.testData;10 using(data.testData, function (data, description) {11 it('should add one and two', function() {12 element(by.model('first')).sendKeys(data.first);13 element(by.model('second')).sendKeys(data.second);14 element(by.id('gobutton')).click();15 toEqual(data.result);16 });17 });18});19var protractor = require('protractor');20var global = protractor.registerGlobal();21exports.testData = {22 "Addition": {23 },24 "Subtraction": {25 }26};27exports.config = {28 onPrepare: function() {29 global = protractor.registerGlobal();30 }31};32global.testData = data.testData;33using(global.testData, function (data, description) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var protractor = require('protractor');2var protractor = require('protractor');3var protractor = require('protractor');4var protractor = require('protractor');5var protractor = require('protractor');6var protractor = require('protractor');7var protractor = require('protractor');8var protractor = require('protractor');9var protractor = require('protractor');10var protractor = require('protractor');11var protractor = require('protractor');12var protractor = require('protractor');

Full Screen

Selenium Protractor Tutorial

Protractor is developed by Google Developers to test Angular and AngularJS code. Today, it is used to test non-Angular applications as well. It performs a real-world user-like test against your application in a real browser. It comes under an end-to-end testing framework. As of now, Selenium Protractor has proved to be a popular framework for end-to-end automation for AngularJS.

Let’s talk about what it does:

  • Protractor, built on WebDriver JS (Selenium), offers Angular-specific locator strategies.
  • It helps to construct automated tests for applications other than Angular JS and is not just intended to test AngularJS applications.
  • Page object design pattern is supported by Protractor Selenium, which improves in producing clear and legible code. Automation testers need to write clean code.
  • Frameworks like Jasmine, Cucumber, and others are fully integrated with Protractor.

Chapters:

Protractor is a JavaScript framework, end-to-end test automation framework for Angular and AngularJS applications.

Protractor Selenium provides new locator methods that actually make it easier to find elements in the DOM.

Two files are required to execute Protractor Selenium tests for end-to-end automation: Specs & Config. Go through the link above to understand in a better way.

To carry out extensive, automated cross browser testing, you can't imagine installing thousands of the available browsers on your own workstation. The only way to increase browser usage is through remote execution on the cloud. To execute your automation test scripts across a variety of platforms and browser versions, LambdaTest offers more than 3000 browsers.

We recommend Selenium for end-to-end automation for AngularJS because both are maintained and owned by Google, and they build JavaScript test automation framework to handle AngularJS components in a way that better matches how developers use it.

For scripting, selenium locators are essential since if they're off, your automation scripts won't run. Therefore, in any testing framework, these Selenium locators are the foundation of your Selenium test automation efforts.

To make sure that your Selenium automation tests function as intended, debugging can be an effective option. Check the blog to know more.

Get familiar with global variables that are majorly used in locating the DOM elements with examples for better understanding of these Selenium locators in protractor.

If you are not familiar with writing Selenium test automation on Protractor, here is a blog for you to get you understand in depth.

Selenium tests are asynchronous and there are various reasons for a timeout to occur in a Protractor test. Find out how to handle timeouts in this Protractor tutorial.

In this Protractor tutorial, learn how to handle frames or iframes in Selenium with Protractor for automated browser testing.

Handle alerts and popups in Protractor more efficiently. It can be confusing. Here's a simple guide to understand how to handle alerts and popups in Selenium.

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