Best JavaScript code snippet using playwright-internal
utils.js
Source:utils.js
1(function($, app, Urls) {2 // SIP3 var popup;4 app.SIP = {5 init: function(fn, failed) {6 popup = window.open("", "Popup", "width=400,height=500");7 // Pop-ups are not allowed8 if (!popup) {9 failed();10 return;11 }12 if (popup.location.href === "about:blank") {13 popup.close();14 popup = window.open(Urls.popup, "Popup", "width=400,height=500");15 popup.onload = function () {16 fn();17 //popup.onunload = function () {18 //};19 };20 } else {21 fn();22 //popup.onunload = function () {23 //};24 }25 window.focus();26 },27 connect: function(sipData) {28 popup.connect(sipData);29 },30 connection: function() {31 return popup.getConnection();32 },33 disconnect: function() {34 popup.kill();35 }36 };37 // Sounds38 try {39 var ringtone = new Audio(Urls.ringtone);40 var backtone = new Audio(Urls.ringbacktone);41 var dtmf = new Audio(Urls.dtmf);42 } catch(e) {43 44 }45 app.Sounds = {46 playRingtone: function () {47 try {48 ringtone.play();49 } catch (e) {50 } 51 },52 playBacktone: function() {53 try {54 backtone.play();55 } catch (e) {56 }57 },58 playDtmf: function() {59 try {60 dtmf.play();61 } catch (e) {62 }63 }64 };65 // Auth66 app.Auth = {67 signIn: function (login, pass) {68 var postData = {69 login: login,70 password: pass,71 format: 'json'72 };73 return ajaxRequest("post", Urls.auth, postData);74 }75 };76 function ajaxRequest(type, url, data, dataType) {77 //var options = {78 // dataType: dataType || "json",79 // contentType: "application/json",80 // cache: false,81 // type: type,82 // data: data ? JSON.stringify(data) : null83 //};84 var options = {85 dataType: dataType || "json",86 cache: false,87 type: type,88 data: data ? data : null89 };90 return $.ajax(url, options);91 }92 // Storage93 var SIP_DATA_STORAGE_NAMESPACE = "callcenter.softphone.sipdata";94 var KEYPAD_VISIBLE_STORAGE_NAMESPACE = "callcenter.softphone.keypadvisible";95 app.Storage = {96 sipData: function (value) {97 if (arguments.length > 0) {98 localStorage.setItem(SIP_DATA_STORAGE_NAMESPACE, JSON.stringify(value));99 } else {100 var data = localStorage.getItem(SIP_DATA_STORAGE_NAMESPACE);101 return data && JSON.parse(data);102 }103 },104 keypadVisible: function(value) {105 if (arguments.length > 0) {106 localStorage.setItem(KEYPAD_VISIBLE_STORAGE_NAMESPACE, JSON.stringify(value));107 } else {108 var data = localStorage.getItem(KEYPAD_VISIBLE_STORAGE_NAMESPACE);109 return data && JSON.parse(data);110 }111 }112 };113 // SalesForce114 app.SF = {115 clickToDial: function(enable) {116 if (enable) {117 sforce.interaction.cti.enableClickToDial();118 } else {119 sforce.interaction.cti.disableClickToDial();120 }121 },122 onClickToDial: function(callback) {123 sforce.interaction.cti.onClickToDial(function(response) {124 var result = JSON.parse(response.result);125 callback(normalizeNumber(result.number));126 });127 },128 screenPop: function(url, force, callback) {129 sforce.interaction.screenPop(url, force, callback);130 },131 searchAndGetScreenPopUrl: function(searchParams, queryParams, callType, callback) {132 sforce.interaction.searchAndGetScreenPopUrl(searchParams, queryParams, callType, callback);133 },134 searchContactAndGetScreenPopUrl: function(searchParams, callback) {135 app.SF.searchAndGetScreenPopUrl(searchParams, null, 'inbound', callback);136 },137 adjustSize: function (force) {138 if (force) {139 adjust();140 } else {141 setTimeout(adjust, 0);142 }143 144 function adjust() {145 var height = $("#phone").height();146 sforce.interaction.cti.setSoftphoneHeight(height + 10);147 }148 },149 saveLog: function (params) {150 var currentDate = params.date;151 var currentDay = currentDate.getDate();152 var currentMonth = currentDate.getMonth() + 1;153 var currentYear = currentDate.getFullYear();154 var timeStamp = currentDate.toString();155 timeStamp = timeStamp.substring(0, timeStamp.lastIndexOf(':') + 3);156 var dueDate = currentYear + '-' + currentMonth + '-' + currentDay;157 var saveParams = "Subject=" + "Call on " + timeStamp;158 saveParams += '&Status=' + params.status;159 saveParams += '&CallType=' + params.callType;160 saveParams += '&Activitydate=' + dueDate;161 saveParams += '&CallObject=' + currentDate.getTime();162 saveParams += '&Phone=' + params.number;163 //saveParams += '&Description=' + callLogText.value;164 //var callDisposition = getSelectedCallDisposition();165 //if (callDisposition) {166 // saveParams += '&CallDisposition=' + callDisposition.value;167 //}168 saveParams += '&CallDurationInSeconds=' + params.duration;169 if (params.whoId) {170 saveParams += '&WhoId=' + params.whoId;171 } else {172 //saveParams += '&WhatId=' + params.whatId;173 saveParams += '&WhoId=' + params.whatId;174 }175 sforce.interaction.saveLog('Task', saveParams, function (response) {176 var result = response.result;177 var error = response.error;178 //alert("result=" + result + " ;error=" + error);179 });180 },181 pageObjectId: function (fn) {182 function callback(response) {183 var result = JSON.parse(response.result);184 if (result.objectId.substr(0, 3) == '003') {185 fn({186 objectId: result.objectId,187 whoId: result.objectId188 });189 } else {190 fn({191 objectId: result.objectId,192 whatId: result.objectId193 });194 }195 }196 sforce.interaction.getPageInfo(callback);197 }198 };199 200 function normalizeNumber(number) {201 return number.replace("+", "").replace(" ", "").replace("(", "").replace(")", "").replace("-", "");202 }...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!