Best JavaScript code snippet using appium-base-driver
FLPAnalytics.qunit.js
Source:FLPAnalytics.qunit.js
1// Copyright (c) 2009-2020 SAP SE, All Rights Reserved2/**3 * @fileOverview QUnit tests for sap.ushell.components.homepage.FLPAnalytics4 * Tests the following use-cases: (which are not tested as part of other modules, e.g. DashboardManager)5 * - Launching an application6 * - By appOpened event7 * - By NavContainer AfterNavigate event8 * - Save as Tile (add bookmark)9 * - Activate action mode10 * - Most used application launching source11 *12 * For all the tests there is a stub implementation of getService that returns another stub for the function logCustomEvent.13 * The idea is to publish the relevant event (e.g. appOpened, bookmarkTileAdded, etc..) and to check the corresponding call to UsageAnalytics service function logCustomEvent.14 * Also: in each test case, the hash is being set using window.location.hash, and the test also verifies that window.swa.custom1.ref got the correct hash value15 */16(function () {17 "use strict";18 /* global module, ok, start, stop, test, hasher, sinon */19 jQuery.sap.require("sap.ushell.services.Container");20 jQuery.sap.require("sap.ushell.ui.AppContainer");21 jQuery.sap.require("sap.ui.core.theming.Parameters");22 var oNavContainer = new sap.ushell.ui.AppContainer({23 id: "viewPortContainer",24 pages: []25 }),26 oUsageAnalyticsLogStub,27 oGetServiceStub;28 jQuery.sap.require("sap.ui.thirdparty.hasher");29 module("sap.ushell.components.homepage.FLPAnalytics", {30 setup: function () {31 stop();32 sap.ushell.bootstrap("local").then(function () {33 window.swa = {};34 oUsageAnalyticsLogStub = sinon.stub().returns({});35 oGetServiceStub = sinon.stub(sap.ushell.Container, "getService");36 oGetServiceStub.returns({ logCustomEvent: oUsageAnalyticsLogStub });37 jQuery.sap.require("sap.ushell.components.homepage.FLPAnalytics");38 start();39 });40 },41 teardown: function () {42 delete sap.ushell.Container;43 window.location.hash = "";44 }45 });46 test("Open application logging", function () {47 hasher.setHash("businessObject0-action0");48 sap.ushell.services.AppConfiguration = {49 getMetadata: function () {50 return { title: "appTitle0" };51 }52 };53 sap.ui.getCore().getEventBus().publish("sap.ushell", "appOpened", {});54 ok(window.swa.custom1.ref === "businessObject0-action0", "swa.custom1.ref contains the correct hash");55 ok(oUsageAnalyticsLogStub.calledOnce === true, "Called once");56 ok(oUsageAnalyticsLogStub.args[0][0] === "FLP: Application Opened", "logCustomEvent called with type 'FLP: Application Opened'");57 ok(oUsageAnalyticsLogStub.args[0][1] === "Direct Launch", "logCustomEvent called with event value 'Direct Launch'");58 ok(oUsageAnalyticsLogStub.args[0][2][0] === "appTitle0", "logCustomEvent called with application title 'appTitle0'");59 });60 test("After navigation logging", function () {61 var oAfterNavigateData = {62 from: {63 getId: function () {64 return "applicationShellPage-previousBusinessObject-action";65 }66 },67 to: {68 getId: function () {69 return "applicationShellPage-businessObject1-action1";70 }71 }72 };73 sap.ushell.services.AppConfiguration = {74 getMetadata: function () {75 return { title: "appTitle1" };76 }77 };78 oNavContainer.fireAfterNavigate(oAfterNavigateData);79 ok(window.swa.custom1.ref === "businessObject1-action1", "swa.custom1.ref contains the correct hash");80 ok(oUsageAnalyticsLogStub.args[0][0] === "FLP: Application Opened", "logCustomEvent called with event type 'FLP: Application Opened'");81 ok(oUsageAnalyticsLogStub.args[0][1] === "Fiori Navigation", "logCustomEvent called with event value 'Through navContainer'");82 ok(oUsageAnalyticsLogStub.args[0][2][0] === "appTitle1", "logCustomEvent called with application title 'appTitle1'");83 oNavContainer.destroy();84 });85 test("Save as Tile logging", function () {86 var oData = {87 tile: { title: "tileTitle" },88 group: {89 title: "groupTitle",90 id: "groupId"91 }92 };93 hasher.setHash("businessObject2-action2");94 window.document.title = "Application Title";95 sap.ui.getCore().getEventBus().publish("sap.ushell.services.Bookmark", "bookmarkTileAdded", oData);96 ok(window.swa.custom1.ref === "businessObject2-action2", "swa.custom1.ref contains the correct hash");97 ok(oUsageAnalyticsLogStub.args[0][0] === "FLP: Personalization", "logCustomEvent called with event type 'FLP: Personalization'");98 ok(oUsageAnalyticsLogStub.args[0][1] === "Save as Tile", "logCustomEvent called with event value 'Save as Tile'");99 ok(oUsageAnalyticsLogStub.args[0][2][0] === "Application Title", "logCustomEvent called with application title 'Application Title'");100 ok(oUsageAnalyticsLogStub.args[0][2][1] === "groupTitle", "logCustomEvent called with group title'groupTitle'");101 ok(oUsageAnalyticsLogStub.args[0][2][2] === "groupId", "logCustomEvent called with group Id 'groupId'");102 ok(oUsageAnalyticsLogStub.args[0][2][3] === "tileTitle", "logCustomEvent called with tile title 'tileTitle'");103 });104 test("Activate action mode logging", function () {105 var oData = { source: "Floating Button" };106 hasher.setHash("businessObject3-action3");107 sap.ui.getCore().getEventBus().publish("launchpad", "actionModeActive", oData);108 ok(window.swa.custom1.ref === "businessObject3-action3", "swa.custom1.ref contains the correct hash");109 ok(oUsageAnalyticsLogStub.args[0][0] === "FLP: Personalization", "logCustomEvent called with event type 'FLP: Personalization'");110 ok(oUsageAnalyticsLogStub.args[0][1] === "Enter Action Mode", "logCustomEvent called with event value 'Enter Action Mode'");111 ok(oUsageAnalyticsLogStub.args[0][2][0] === "Floating Button", "logCustomEvent called with array value 'Floating Button'");112 });113 test("Most used source logging", function () {114 var index,115 oData;116 for (index = 0; index < 5; index++) {117 window.location.hash = "businessObject" + index + "-action" + index;118 sap.ui.getCore().getEventBus().publish("launchpad", "catalogTileClick");119 }120 for (index = 5; index < 10; index++) {121 window.location.hash = "businessObject" + index + "-action" + index;122 sap.ui.getCore().getEventBus().publish("launchpad", "dashboardTileClick");123 }124 window.location.hash = "businessObjectForLink-actionForLink";125 for (index = 10; index < 15; index++) {126 oData = { targetHash: "#businessObject" + index + "-action" + index };127 sap.ui.getCore().getEventBus().publish("launchpad", "dashboardTileLinkClick", oData);128 }129 ok(oUsageAnalyticsLogStub.callCount === 15, "logCustomEvent was called 15 times");130 ok(oUsageAnalyticsLogStub.args[0][0] === "FLP: Application Launch point", "1st Event type is 'FLP: Application Launch point'");131 ok(oUsageAnalyticsLogStub.args[0][1] === "Catalog", "1st Event value 'Catalog'");132 ok(oUsageAnalyticsLogStub.args[5][0] === "FLP: Application Launch point", "5th Event type is 'FLP: Application Launch point'");133 ok(oUsageAnalyticsLogStub.args[5][1] === "Homepage", "5th Event value is 'Homepage'");134 ok(oUsageAnalyticsLogStub.args[10][0] === "FLP: Application Launch point", "10th Event type is 'FLP: Application Launch point'");135 ok(oUsageAnalyticsLogStub.args[10][1] === "Tile Group Link", "10th Event value is 'Tile Group Link'");136 });...
FLPAnalytics-dbg.js
Source:FLPAnalytics-dbg.js
1sap.ui.define(function() {2 "use strict";34 /*global jQuery, sap, hasher */5 /**6 * Manage UsageAnalytics event logging as a result of FLP user flows7 */89 // Launchpad action events that trigger logging10 var aObservedLaunchpadActions = ["appOpened", "deleteTile", "createGroup", "actionModeActive", "catalogTileClick", "dashboardTileClick", "dashboardTileLinkClick"],11 oEventBus = sap.ui.getCore().getEventBus(),12 that = this,13 oLaunchedApplications = {};1415 /**16 * Updates oLaunchedApplications with the title and opening time of the given application17 */18 function saveOpenAppicationData(applicationId) {19 var oMetadataOfTarget = sap.ushell.services.AppConfiguration.getMetadata();20 oLaunchedApplications[applicationId] = {};21 oLaunchedApplications[applicationId].startTime = new Date();22 oLaunchedApplications[applicationId].title = oMetadataOfTarget.title;23 }2425 /**26 * Logs a "Time in App" event according to the given application ID27 *28 * Calculates the time according to the current (closing) time29 * and the opening time that is kept on oLaunchedApplications[applicationId]30 */31 function logTimeInAppEvent(applicationId) {32 var appDuration = 0;3334 try {35 appDuration = (new Date() - oLaunchedApplications[applicationId].startTime) / 1000;36 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Time in Application (sec)", appDuration, [oLaunchedApplications[applicationId].title]);37 } catch (e) {38 jQuery.sap.log.warning("Duration in application " + applicationId + " could not be calculated", null, "sap.ushell.components.flp.FLPAnalytics");39 }40 }4142 /**43 * Handler for published usageAnalytics events.44 */45 function handleAction(sChannelId, sEventId, oData) {46 var sApplicationId = hasher.getHash(),47 sApplicationTitle;4849 window.swa.custom1 = {ref: sApplicationId};50 switch (sEventId) {51 case 'appOpened':52 // In order to be notified when applications are launched - we rely on navContainer's attachAfterNavigate event.53 // but for the first navigation (e.g. login or direct URL in a new tab) we still need the "appOpened" event.54 saveOpenAppicationData(sApplicationId);55 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Application Opened", "Direct Launch", [oLaunchedApplications[sApplicationId].title]);56 oEventBus.unsubscribe("launchpad", "appOpened", handleAction);57 break;58 case 'bookmarkTileAdded':59 sApplicationTitle = window.document.title;60 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Personalization", "Save as Tile", [61 sApplicationTitle,62 oData && oData.group && oData.group.title ? oData.group.title : "",63 oData && oData.group && oData.group.id ? oData.group.id : "",64 oData && oData.tile && oData.tile.title ? oData.tile.title : sApplicationTitle65 ]);66 break;67 case 'actionModeActive':68 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Personalization", "Enter Action Mode", [oData.source]);69 break;70 case 'catalogTileClick':71 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Application Launch point", "Catalog", []);72 break;73 case 'dashboardTileClick':74 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Application Launch point", "Homepage", []);75 break;76 case 'dashboardTileLinkClick':77 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Application Launch point", "Tile Group Link", []);78 break;79 default:80 break;81 }82 }8384 /**85 * Handler of navContainer's AfterNavigate event (i.e. navigation between the container's pages)86 *87 * - Logs "TimeInAppEvent" for the source application (i.e. from which the navigation occurred)88 * - Updated data about the opened application89 * - Logs "Application Opened" event90 */91 function handleAfterNavigate(oEvent) {92 var sFromApplicationId,93 sToApplicationId,94 oTargetApplication;9596 // For the source application (the one from which the user navigates) -97 // Calculate the time duration and log a "Time in Application" event98 if (oEvent.getParameter("from") && oEvent.getParameter("to")) {99 sFromApplicationId = oEvent.getParameter("from").getId().replace("application-", "").replace("applicationShellPage-", "");100 window.swa.custom1 = {ref: sFromApplicationId};101 logTimeInAppEvent(sFromApplicationId);102 // For the target application (the one to which the user navigates) -103 // Keep the opening time and title, and log an "Application Opened" event104 oTargetApplication = oEvent.getParameter("to");105 sToApplicationId = oTargetApplication.getId().replace("application-", "").replace("applicationShellPage-", "");106 saveOpenAppicationData(sToApplicationId);107 window.swa.custom1 = {ref: sToApplicationId};108 sap.ushell.Container.getService("UsageAnalytics").logCustomEvent("FLP: Application Opened", "Fiori Navigation", [oLaunchedApplications[sToApplicationId].title]);109 }110 }111112 /**113 * Handler of browser tab close event114 *115 * Logs a "Time in App" event116 */117 jQuery(window).unload(function (event) {118 var currentApp = window.location.hash.substr(1);119 logTimeInAppEvent(currentApp);120 });121122 try {123 sap.ui.getCore().byId('viewPortContainer').attachAfterNavigate(handleAfterNavigate, that);124 } catch (e) {125 jQuery.sap.log.warning("Failure when subscribing to viewPortContainer 'AfterNavigate' event", null, "sap.ushell.components.flp.FLPAnalytics");126 }127 oEventBus.subscribe("sap.ushell.services.Bookmark", "bookmarkTileAdded", handleAction, that);128 aObservedLaunchpadActions.forEach(function (item, i, arr) {129 oEventBus.subscribe("launchpad", item, handleAction, that);130 });131132
...
UsageAnalyticsConsumer-dbg.js
Source:UsageAnalyticsConsumer-dbg.js
1/* global jQuery, sap, window */23sap.ui.define([4 'sap/ushell/renderers/fiori2/search/eventlogging/EventConsumer'5], function(EventConsumer) {6 "use strict";78 // =======================================================================9 // import packages10 // =======================================================================11 var sinaBaseModule = window.sinabase;1213 // =======================================================================14 // declare package15 // =======================================================================16 jQuery.sap.declare('sap.ushell.renderers.fiori2.search.eventlogging.UsageAnalyticsConsumer');1718 // =======================================================================19 // SinaEventConsumer20 // =======================================================================21 var module = sap.ushell.renderers.fiori2.search.eventlogging.UsageAnalyticsConsumer = function() {22 this.init.apply(this, arguments);23 };2425 module.prototype = jQuery.extend(new EventConsumer(), {2627 collectEvents: false,2829 init: function() {30 try {31 this.analytics = sap.ushell.Container.getService("UsageAnalytics");32 } catch (e) { /* empty */ }33 },3435 logEvent: function(event) {36 if (!this.analytics) {37 return;38 }39 switch (event.type) {40 case this.eventLogger.ITEM_NAVIGATE:41 this.analytics.logCustomEvent('FLP: Search', 'Launch Object', [event.targetUrl]);42 break;43 case this.eventLogger.SUGGESTION_SELECT:44 switch (event.suggestionType) {45 case sinaBaseModule.SuggestionType.APPS:46 this.analytics.logCustomEvent('FLP: Search', 'Suggestion Select App', [47 event.suggestionTitle,48 event.targetUrl,49 event.searchTerm50 ]);51 this.analytics.logCustomEvent('FLP: Application Launch point', 'Search Suggestions', [52 event.suggestionTitle,53 event.targetUrl,54 event.searchTerm55 ]);56 break;57 case sinaBaseModule.SuggestionType.DATASOURCE:58 this.analytics.logCustomEvent('FLP: Search', 'Suggestion Select Datasource', [59 event.dataSourceKey,60 event.searchTerm61 ]);62 break;63 case sinaBaseModule.SuggestionType.OBJECTDATA:64 this.analytics.logCustomEvent('FLP: Search', 'Suggestion Select Object Data', [65 event.suggestionTerm,66 event.dataSourceKey,67 event.searchTerm68 ]);69 break;70 case sinaBaseModule.SuggestionType.HISTORY:71 this.analytics.logCustomEvent('FLP: Search', 'Suggestion Select Object Data', [72 event.suggestionTerm,73 event.dataSourceKey,74 event.searchTerm75 ]);76 break;77 }78 break;79 case this.eventLogger.SEARCH_REQUEST:80 this.analytics.logCustomEvent('FLP: Search', 'Search', [81 event.searchTerm,82 event.dataSourceKey83 ]);84 break;85 case this.eventLogger.ITEM_NAVIGATE_RELATED_OBJECT:86 this.analytics.logCustomEvent('FLP: Search', 'Launch Related Object', [event.targetUrl]);87 break;88 case this.eventLogger.SUGGESTION_REQUEST:89 this.analytics.logCustomEvent('FLP: Search', 'Suggestion', [90 event.suggestionTerm,91 event.dataSourceKey92 ]);93 break;94 case this.eventLogger.TILE_NAVIGATE:95 this.analytics.logCustomEvent('FLP: Search', 'Launch App', [96 event.tileTitle,97 event.targetUrl98 ]);99 this.analytics.logCustomEvent('FLP: Application Launch point', 'Search Results', [100 event.titleTitle,101 event.targetUrl102 ]);103 break;104 }105 }106 });107108 return module;
...
fba.js
Source:fba.js
1"use strict";2const request = require("request");3class FBA {4 constructor(config) {5 if (!config) {6 config = {};7 }8 this.app_id = config.app_id;9 this.page_id = config.page_id;10 }11 logCSATResponse(rating, psid) {12 const event = {13 _eventName: "customer_care_csat",14 rating: rating,15 }16 return this.logCustomEvent(psid, event);17 }18 logNPSResponse(rating, psid) {19 const event = {20 _eventName: "customer_care_nps",21 rating: rating,22 }23 return this.logCustomEvent(psid, event);24 }25 logCustomEvent(psid, event) {26 return new Promise (async (resolve, reject) => {27 if (!psid) {28 reject("PSID required");29 }30 if (!event) {31 reject("Event undefined");32 }33 if (!this.app_id) {34 reject("App ID not initialized");35 }36 if (!this.page_id) {37 reject("Page ID not initialized");38 }39 40 request.post(41 {42 url : `https://graph.facebook.com/${this.app_id}/activities`,43 form: {44 event: "CUSTOM_APP_EVENTS",45 custom_events: JSON.stringify([event]),46 advertiser_tracking_enabled: 1,47 application_tracking_enabled: 1,48 extinfo: JSON.stringify(["mb1"]),49 page_id: this.page_id,50 page_scoped_user_id: psid51 }52 }, (error, response, body) => { 53 if (error) {54 reject(error, body);55 }56 if (body.error) {57 reject(body);58 }59 if (typeof body === "string") body = JSON.parse(body);60 resolve(body);61 }62 );63 });64 }65}...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var caps = {4};5 .init(caps)6 .then(function() {7 return driver.logCustomEvent('myevent', 'mydata');8 })9 .then(function() {10 return driver.logCustomEvent('myevent', {foo: 'bar'});11 })12 .then(function() {13 return driver.logCustomEvent('myevent', {foo: 'bar'}, 'mydata');14 })15 .then(function() {16 return driver.logCustomEvent('myevent', {foo: 'bar'}, {foo: 'bar'});17 })18 .then(function() {19 return driver.logCustomEvent('myevent', {foo: 'bar'}, {foo: 'bar'}, 'mydata');20 })21 .then(function() {22 return driver.logCustomEvent('myevent', {foo: 'bar'}, {foo: 'bar'}, {foo: 'bar'});23 })24 .then(function() {25 return driver.logCustomEvent('myevent', {foo: 'bar'}, {foo: 'bar'}, {foo: 'bar'}, 'mydata');26 })27 .catch(function(err) {28 console.log(err);29 });30from appium import webdriver31from appium.webdriver.common.touch_action import TouchAction32caps = {33}34driver.log_custom_event('myevent', 'mydata')35driver.log_custom_event('myevent', {'foo': 'bar'})36driver.log_custom_event('myevent', {'foo': 'bar'}, 'mydata')37driver.log_custom_event('myevent', {'foo':
Using AI Code Generation
1import { ios } from 'appium-ios-driver';2import { android } from 'appium-android-driver';3import { BaseDriver } from 'appium-base-driver';4const iosDriver = new ios.Driver();5const androidDriver = new android.Driver();6const baseDriver = new BaseDriver();7baseDriver.logCustomEvent('ios', {foo: bar});8iosDriver.logCustomEvent('ios', {foo: bar});9androidDriver.logCustomEvent('android', {foo: bar});10import { ios } from 'appium-ios-driver';11import { android } from 'appium-android-driver';12import { BaseDriver } from 'appium-base-driver';13const iosDriver = new ios.Driver();14const androidDriver = new android.Driver();15const baseDriver = new BaseDriver();16baseDriver.logCustomEvent('ios', {foo: bar});17iosDriver.logCustomEvent('ios', {foo: bar});18androidDriver.logCustomEvent('android', {foo: bar});19import { ios } from 'appium-ios-driver';20import { android } from 'appium-android-driver';21import { BaseDriver } from 'appium-base-driver';22const iosDriver = new ios.Driver();23const androidDriver = new android.Driver();24const baseDriver = new BaseDriver();25baseDriver.logCustomEvent('ios', {foo: bar});26iosDriver.logCustomEvent('ios', {foo: bar});27androidDriver.logCustomEvent('android', {foo: bar});
Using AI Code Generation
1const d = new AppiumDriver();2d.logCustomEvent("testEvent", {foo: "bar"});3async logCustomEvent (eventName, params) {4 this.logEvent('appiumEvent', {event: eventName, params});5}6async logEvent (eventType, eventData) {7 this.emit(eventType, eventData);8}9async logEvent (eventType, eventData) {10 this.emit(eventType, eventData);11}12async logEvent (eventType, eventData) {13 this.emit(eventType, eventData);14}15async logEvent (eventType, eventData) {16 this.emit(eventType, eventData);17}18async logEvent (eventType, eventData) {19 this.emit(eventType, eventData);20}21async logEvent (eventType, eventData) {22 this.emit(eventType, eventData);23}24async logEvent (eventType, eventData) {25 this.emit(eventType, eventData);26}27async logEvent (eventType, eventData) {28 this.emit(eventType, eventData);29}30async logEvent (eventType, eventData) {31 this.emit(eventType, eventData);32}33async logEvent (eventType, eventData) {34 this.emit(eventType, eventData);35}36async logEvent (
Using AI Code Generation
1d.logCustomEvent('testEvent', {message: 'testMessage'});2async logCustomEvent (eventName, eventData) {3 console.log(`Event Name: ${eventName}`);4 console.log(`Event Data: ${JSON.stringify(eventData)}`);5 }6commands.logCustomEvent = async function (eventName, eventData) {7 return await this.logCustomEvent(eventName, eventData);8 };9export { logCustomEvent } from './log';10import { logCustomEvent } from './commands';11import { logCustomEvent } from './log';12commands.logCustomEvent = async function (eventName, eventData) {13 return await this.logCustomEvent(eventName, eventData);14 };15import { logCustomEvent } from './commands';16import { logCustomEvent } from './log';17import { logCustomEvent } from './commands';18import { logCustomEvent } from './log';19import { logCustomEvent } from './log';20import { logCustomEvent } from './commands';21import { logCustomEvent } from './log';22import { logCustomEvent } from './commands';23import { logCustomEvent } from './log';24import { logCustomEvent } from './commands
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!!