How to use addBinding method in Playwright Internal

Best JavaScript code snippet using playwright-internal

addBinding.js

Source:addBinding.js Github

copy

Full Screen

1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17define(["dojo/_base/connect",18 "dojo/dom",19 "dojo/dom-construct",20 "dojo/_base/window",21 "dijit/registry",22 "dojo/parser",23 "dojo/_base/array",24 "dojo/_base/event",25 'dojo/_base/json',26 "dojo/_base/lang",27 "dojo/_base/declare",28 "dojo/store/Memory",29 "dijit/form/FilteringSelect",30 "qpid/common/util",31 "dojo/text!addBinding.html",32 "dijit/form/NumberSpinner", // required by the form33 /* dojox/ validate resources */34 "dojox/validate/us", "dojox/validate/web",35 /* basic dijit classes */36 "dijit/Dialog",37 "dijit/form/CheckBox", "dijit/form/Textarea",38 "dijit/form/FilteringSelect", "dijit/form/TextBox",39 "dijit/form/ValidationTextBox", "dijit/form/DateTextBox",40 "dijit/form/TimeTextBox", "dijit/form/Button",41 "dijit/form/RadioButton", "dijit/form/Form",42 "dijit/form/DateTextBox",43 /* basic dojox classes */44 "dojox/form/BusyButton", "dojox/form/CheckedMultiSelect",45 "dojox/grid/EnhancedGrid",46 "dojo/data/ObjectStore",47 "dojo/domReady!"],48 function (connect, dom, construct, win, registry, parser, array, event, json, lang, declare, Memory, FilteringSelect, util, template) {49 var noLocalValues = new Memory({50 data: [51 {name:"true", id:true},52 {name:"false", id:false}53 ]54 });55 var xMatchValues = new Memory({56 data: [57 {name:"all", id:"all"},58 {name:"any", id:"any"}59 ]60 });61 var defaultBindingArguments = [62 {id: 0, name:"x-filter-jms-selector", value: null},63 {id: 1, name:"x-qpid-no-local", value: null}64 ];65 var GridWidgetProxy = declare("qpid.dojox.grid.cells.GridWidgetProxy", dojox.grid.cells._Widget, {66 createWidget: function(inNode, inDatum, inRowIndex)67 {68 var WidgetClass = this.widgetClass;69 var widgetProperties = this.getWidgetProps(inDatum);70 var getWidgetProperties = widgetProperties.getWidgetProperties;71 if (typeof getWidgetProperties == "function")72 {73 var item = this.grid.getItem(inRowIndex);74 if (item)75 {76 var additionalWidgetProperties = getWidgetProperties(inDatum, inRowIndex, item);77 if (additionalWidgetProperties)78 {79 WidgetClass = additionalWidgetProperties.widgetClass;80 for(var prop in additionalWidgetProperties)81 {82 if(additionalWidgetProperties.hasOwnProperty(prop) && !widgetProperties[prop])83 {84 widgetProperties[prop] = additionalWidgetProperties[ prop ];85 }86 }87 }88 }89 }90 var widget = new WidgetClass(widgetProperties, inNode);91 return widget;92 },93 getValue: function(inRowIndex)94 {95 if (this.widget)96 {97 return this.widget.get('value');98 }99 return null;100 },101 _finish: function(inRowIndex)102 {103 if (this.widget)104 {105 this.inherited(arguments);106 this.widget.destroyRecursive();107 this.widget = null;108 }109 }110 });111 var addBinding = {};112 var node = construct.create("div", null, win.body(), "last");113 var convertToBinding = function convertToBinding(formValues)114 {115 var newBinding = {};116 newBinding.name = formValues.name;117 for(var propName in formValues)118 {119 if(formValues.hasOwnProperty(propName))120 {121 if(propName === "durable")122 {123 if (formValues.durable[0] && formValues.durable[0] == "durable") {124 newBinding.durable = true;125 }126 } else {127 if(formValues[ propName ] !== "") {128 newBinding[ propName ] = formValues[propName];129 }130 }131 }132 }133 if(addBinding.queue) {134 newBinding.queue = addBinding.queue;135 }136 if(addBinding.exchange) {137 newBinding.exchange = addBinding.exchange;138 }139 addBinding.bindingArgumentsGrid.store.fetch({140 onComplete:function(items,request)141 {142 if(items.length)143 {144 array.forEach(items, function(item)145 {146 if (item && item.name && item.value)147 {148 var bindingArguments = newBinding.arguments;149 if (!bindingArguments)150 {151 bindingArguments = {};152 newBinding.arguments = bindingArguments;153 }154 bindingArguments[item.name]=item.value;155 }156 });157 }158 }159 });160 return newBinding;161 };162 var theForm;163 node.innerHTML = template;164 addBinding.dialogNode = dom.byId("addBinding");165 parser.instantiate([addBinding.dialogNode]);166 theForm = registry.byId("formAddBinding");167 array.forEach(theForm.getDescendants(), function(widget)168 {169 if(widget.name === "type") {170 widget.on("change", function(isChecked) {171 var obj = registry.byId(widget.id + ":fields");172 if(obj) {173 if(isChecked) {174 obj.domNode.style.display = "block";175 obj.resize();176 } else {177 obj.domNode.style.display = "none";178 obj.resize();179 }180 }181 })182 }183 });184 var argumentsGridNode = dom.byId("formAddbinding.bindingArguments");185 var objectStore = new dojo.data.ObjectStore({objectStore: new Memory({data:lang.clone(defaultBindingArguments), idProperty: "id"})});186 var layout = [[187 { name: "Argument Name", field: "name", width: "50%", editable: true },188 { name: 'Argument Value', field: 'value', width: '50%', editable: true, type: GridWidgetProxy,189 widgetProps: {190 getWidgetProperties: function(inDatum, inRowIndex, item)191 {192 if (item.name == "x-qpid-no-local")193 {194 return {195 labelAttr: "name",196 searchAttr: "id",197 selectOnClick: false,198 query: { id: "*"},199 required: false,200 store: noLocalValues,201 widgetClass: dijit.form.FilteringSelect202 };203 }204 else if (item.name && item.name.toLowerCase() == "x-match")205 {206 return {207 labelAttr: "name",208 searchAttr: "id",209 selectOnClick: false,210 query: { id: "*"},211 required: false,212 store: xMatchValues,213 widgetClass: dijit.form.FilteringSelect214 };215 }216 return {widgetClass: dijit.form.TextBox };217 }218 }219 }220 ]];221 var grid = new dojox.grid.EnhancedGrid({222 selectionMode: "multiple",223 store: objectStore,224 singleClickEdit: true,225 structure: layout,226 autoHeight: true,227 plugins: {indirectSelection: true}228 }, argumentsGridNode);229 grid.startup();230 addBinding.bindingArgumentsGrid = grid;231 addBinding.idGenerator = 1;232 var addArgumentButton = registry.byId("formAddbinding.addArgumentButton");233 var deleteArgumentButton = registry.byId("formAddbinding.deleteArgumentButton");234 var toggleGridButtons = function(index)235 {236 var data = grid.selection.getSelected();237 deleteArgumentButton.set("disabled", !data || data.length==0);238 };239 connect.connect(grid.selection, 'onSelected', toggleGridButtons);240 connect.connect(grid.selection, 'onDeselected', toggleGridButtons);241 deleteArgumentButton.set("disabled", true);242 addArgumentButton.on("click",243 function(event)244 {245 addBinding.idGenerator = addBinding.idGenerator + 1;246 var newItem = {id:addBinding.idGenerator, name: "", value: ""};247 grid.store.newItem(newItem);248 grid.store.save();249 grid.store.fetch(250 {251 onComplete:function(items,request)252 {253 var rowIndex = items.length - 1;254 window.setTimeout(function()255 {256 grid.focus.setFocusIndex(rowIndex, 1 );257 },10);258 }259 });260 }261 );262 deleteArgumentButton.on("click",263 function(event)264 {265 var data = grid.selection.getSelected();266 if(data.length)267 {268 array.forEach(data, function(selectedItem) {269 if (selectedItem !== null)270 {271 grid.store.deleteItem(selectedItem);272 }273 });274 grid.store.save();275 }276 }277 );278 theForm.on("submit", function(e) {279 event.stop(e);280 if(theForm.validate()){281 var newBinding = convertToBinding(util.getFormWidgetValues(registry.byId("formAddBinding")));282 var that = this;283 var model = null;284 if (addBinding.modelObj.type == "exchange")285 {286 model = {name: newBinding.queue, type: "queue", parent: addBinding.modelObj};287 }288 else289 {290 model = {name: newBinding.queue,291 type: "queue",292 parent: { name: newBinding.exchange,293 type: "exchange",294 parent: addBinding.modelObj.parent295 }296 };297 }298 addBinding.management.create("binding", model, newBinding).then(function(x){registry.byId("addBinding").hide();});299 return false;300 }else{301 alert('Form contains invalid data. Please correct first');302 return false;303 }304 });305 addBinding.show = function(management, obj) {306 var that = this;307 addBinding.management = management;308 addBinding.modelObj = obj;309 registry.byId("formAddBinding").reset();310 var grid = addBinding.bindingArgumentsGrid;311 grid.store.fetch({312 onComplete:function(items,request)313 {314 if(items.length)315 {316 array.forEach(items, function(item)317 {318 if (item !== null)319 {320 grid.store.deleteItem(item);321 }322 });323 }324 }325 });326 array.forEach(lang.clone(defaultBindingArguments), function(item) {grid.store.newItem(item); });327 grid.store.save();328 management.load({type: "queue", parent: obj.parent }, {depth: 0}).then(329 function(data) {330 var queues = [];331 for(var i=0; i < data.length; i++) {332 queues[i] = {id: data[i].name, name: data[i].name};333 }334 var queueStore = new Memory({ data: queues });335 if(that.queueChooser) {336 that.queueChooser.destroy( false );337 }338 var queueDiv = dom.byId("addBinding.selectQueueDiv");339 var input = construct.create("input", {id: "addBindingSelectQueue"}, queueDiv);340 that.queueChooser = new FilteringSelect({ id: "addBindingSelectQueue",341 name: "queue",342 store: queueStore,343 searchAttr: "name",344 promptMessage: "Name of the queue",345 title: "Select the name of the queue"}, input);346 if(obj.type == "queue")347 {348 that.queueChooser.set("value", obj.name);349 that.queueChooser.set("disabled", true);350 }351 management.load({type: "exchange", parent: obj.parent }, {depth: 0}).then(352 function(data) {353 var exchanges = [];354 for(var i=0; i < data.length; i++) {355 exchanges[i] = {id: data[i].name, name: data[i].name};356 }357 var exchangeStore = new Memory({ data: exchanges });358 if(that.exchangeChooser) {359 that.exchangeChooser.destroy( false );360 }361 var exchangeDiv = dom.byId("addBinding.selectExchangeDiv");362 var input = construct.create("input", {id: "addBindingSelectExchange"}, exchangeDiv);363 that.exchangeChooser = new FilteringSelect({ id: "addBindingSelectExchange",364 name: "exchange",365 store: exchangeStore,366 searchAttr: "name",367 promptMessage: "Name of the exchange",368 title: "Select the name of the exchange"}, input);369 if(obj.type == "exchange")370 {371 that.exchangeChooser.set("value", obj.name);372 that.exchangeChooser.set("disabled", true);373 }374 registry.byId("addBinding").show();375 }, util.xhrErrorHandler);376 }, util.xhrErrorHandler);377 };378 return addBinding;...

Full Screen

Full Screen

KeyBindingManager-test.js

Source:KeyBindingManager-test.js Github

copy

Full Screen

...65 });66 describe("addBinding", function () {67 68 it("should require command and key binding arguments", function () {69 KeyBindingManager.addBinding();70 expect(KeyBindingManager.getKeymap()).toEqual({});71 72 KeyBindingManager.addBinding("test.foo");73 expect(KeyBindingManager.getKeymap()).toEqual({});74 expect(KeyBindingManager.getKeyBindings("test.foo")).toEqual([]);75 });76 77 it("should ignore invalid bindings", function () {78 expect(KeyBindingManager.addBinding("test.foo", "Ktrl-Shift-A")).toBeNull();79 expect(KeyBindingManager.addBinding("test.foo", "Ctrl+R")).toBeNull();80 expect(KeyBindingManager.getKeymap()).toEqual({});81 });82 83 it("should add single bindings to the keymap", function () {84 var result = KeyBindingManager.addBinding("test.foo", "Ctrl-A");85 expect(result).toEqual(key("Ctrl-A"));86 expect(KeyBindingManager.getKeyBindings("test.foo")).toEqual([key("Ctrl-A")]);87 88 result = KeyBindingManager.addBinding("test.bar", "Ctrl-B");89 expect(result).toEqual(key("Ctrl-B"));90 expect(KeyBindingManager.getKeyBindings("test.bar")).toEqual([key("Ctrl-B")]);91 92 result = KeyBindingManager.addBinding("test.cat", "Ctrl-C", "bark");93 expect(result).toBeNull();94 95 result = KeyBindingManager.addBinding("test.dog", "Ctrl-D", "test");96 expect(result).toEqual(key("Ctrl-D"));97 expect(KeyBindingManager.getKeyBindings("test.dog")).toEqual([key("Ctrl-D")]);98 99 // only "test" platform bindings100 var expected = keyMap([101 keyBinding("Ctrl-A", "test.foo"),102 keyBinding("Ctrl-B", "test.bar"),103 keyBinding("Ctrl-D", "test.dog")104 ]);105 106 expect(KeyBindingManager.getKeymap()).toEqual(expected);107 });108 109 it("should use displayKey to override display of the shortcut", function () {110 KeyBindingManager.addBinding("test.foo", key("Ctrl-=", "Ctrl-+"));111 112 // only "test" platform bindings113 var expected = keyMap([114 keyBinding("Ctrl-=", "test.foo", "Ctrl-+")115 ]);116 117 expect(KeyBindingManager.getKeymap()).toEqual(expected);118 });119 120 it("should add multiple bindings to the keymap", function () {121 // use a fake platform122 brackets.platform = "test1";123 124 var results = KeyBindingManager.addBinding("test.foo", [{key: "Ctrl-A", platform: "test1"}, "Ctrl-1"]);125 expect(results).toEqual([126 key("Ctrl-A"),127 key("Ctrl-1")128 ]);129 expect(KeyBindingManager.getKeyBindings("test.foo")).toEqual([130 key("Ctrl-A"),131 key("Ctrl-1")132 ]);133 134 results = KeyBindingManager.addBinding("test.bar", [{key: "Ctrl-B"}, {key: "Ctrl-2", platform: "test2"}]);135 expect(results).toEqual([136 key("Ctrl-B")137 ]);138 expect(KeyBindingManager.getKeyBindings("test.bar")).toEqual([139 key("Ctrl-B")140 ]);141 142 // only "test1" platform and cross-platform bindings143 var expected = keyMap([144 keyBinding("Ctrl-A", "test.foo"),145 keyBinding("Ctrl-1", "test.foo"),146 keyBinding("Ctrl-B", "test.bar")147 ]);148 149 expect(KeyBindingManager.getKeymap()).toEqual(expected);150 });151 152 it("should prevent a key binding from mapping to multiple commands", function () {153 KeyBindingManager.addBinding("test.foo", "Ctrl-A");154 KeyBindingManager.addBinding("test.bar", "Ctrl-A");155 156 var expected = keyMap([157 keyBinding("Ctrl-A", "test.foo")158 ]);159 160 expect(KeyBindingManager.getKeymap()).toEqual(expected);161 });162 163 it("should allow a command to map to multiple key bindings", function () {164 KeyBindingManager.addBinding("test.foo", "Ctrl-A");165 KeyBindingManager.addBinding("test.foo", "Ctrl-B");166 167 // only "test1" platform and cross-platform bindings168 var expected = keyMap([169 keyBinding("Ctrl-A", "test.foo"),170 keyBinding("Ctrl-B", "test.foo")171 ]);172 173 expect(KeyBindingManager.getKeymap()).toEqual(expected);174 });175 176 it("should support the Ctrl key on mac", function () {177 brackets.platform = "mac";178 179 KeyBindingManager.addBinding("test.cmd", "Cmd-A", "mac");180 KeyBindingManager.addBinding("test.ctrl", "Ctrl-A", "mac");181 KeyBindingManager.addBinding("test.ctrlAlt", "Ctrl-Alt-A", "mac");182 KeyBindingManager.addBinding("test.cmdCtrlAlt", "Cmd-Ctrl-A", "mac");183 184 var expected = keyMap([185 keyBinding("Cmd-A", "test.cmd"),186 keyBinding("Ctrl-A", "test.ctrl"),187 keyBinding("Ctrl-Alt-A", "test.ctrlAlt"),188 keyBinding("Ctrl-Cmd-A", "test.cmdCtrlAlt") // KeyBindingManager changes the order189 ]);190 191 expect(KeyBindingManager.getKeymap()).toEqual(expected);192 });193 });194 describe("removeBinding", function () {195 196 it("should handle an empty keymap gracefully", function () {197 KeyBindingManager.removeBinding("Ctrl-A");198 expect(KeyBindingManager.getKeymap()).toEqual({});199 });200 201 it("should require a key to remove", function () {202 KeyBindingManager.addBinding("test.foo", "Ctrl-A");203 KeyBindingManager.addBinding("test.bar", "Ctrl-B");204 205 // keymap should be unchanged206 var expected = keyMap([207 keyBinding("Ctrl-A", "test.foo"),208 keyBinding("Ctrl-B", "test.bar")209 ]);210 211 KeyBindingManager.removeBinding();212 213 expect(KeyBindingManager.getKeymap()).toEqual(expected);214 });215 216 it("should remove a key from the key map", function () {217 KeyBindingManager.addBinding("test.foo", "Ctrl-A");218 KeyBindingManager.addBinding("test.foo", "Ctrl-B");219 220 // Ctrl-A should be removed221 var expected = keyMap([222 keyBinding("Ctrl-B", "test.foo")223 ]);224 225 KeyBindingManager.removeBinding("Ctrl-A");226 227 expect(KeyBindingManager.getKeymap()).toEqual(expected);228 expect(KeyBindingManager.getKeyBindings("test.foo")).toEqual([key("Ctrl-B")]);229 230 KeyBindingManager.removeBinding("Ctrl-B");231 expect(KeyBindingManager.getKeyBindings("test.foo")).toEqual([]);232 });233 234 it("should remove a key from the key map for the specified platform", function () {235 brackets.platform = "test1";236 237 KeyBindingManager.addBinding("test.foo", "Ctrl-A", "test1");238 239 // remove Ctrl-A, only for platform "test1"240 KeyBindingManager.removeBinding("Ctrl-A", "test1");241 expect(KeyBindingManager.getKeymap()).toEqual({});242 });243 244 it("should exclude a specified platform key binding for a cross-platform command", function () {245 brackets.platform = "test1";246 247 // all platforms248 KeyBindingManager.addBinding("test.foo", "Ctrl-B");249 250 var expected = keyMap([251 keyBinding("Ctrl-B", "test.foo")252 ]);253 254 // remove Ctrl-B, only for platform "test2"255 KeyBindingManager.removeBinding("Ctrl-B", "test2");256 expect(KeyBindingManager.getKeymap()).toEqual(expected);257 });258 259 });260 describe("handleKey", function () {261 262 it("should execute a command", function () {263 var fooCalled = false;264 CommandManager.register("Foo", "test.foo", function () {265 fooCalled = true;266 });267 268 KeyBindingManager.addBinding("test.foo", "Ctrl-A");269 expect(fooCalled).toBe(false);270 271 KeyBindingManager.handleKey("Ctrl-A");272 expect(fooCalled).toBe(true);273 });274 275 });276 277 });...

Full Screen

Full Screen

add-binding.js

Source:add-binding.js Github

copy

Full Screen

...5InspectorTest.runAsyncTestSuite([6 async function testBasic() {7 const {contextGroup, sessions: [session1, session2]} = setupSessions(2);8 InspectorTest.log('\nAdd binding inside session1..');9 session1.Protocol.Runtime.addBinding({name: 'send'});10 InspectorTest.log('Call binding..');11 await session1.Protocol.Runtime.evaluate({expression: `send('payload')`});12 InspectorTest.log('\nAdd binding inside session2..');13 session2.Protocol.Runtime.addBinding({name: 'send'});14 InspectorTest.log('Call binding..');15 await session2.Protocol.Runtime.evaluate({expression: `send('payload')`});16 InspectorTest.log('\nDisable agent inside session1..');17 session1.Protocol.Runtime.disable();18 InspectorTest.log('Call binding..');19 await session2.Protocol.Runtime.evaluate({expression: `send('payload')`});20 InspectorTest.log('\nDisable agent inside session2..');21 session2.Protocol.Runtime.disable();22 InspectorTest.log('Call binding..');23 await session2.Protocol.Runtime.evaluate({expression: `send('payload')`});24 InspectorTest.log('\nEnable agent inside session1..');25 session1.Protocol.Runtime.enable();26 InspectorTest.log('Call binding..');27 await session2.Protocol.Runtime.evaluate({expression: `send('payload')`});28 },29 async function testReconnect() {30 const {contextGroup, sessions: [session]} = setupSessions(1);31 InspectorTest.log('\nAdd binding inside session..');32 await session.Protocol.Runtime.addBinding({name: 'send'});33 InspectorTest.log('Reconnect..');34 session.reconnect();35 await session.Protocol.Runtime.evaluate({expression: `send('payload')`});36 },37 async function testBindingOverrides() {38 const {contextGroup, sessions: [session]} = setupSessions(1);39 InspectorTest.log('\nAdd send function on global object..');40 session.Protocol.Runtime.evaluate({expression: 'send = () => 42'});41 InspectorTest.log('Add binding inside session..');42 session.Protocol.Runtime.addBinding({name: 'send'});43 InspectorTest.log('Call binding..');44 await session.Protocol.Runtime.evaluate({expression: `send('payload')`});45 },46 async function testRemoveBinding() {47 const {contextGroup, sessions: [session]} = setupSessions(1);48 InspectorTest.log('\nAdd binding inside session..');49 session.Protocol.Runtime.addBinding({name: 'send'});50 InspectorTest.log('Call binding..');51 await session.Protocol.Runtime.evaluate({expression: `send('payload')`});52 InspectorTest.log('Remove binding inside session..');53 session.Protocol.Runtime.removeBinding({name: 'send'});54 InspectorTest.log('Call binding..');55 await session.Protocol.Runtime.evaluate({expression: `send('payload')`});56 },57 async function testAddBindingToContextById() {58 const {contextGroup, sessions: [session]} = setupSessions(1);59 const contextId1 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;60 contextGroup.createContext();61 const contextId2 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;62 await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: contextId2});63 const expression = `frobnicate('message')`;64 InspectorTest.log('Call binding in default context (binding should NOT be exposed)');65 await session.Protocol.Runtime.evaluate({expression});66 InspectorTest.log('Call binding in target context (binding should be exposed)');67 await session.Protocol.Runtime.evaluate({expression, contextId: contextId2});68 InspectorTest.log('Call binding in newly created context (binding should NOT be exposed)');69 contextGroup.createContext();70 const contextId3 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;71 await session.Protocol.Runtime.evaluate({expression, contextId: contextId3});72 },73 async function testAddBindingToMultipleContextsById() {74 const {contextGroup, sessions: [session]} = setupSessions(1);75 const contextId1 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;76 contextGroup.createContext();77 const contextId2 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;78 await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: contextId1});79 await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: contextId2});80 const expression = `frobnicate('message')`;81 InspectorTest.log('Call binding in default context (binding should be exposed)');82 await session.Protocol.Runtime.evaluate({expression});83 InspectorTest.log('Call binding in target context (binding should be exposed)');84 await session.Protocol.Runtime.evaluate({expression, contextId: contextId2});85 },86 async function testAddBindingToMultipleContextsInDifferentContextGroups() {87 const sessions1 = setupSessions(1, 'group1/');88 const session1 = sessions1.sessions[0];89 const contextId1 = (await session1.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;90 const sessions2 = setupSessions(1, 'group2/');91 const session2 = sessions2.sessions[0];92 const contextId2 = (await session2.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;93 await session1.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: contextId1});94 await session2.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: contextId2});95 const expression = `frobnicate('message')`;96 InspectorTest.log('Call binding in default context (binding should be exposed)');97 await session1.Protocol.Runtime.evaluate({expression, contextId: contextId1});98 InspectorTest.log('Call binding in target context (binding should be exposed)');99 await session2.Protocol.Runtime.evaluate({expression, contextId: contextId2});100 },101 async function testAddBindingToContextByName() {102 const {contextGroup, sessions: [session]} = setupSessions(1);103 const defaultContext = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;104 contextGroup.createContext("foo");105 const contextFoo = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;106 contextGroup.createContext("bar");107 const contextBar = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;108 await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextName: 'foo'});109 const expression = `frobnicate('message')`;110 InspectorTest.log('Call binding in default context (binding should NOT be exposed)');111 await session.Protocol.Runtime.evaluate({expression});112 InspectorTest.log('Call binding in Foo (binding should be exposed)');113 await session.Protocol.Runtime.evaluate({expression, contextId: contextFoo});114 InspectorTest.log('Call binding in Bar (binding should NOT be exposed)');115 await session.Protocol.Runtime.evaluate({expression, contextId: contextBar});116 contextGroup.createContext("foo");117 const contextFoo2 = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;118 InspectorTest.log('Call binding in newly-created Foo (binding should be exposed)');119 await session.Protocol.Runtime.evaluate({expression, contextId: contextFoo2});120 contextGroup.createContext("bazz");121 const contextBazz = (await session.Protocol.Runtime.onceExecutionContextCreated()).params.context.id;122 InspectorTest.log('Call binding in newly-created Bazz (binding should NOT be exposed)');123 await session.Protocol.Runtime.evaluate({expression, contextId: contextBazz});124 },125 async function testErrors() {126 const {contextGroup, sessions: [session]} = setupSessions(1);127 let err = await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextName: ''});128 InspectorTest.logMessage(err);129 err = await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextName: 'foo', executionContextId: 1});130 InspectorTest.logMessage(err);131 err = await session.Protocol.Runtime.addBinding({name: 'frobnicate', executionContextId: 2128506});132 InspectorTest.logMessage(err);133 }134]);135function setupSessions(num, prefix = '') {136 const contextGroup = new InspectorTest.ContextGroup();137 const sessions = [];138 for (let i = 0; i < num; ++i) {139 const session = contextGroup.connect();140 sessions.push(session);141 session.Protocol.Runtime.enable();142 session.Protocol.Runtime.onBindingCalled(msg => {143 InspectorTest.log(`binding called in ${prefix}session${i + 1}`);144 InspectorTest.logMessage(msg);145 });...

Full Screen

Full Screen

history_in_a_rush.js

Source:history_in_a_rush.js Github

copy

Full Screen

...3 if (typeof InARush !== 'undefined') {4 var translate = function(s) {5 return (HISTORY_IN_A_RUSH_TRANSLATIONS[s] || s);6 };7 InARush.Bindings.addBinding({8 id: 'system_history',9 keySequence: ['h'],10 handler: function () { window.location.href = APP_PATH + 'history'; },11 description: translate('system_history'),12 condition: function () { return !window.location.href.includes('/history'); },13 category: translate('category_history'),14 });15 InARush.Bindings.addBinding({16 id: 'record_history',17 keySequence: ['r'],18 handler: function () {19 window.location.href = $('#as-history-button').attr('href');20 },21 description: translate('record_history'),22 condition: function () { return $('#as-history-button').length > 0; },23 category: translate('category_history'),24 });25 InARush.Bindings.addBinding({26 id: 'diff_only_history',27 keySequence: ['1'],28 handler: function () {29 $('#as-history-tb-diff-only-button').click();30 },31 description: translate('diff_only_history'),32 condition: function () { return $('#as-history-tb-diff-only-button').length > 0; },33 category: translate('category_history'),34 });35 InARush.Bindings.addBinding({36 id: 'diff_all_history',37 keySequence: ['2'],38 handler: function () {39 $('#as-history-tb-diff-all-button').click();40 },41 description: translate('diff_all_history'),42 condition: function () { return $('#as-history-tb-diff-all-button').length > 0; },43 category: translate('category_history'),44 });45 InARush.Bindings.addBinding({46 id: 'diff_clean_history',47 keySequence: ['3'],48 handler: function () {49 $('#as-history-tb-diff-clean-button').click();50 },51 description: translate('diff_clean_history'),52 condition: function () { return $('#as-history-tb-diff-clean-button').length > 0; },53 category: translate('category_history'),54 });55 InARush.Bindings.addBinding({56 id: 'record_audit_history',57 keySequence: ['4'],58 handler: function () {59 $('#as-history-tb-record-button').click();60 },61 description: translate('record_audit_history'),62 condition: function () { return $('#as-history-tb-record-button').length > 0; },63 category: translate('category_history'),64 });65 InARush.Bindings.addBinding({66 id: 'exit_history',67 keySequence: ['5'],68 handler: function () {69 window.location.href = $('#as-history-tb-exit-button').attr('href');70 },71 description: translate('exit_history'),72 condition: function () { return $('#as-history-tb-exit-button').length > 0; },73 category: translate('category_history'),74 });75 InARush.Bindings.addBinding({76 id: 'restore_history',77 keySequence: ['6'],78 handler: function () {79 $('#as-history-tb-restore-button').click();80 },81 description: translate('restore_history'),82 condition: function () { return $('#as-history-tb-restore-button').length > 0; },83 category: translate('category_history'),84 });85 InARush.Bindings.addBinding({86 id: 'quit_history',87 keySequence: ['q'],88 handler: function () {89 window.location.href = $('#as-history-tb-exit-button').attr('href');90 },91 description: translate('quit_history'),92 condition: function () { return $('#as-history-tb-exit-button').length > 0; },93 category: translate('category_history'),94 });95 InARush.Bindings.addBinding({96 id: 'previous_history',97 keySequence: ['p'],98 handler: function () {99 $('.history-previous-sets-button').click();100 },101 description: translate('previous_history'),102 condition: function () { return $('.history-previous-sets-button').length > 0; },103 category: translate('category_history'),104 });105 InARush.Bindings.addBinding({106 id: 'search_history',107 keySequence: ['s'],108 handler: function () {109 $('.history-version-set').click();110 },111 description: translate('search_history'),112 condition: function () { return $('.history-version-set').length > 0; },113 category: translate('category_history'),114 });115 InARush.Bindings.addBinding({116 id: 'goto_diff_history',117 keySequence: [']'],118 handler: function () {119 window.location.href = $('.history-showing-diff-version').attr('href');120 },121 description: translate('goto_diff_history'),122 condition: function () { return $('.history-showing-diff-version').length > 0; },123 category: translate('category_history'),124 });125 InARush.Bindings.addBinding({126 id: 'goto_newer_history',127 keySequence: ['['],128 handler: function () {129 window.location.href = $('.history-showing-version').parent().prev().children().attr('href');130 },131 description: translate('goto_newer_history'),132 condition: function () { return $('.history-showing-version').parent().prev().children().length > 0; },133 category: translate('category_history'),134 });135 InARush.Bindings.addBinding({136 id: 'goto_first_history',137 keySequence: ['\\'],138 handler: function () {139 window.location.href = $('.history-version-box').first().children().attr('href');140 },141 description: translate('goto_first_history'),142 condition: function () { return $('.history-version-box').length > 0; },143 category: translate('category_history'),144 });145 InARush.Bindings.addBinding({146 id: 'goto_last_history',147 keySequence: ["'"],148 handler: function () {149 window.location.href = $('.history-version-box').last().find('.history-version').attr('href');150 },151 description: translate('goto_last_history'),152 condition: function () { return $('.history-version-box').length > 0; },153 category: translate('category_history'),154 });155 }...

Full Screen

Full Screen

initHotKey.js

Source:initHotKey.js Github

copy

Full Screen

...3 */4'use strict';5import hooks from './hooks';6export default function (quill) {7 quill.keyboard.addBinding({8 key: 's',9 shortKey: true10 }, function(range, context) {11 console.log('save');12 hooks.onSave(range,context);13 });14 quill.keyboard.addBinding({15 key: 'b',16 shortKey: true17 }, function(range, context) {18 this.quill.formatText(range, 'bold', !context.format.bold,'user');19 });20 quill.keyboard.addBinding({21 key: 'i',22 shortKey: true23 }, function(range, context) {24 this.quill.formatText(range, 'italic', !context.format.italic,'user');25 });26 quill.keyboard.addBinding({27 key: 'u',28 shortKey: true29 }, function(range, context) {30 this.quill.formatText(range, 'underline', !context.format.underline,'user');31 });32 quill.keyboard.addBinding({33 key: 'x',34 shortKey: true,35 shiftKey: true36 }, function(range, context) {37 this.quill.formatText(range, 'strike', !context.format.strike,'user');38 });39 quill.keyboard.addBinding({40 key: 'u',41 shortKey: true,42 shiftKey: true43 }, function(range, context) {44 if(!context.format.list) {45 this.quill.formatLine(range, 'list', 'bullet','user');46 }else{47 this.quill.formatLine(range, 'list', false,'user');48 }49 });50 quill.keyboard.addBinding({51 key: 'l',52 shortKey: true,53 shiftKey: true54 }, function(range, context) {55 if(!context.format.list) {56 this.quill.formatLine(range, 'list', 'ordered','user');57 }else{58 this.quill.formatLine(range, 'list', false,'user');59 }60 });61 quill.keyboard.addBinding({62 key:'c',63 shortKey: true,64 shiftKey: true65 }, function(range, context) {66 this.quill.removeFormat(range.index,range.length,'user');67 });68 quill.keyboard.addBinding({69 key: '0',70 shortKey: true,71 altKey: true72 }, function(range, context) {73 this.quill.formatLine(range, 'header', false,'user');74 });75 quill.keyboard.addBinding({76 key: '1',77 shortKey: true,78 altKey: true79 }, function(range, context) {80 if(!context.format.header) {81 this.quill.formatLine(range, 'header', 1,'user');82 }else{83 this.quill.formatLine(range, 'header', false,'user');84 }85 });86 quill.keyboard.addBinding({87 key: '2',88 shortKey: true,89 altKey: true90 }, function(range, context) {91 if(!context.format.header) {92 this.quill.formatLine(range, 'header', 2,'user');93 }else{94 this.quill.formatLine(range, 'header', false,'user');95 }96 });97 quill.keyboard.addBinding({98 key: '3',99 shortKey: true,100 altKey: true101 }, function(range, context) {102 if(!context.format.header) {103 this.quill.formatLine(range, 'header', 3,'user');104 }else{105 this.quill.formatLine(range, 'header', false,'user');106 }107 });108 quill.keyboard.addBinding({109 key: '4',110 shortKey: true,111 altKey: true112 }, function(range, context) {113 if(!context.format.header) {114 this.quill.formatLine(range, 'header', 4,'user');115 }else{116 this.quill.formatLine(range, 'header', false,'user');117 }118 });119 quill.keyboard.addBinding({120 key: '5',121 shortKey: true,122 altKey: true123 }, function(range, context) {124 if(!context.format.header) {125 this.quill.formatLine(range, 'header', 5,'user');126 }else{127 this.quill.formatLine(range, 'header', false,'user');128 }129 });130 quill.keyboard.addBinding({131 key: '6',132 shortKey: true,133 altKey: true134 }, function(range, context) {135 if(!context.format.header) {136 this.quill.formatLine(range, 'header', 6,'user');137 }else{138 this.quill.formatLine(range, 'header', false,'user');139 }140 });141 quill.keyboard.addBinding({142 key: '6',143 shortKey: true,144 shiftKey: true145 }, function(range, context) {146 if(!context.format.header) {147 this.quill.formatLine(range, 'header', 6,'user');148 }else{149 this.quill.formatLine(range, 'header', false,'user');150 }151 });152 quill.keyboard.addBinding({153 key: 'j',154 shortKey: true,155 shiftKey: true156 }, function(range, context) {157 this.quill.format('align','justify','user');158 });159 quill.keyboard.addBinding({160 key: 'j',161 shortKey: true,162 shiftKey: true163 }, function(range, context) {164 this.quill.format('align','justify','user');165 });166 quill.keyboard.addBinding({167 key: 'j',168 shortKey: true,169 shiftKey: true170 }, function(range, context) {171 this.quill.format('align','justify','user');172 });173 quill.keyboard.addBinding({174 key: 'l',175 shortKey: true,176 shiftKey: true177 }, function(range, context) {178 this.quill.format('align','left','user');179 });180 quill.keyboard.addBinding({181 key: 'e',182 shortKey: true,183 shiftKey: true184 }, function(range, context) {185 this.quill.format('align','center','user');186 });187 quill.keyboard.addBinding({188 key: 'r',189 shortKey: true,190 shiftKey: true191 }, function(range, context) {192 this.quill.format('align','right','user');193 });...

Full Screen

Full Screen

custom-keybinding.js

Source:custom-keybinding.js Github

copy

Full Screen

...14quillEditor.addEventListener('keydown', e => {15 EditorHelper.scrollToCaret();16});17// auto-complete menu18keyboardModule.addBinding({19 key: ' ',20 collapsed: true,21 format: {list: false}, // ...on an line that's not already a list22 prefix: /[\u0660-\u0669]/, // ...following a arabic number23 offset: 1, // ...at the 1st position of the line,24 handler: (range, context) => {25 // the space character is consumed by this handler26 // so we only need to delete the hyphen27 quill.deleteText(range.index - 1, 1);28 // apply bullet formatting to the line29 quill.formatLine(range.index, 1, 'list', 'ordered');30 // restore selection31 quill.setSelection(range.index - 1);32 }33});34keyboardModule.addBinding({35 key: ' ',36 collapsed: true,37 prefix: /صلى الله عليه وسلم/,38 handler: (range, context) => {39 let change = [40 {insert: 'ﷺ '},41 {delete: 'صلى الله عليه وسلم'.length},42 ];43 if (range.index !== 'صلى الله عليه وسلم'.length) change.unshift({retain: range.index - 18});44 quill.updateContents({45 ops: change46 });47 }48});49keyboardModule.addBinding({50 key: ',',51 collapsed: true,52 shiftKey: null,53 format: {align: 'right', direction: 'rtl'},54 handler: (range) => {55 quill.insertText(range.index, ArabicHelper.COMMA);56 // restore selection57 quill.setSelection(range.index + 1);58 }59});60keyboardModule.addBinding({61 key: ';',62 collapsed: true,63 shiftKey: null,64 format: {align: 'right', direction: 'rtl'},65 handler: (range) => {66 quill.insertText(range.index, ArabicHelper.SEMI_COMMA);67 // restore selection68 quill.setSelection(range.index + 1);69 }70});71keyboardModule.addBinding({72 key: '1',73 collapsed: true,74 format: {align: 'right', direction: 'rtl'},75 handler: (range, context) => {76 const pressedNumber = context.event.key;77 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);78 // restore selection79 quill.setSelection(range.index + 1);80 }81});82keyboardModule.addBinding({83 key: '2',84 collapsed: true,85 format: {align: 'right', direction: 'rtl'},86 handler: (range, context) => {87 const pressedNumber = context.event.key;88 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);89 // restore selection90 quill.setSelection(range.index + 1);91 }92});93keyboardModule.addBinding({94 key: '3',95 collapsed: true,96 format: {align: 'right', direction: 'rtl'},97 handler: (range, context) => {98 const pressedNumber = context.event.key;99 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);100 // restore selection101 quill.setSelection(range.index + 1);102 }103});104keyboardModule.addBinding({105 key: '4',106 collapsed: true,107 format: {align: 'right', direction: 'rtl'},108 handler: (range, context) => {109 const pressedNumber = context.event.key;110 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);111 // restore selection112 quill.setSelection(range.index + 1);113 }114});115keyboardModule.addBinding({116 key: '5',117 collapsed: true,118 format: {align: 'right', direction: 'rtl'},119 handler: (range, context) => {120 const pressedNumber = context.event.key;121 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);122 // restore selection123 quill.setSelection(range.index + 1);124 }125});126keyboardModule.addBinding({127 key: '6',128 collapsed: true,129 format: {align: 'right', direction: 'rtl'},130 handler: (range, context) => {131 const pressedNumber = context.event.key;132 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);133 // restore selection134 quill.setSelection(range.index + 1);135 }136});137keyboardModule.addBinding({138 key: '7',139 collapsed: true,140 format: {align: 'right', direction: 'rtl'},141 handler: (range, context) => {142 const pressedNumber = context.event.key;143 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);144 // restore selection145 quill.setSelection(range.index + 1);146 }147});148keyboardModule.addBinding({149 key: '8',150 collapsed: true,151 format: {align: 'right', direction: 'rtl'},152 handler: (range, context) => {153 const pressedNumber = context.event.key;154 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);155 // restore selection156 quill.setSelection(range.index + 1);157 }158});159keyboardModule.addBinding({160 key: '9',161 collapsed: true,162 format: {align: 'right', direction: 'rtl'},163 handler: (range, context) => {164 const pressedNumber = context.event.key;165 quill.insertText(range.index, ArabicHelper.NUMBERS[pressedNumber]);166 // restore selection167 quill.setSelection(range.index + 1);168 }...

Full Screen

Full Screen

bindingPreprocessingBehaviors.js

Source:bindingPreprocessingBehaviors.js Github

copy

Full Screen

...15 it('Should allow binding to add/replace bindings through "preprocess" method\'s "addBinding" callback', function() {16 ko.bindingHandlers.a = {17 preprocess: function(value, key, addBinding) {18 // the a binding will be copied to a219 addBinding(key+"2", value);20 return value;21 }22 };23 ko.bindingHandlers.b = {24 preprocess: function(value, key, addBinding) {25 // the b binding will be replaced by b226 addBinding(key+"2", value);27 }28 };29 var rewritten = ko.expressionRewriting.preProcessBindings("a: 1, b: 2");30 var parsedRewritten = eval("({" + rewritten + "})");31 expect(parsedRewritten.a).toEqual(1);32 expect(parsedRewritten.a2).toEqual(1);33 expect(parsedRewritten.b).toBeUndefined();34 expect(parsedRewritten.b2).toEqual(2);35 });36 it('Should be able to chain "preprocess" calls when one adds a binding for another', function() {37 ko.bindingHandlers.a = {38 preprocess: function(value, key, addBinding) {39 // replace with b40 addBinding("b", value);41 }42 };43 ko.bindingHandlers.b = {44 preprocess: function(value, key, addBinding) {45 // adds 1 to value46 return '' + (+value + 1);47 }48 };49 var rewritten = ko.expressionRewriting.preProcessBindings("a: 2");50 var parsedRewritten = eval("({" + rewritten + "})");51 expect(parsedRewritten.a).toBeUndefined();52 expect(parsedRewritten.b).toEqual(3);53 });54 it('Should be able to get a dynamically created binding handler during preprocessing', function() {...

Full Screen

Full Screen

5376.js

Source:5376.js Github

copy

Full Screen

...15 it('Should allow binding to add/replace bindings through "preprocess" method\'s "addBinding" callback', function() {16 ko.bindingHandlers.a = {17 preprocess: function(value, key, addBinding) {18 // the a binding will be copied to a219 addBinding(key+"2", value);20 return value;21 }22 };23 ko.bindingHandlers.b = {24 preprocess: function(value, key, addBinding) {25 // the b binding will be replaced by b226 addBinding(key+"2", value);27 }28 };29 var rewritten = ko.expressionRewriting.preProcessBindings("a: 1, b: 2");30 var parsedRewritten = eval("({" + rewritten + "})");31 expect(parsedRewritten.a).toEqual(1);32 expect(parsedRewritten.a2).toEqual(1);33 expect(parsedRewritten.b).toBeUndefined();34 expect(parsedRewritten.b2).toEqual(2);35 });36 it('Should be able to chain "preprocess" calls when one adds a binding for another', function() {37 ko.bindingHandlers.a = {38 preprocess: function(value, key, addBinding) {39 // replace with b40 addBinding("b", value);41 }42 };43 ko.bindingHandlers.b = {44 preprocess: function(value, key, addBinding) {45 // adds 1 to value46 return '' + (+value + 1);47 }48 };49 var rewritten = ko.expressionRewriting.preProcessBindings("a: 2");50 var parsedRewritten = eval("({" + rewritten + "})");51 expect(parsedRewritten.a).toBeUndefined();52 expect(parsedRewritten.b).toEqual(3);53 });54 it('Should be able to get a dynamically created binding handler during preprocessing', function() {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.addBinding('testBinding', testBinding);7 const result = await page.evaluate(() => testBinding(1, 2));8 await browser.close();9})();10function testBinding(a, b) {11 return a + b;12}13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.addInitScript(testBinding);19 const result = await page.evaluate(() => testBinding(1, 2));20 await browser.close();21})();22function testBinding(a, b) {23 return a + b;24}25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.exposeBinding('testBinding', testBinding);31 const result = await page.evaluate(() => testBinding(1, 2));32 await browser.close();33})();34function testBinding(a, b) {35 return a + b;36}37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.addBinding('foo', () => 'bar');6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { addBinding } = require('@playwright/test');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await addBinding(page, 'foo', (arg1, arg2) => {8 return 'bar';9 });10 const result = await page.evaluate(async (arg1, arg2) => {11 return await foo(arg1, arg2);12 }, 'arg1', 'arg2');13 console.log(result);14 await browser.close();15})();16const { addBinding } = require('@playwright/test');17const { chromium } = require('playwright');18(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { addBinding } = require('playwright/lib/client/api');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 addBinding(page, 'myBinding', (source, ...args) => {8 console.log('myBinding', source, args);9 });10 await page.evaluate(() => {11 window.myBinding('fromEvaluate', 1, 2, 3);12 });13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { addBinding } = require('playwright');2addBinding('add', (a, b) => a + b);3const { addBinding } = require('playwright');4addBinding('add', (a, b) => a + b);5const { test, expect } = require('@playwright/test');6test('add', async ({ page }) => {7 await page.evaluate(async () => {8 const result = await add(1, 2);9 expect(result).toBe(3);10 });11});12const { addBinding } = require('playwright');13addBinding('add', (a, b) => a + b);14const { addBinding } = require('playwright');15addBinding('add', (a, b) => a + b);16const { test, expect } = require('@playwright/test');17test('add', async ({ page }) => {18 await page.evaluate(async () => {19 const result = await add(1, 2);20 expect(result).toBe(3);21 });22});23const { addBinding } = require('playwright');24addBinding('add', (a, b) => a + b);25const { addBinding } = require('playwright');26addBinding('add', (a, b) => a + b);27const { test, expect } = require('@playwright/test');28test('add', async ({ page }) => {29 await page.evaluate(async () => {30 const result = await add(1, 2);31 expect(result).toBe(3);32 });33});34const { addBinding } = require('playwright');35addBinding('add', (a, b) => a + b);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { addBinding } = require('playwright');2addBinding('myBinding', (source) => {3 console.log('Binding called from ' + source);4});5const { evaluate } = require('playwright');6evaluate(() => {7 window.myBinding('evaluate');8});9const { evaluateHandle } = require('playwright');10evaluateHandle(() => {11 window.myBinding('evaluateHandle');12});13const { exposeBinding } = require('playwright');14exposeBinding('myBinding', (source, ...args) => {15 console.log('Binding called from ' + source);16 return args[0];17});18const { exposeFunction } = require('playwright');19exposeFunction('myFunction', (arg) => {20 console.log('Function called with ' + arg);21});22const { waitForEvent } = require('playwright');23waitForEvent('bindingcall', (source, name, ...args) => {24 console.log('Binding called from ' + source);25 return name === 'myBinding';26});

Full Screen

Using AI Code Generation

copy

Full Screen

1const binding = require('playwright/lib/internal/binding');2binding.addBinding('test', (source, target, ...args) => {3 console.log('source', source);4 console.log('target', target);5 console.log('args', args);6});7const { chromium } = require('playwright');8(async () => {9 const browser = await chromium.launch();10 const page = await browser.newPage();11 await page.evaluate(() => {12 window.test('a', 'b', 1, 2, 3);13 });14 await browser.close();15})();16import * as binding from 'playwright/lib/internal/binding';17binding.addBinding('test', (source, target, ...args) => {18 console.log('source', source);19 console.log('target', target);20 console.log('args', args);21});22import { chromium } from 'playwright';23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 await page.evaluate(() => {27 window.test('a', 'b', 1, 2, 3);28 });29 await browser.close();30})();31import com.microsoft.playwright.Browser;32import com.microsoft.playwright.BrowserType;33import com.microsoft.playwright.Page;34import com.microsoft.playwright.Playwright;35import com.microsoft.playwright.internal.binding.Binding;36public class test {37 public static void main(String[] args) {38 Playwright playwright = Playwright.create();39 BrowserType chromium = playwright.chromium();40 Browser browser = chromium.launch();41 Page page = browser.newPage();42 Binding.addBinding(page, "test", (source, target, args) -> {43 System.out.println("source " + source);44 System.out.println("target " + target);45 System.out.println("

Full Screen

Using AI Code Generation

copy

Full Screen

1const {addBinding} = require('playwright-core/lib/server/injected/injectedScript');2addBinding('myBinding', (source, ...args) => {3});4const {removeBinding} = require('playwright-core/lib/server/injected/injectedScript');5removeBinding('myBinding');6const {evaluateHandle} = require('playwright-core/lib/server/injected/injectedScript');7const result = await evaluateHandle(() => {8 return result;9});10const {evaluate} = require('playwright-core/lib/server/injected/injectedScript');11const result = await evaluate(() => {12 return result;13});14const {evaluateOnNewDocument} = require('playwright-core/lib/server/injected/injectedScript');15await evaluateOnNewDocument(() => {16});17const {evaluateExpressionHandle} = require('playwright-core/lib/server/injected/injectedScript');18const result = await evaluateExpressionHandle('document.body', true);19const {evaluateExpression} = require('playwright-core/lib/server/injected/injectedScript');20const result = await evaluateExpression('document.body', true);21const {evaluateExpressionAndWaitForSignals} = require('playwright-core/lib/server/injected/injectedScript');22const result = await evaluateExpressionAndWaitForSignals('document.body', true);23const {addConsoleMessage} = require('playwright-core/lib/server/injected/injectedScript');24addConsoleMessage('message');25const {addLifecycleListener} = require('playwright-core/lib/server

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 page.addBinding('foo', () => 'foo');7 const text = await page.evaluate(() => window.foo());8 console.log(text);9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 page.addBinding('foo', (arg1, arg2) => arg1 + arg2);17 const text = await page.evaluate((arg1, arg2) => window.foo(arg1, arg2), 1, 2);18 console.log(text);19 await browser.close();20})();21const { chromium } = require('playwright');22(async () => {23 const browser = await chromium.launch();24 const context = await browser.newContext();25 const page = await context.newPage();26 page.addBinding('foo', () => Promise.resolve('foo'));27 const text = await page.evaluate(() => window.foo());28 console.log(text);29 await browser.close();30})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { addBinding } = require('playwright');2addBinding('testBinding', () => {3 return 'test result';4});5const result = await page.evaluate(async () => {6 return await testBinding();7});

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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