Best JavaScript code snippet using playwright-internal
block.test.js
Source:block.test.js
...39 it('should return elem by name', function () {40 var block = new Block(41 $('<div class="block"><a class="block__elem" data-attr="42"></a></div>')42 );43 block._findElement('elem').attr('data-attr').should.equal('42');44 });45 it('should return elem by mod name', function () {46 var block = new Block($(47 '<div class="block">' +48 '<a class="block__elem block__elem_mod_val" data-attr="42"></a>' +49 '</div>'50 ));51 block._findElement('elem_mod_val').attr('data-attr').should.equal('42');52 });53 });54 describe('find', function () {55 var SubBlock;56 var block;57 beforeEach(function () {58 SubBlock = inherit(Block, {59 getTheAnswer: function () {60 return this.getDomNode().attr('data-attr');61 }62 }, {63 getBlockName: function () {64 return 'sub-block';65 }66 });67 block = new Block($(68 '<div class="block">' +69 '<a class="sub-block" data-block="sub-block" data-attr="42"></a>' +70 '<a class="sub-block" data-block="sub-block" data-attr="24"></a>' +71 '<a class="sub-block" data-block="sub-block" data-attr="12"></a>' +72 '</div>'73 ));74 });75 it('should find first block', function () {76 SubBlock.find(block).getTheAnswer().should.equal('42');77 });78 });79 describe('findAll', function () {80 var SubBlock;81 var block;82 beforeEach(function () {83 SubBlock = inherit(Block, {84 getTheAnswer: function () {85 return this.getDomNode().attr('data-attr');86 }87 }, {88 getBlockName: function () {89 return 'sub-block';90 }91 });92 block = new Block($(93 '<div class="block">' +94 '<a class="sub-block" data-block="sub-block" data-attr="42"></a>' +95 '<a class="sub-block" data-block="sub-block" data-attr="24"></a>' +96 '<a class="sub-block" data-block="sub-block" data-attr="12"></a>' +97 '</div>'98 ));99 });100 it('should find all blocks', function () {101 SubBlock.findAll(block).map(function (subBlock) {102 return subBlock.getTheAnswer();103 }).should.have.members(['42', '24', '12']);104 });105 });106 describe('initDomTree', function () {107 it('should initialize block without params', function (done) {108 modulesStorage['sub-block'] = inherit(Block, {109 __constructor: function () {110 this.__base.apply(this, arguments);111 done();112 }113 }, {114 getBlockName: function () {115 return 'sub-block';116 }117 });118 Block.initDomTree($(119 '<div class="block">' +120 '<a class="sub-block _init" data-block="sub-block"></a>' +121 '</div>'122 )).fail(done);123 });124 it('should initialize block inside DOM Tree', function (done) {125 modulesStorage['sub-block'] = inherit(Block, {126 __constructor: function (domNode, params) {127 this.__base.apply(this, arguments);128 params.answer.should.equal(42);129 done();130 }131 }, {132 getBlockName: function () {133 return 'sub-block';134 }135 });136 Block.initDomTree($(137 '<div class="block">' +138 '<a' +139 ' class="sub-block _init"' +140 ' data-block="sub-block" ' +141 ' data-options="{"options":{"answer":42}}"></a>' +142 '</div>'143 )).fail(done);144 });145 it('should not initialize block twice', function (done) {146 var counter = 0;147 modulesStorage['sub-block'] = inherit(Block, {148 __constructor: function () {149 this.__base.apply(this, arguments);150 counter++;151 }152 }, {153 getBlockName: function () {154 return 'sub-block';155 }156 });157 var dom = $(158 '<div class="block">' +159 '<a class="sub-block _init"' +160 ' data-block="sub-block" data-options="{"options":{}}"></a>' +161 '</div>'162 );163 Block164 .initDomTree(dom)165 .then(function () {166 return Block.initDomTree(dom);167 })168 .then(function () {169 counter.should.equal(1);170 done();171 })172 .fail(done);173 });174 it('should not initialize block without `_init`', function (done) {175 modulesStorage['sub-block'] = inherit(Block, {176 __constructor: function () {177 this.__base.apply(this, arguments);178 throw new Error('Initialized');179 }180 }, {181 getBlockName: function () {182 return 'sub-block';183 }184 });185 Block.initDomTree($(186 '<div class="block">' +187 '<a class="sub-block"' +188 ' data-block="sub-block"' +189 ' data-options="{"options":{"answer":42}}"></a>' +190 '</div>'191 )).then(done, done);192 });193 it('should not initialize block without `data-block`', function (done) {194 modulesStorage['sub-block'] = inherit(Block, {195 __constructor: function () {196 this.__base.apply(this, arguments);197 throw new Error('Initialized');198 }199 }, {200 getBlockName: function () {201 return 'sub-block';202 }203 });204 Block.initDomTree($(205 '<div class="block">' +206 '<a class="sub-block _init"></a>' +207 '</div>'208 )).then(done, done);209 });210 });211 describe('destructDomTree()', function () {212 it('should destruct once all blocks inside given DOM tree', function (done) {213 var spies = {};214 ['block1', 'block2', 'block3'].forEach(function (blockName) {215 var TmpBlock = inherit(Block, null, {216 getBlockName: function () {217 return blockName;218 }219 });220 spies[blockName] = sinon.spy(TmpBlock.prototype, 'destruct');221 modulesStorage[blockName] = TmpBlock;222 });223 var elem = $(224 '<div>' +225 '<div data-block="block1" class="_init">' +226 '<div>' +227 '<div data-block="block2" class="_init"></div>' +228 '</div>' +229 '</div>' +230 '<div data-block="block3" class="_init"></div>' +231 '</div>'232 );233 Block.initDomTree(elem).done(function () {234 Block.destructDomTree(elem);235 spies.block1.calledOnce.should.be.true;236 spies.block2.calledOnce.should.be.true;237 spies.block3.calledOnce.should.be.true;238 Block.destructDomTree(elem);239 spies.block1.calledOnce.should.be.true;240 spies.block2.calledOnce.should.be.true;241 spies.block3.calledOnce.should.be.true;242 done();243 });244 });245 it('should destruct emitters', function () {246 var BlockEm = inherit(Block, null, {247 getBlockName: function () {248 return 'block-em';249 }250 });251 modulesStorage['block-em'] = BlockEm;252 var subElem = $(253 '<div>' +254 '<div data-block="block-em"></div>' +255 '</div>'256 );257 var elem = $('<div>').append(subElem);258 var emitter = BlockEm.getEmitter(elem);259 var subEmitter = BlockEm.getEmitter(subElem);260 var spy = sinon.spy();261 emitter.on('event', spy);262 subEmitter.on('event', spy);263 BlockEm._getDomNodeDataStorage(elem).blockEvents['block-em'].should.equal(emitter);264 BlockEm._getDomNodeDataStorage(subElem).blockEvents['block-em'].should.equal(subEmitter);265 BlockEm.destructDomTree(elem);266 BlockEm._getDomNodeDataStorage(elem).blockEvents.should.be.empty;267 BlockEm._getDomNodeDataStorage(subElem).blockEvents.should.be.empty;268 var eventName = BlockEm._getPropagationEventName('event');269 elem.trigger(eventName);270 subElem.trigger(eventName);271 spy.called.should.be.false;272 });273 });274 describe('emit()', function () {275 var block;276 var spy1;277 var spy2;278 beforeEach(function () {279 block = new Block();280 spy1 = sinon.spy();281 spy2 = sinon.spy();282 block.on('event1', spy1);283 block.on('event2', spy2);284 });285 afterEach(function () {286 block.destruct();287 });288 it('should emit event on block', function () {289 block.emit('event1');290 var event2 = new BlockEvent('event2');291 block.emit(event2);292 spy1.calledOnce.should.be.true;293 var e = spy1.firstCall.args[0];294 e.should.be.instanceof(BlockEvent);295 e.type.should.eq('event1');296 e.target.should.eq(block);297 spy2.calledOnce.should.be.true;298 e = spy2.firstCall.args[0];299 e.should.be.eq(event2);300 e.type.should.eq('event2');301 e.target.should.eq(block);302 });303 it('should emit event width additional data', function () {304 var data = {foo: 'bar'};305 block.emit('event1', data);306 var event2 = new BlockEvent('event2');307 block.emit(event2, data);308 spy1.calledOnce.should.be.true;309 var e = spy1.firstCall.args[0];310 e.should.be.instanceof(BlockEvent);311 e.type.should.eq('event1');312 e.target.should.eq(block);313 e.data.should.eq(data);314 spy2.calledOnce.should.be.true;315 e = spy2.firstCall.args[0];316 e.should.be.eq(event2);317 e.type.should.eq('event2');318 e.target.should.eq(block);319 e.data.should.eq(data);320 });321 });322 describe('getEmitter()', function () {323 it('should return the same instance for same DOM node', function () {324 var dom = $('<div></div>');325 Block.getEmitter(dom).should.equal(Block.getEmitter(dom));326 });327 it('should listen handle bubbling events', function (done) {328 var SubBlock = inherit(Block, {329 __constructor: function () {330 this.__base.apply(this, arguments);331 this._bindTo(this._findElement('button'), 'click', function () {332 this.emit('button-click');333 });334 }335 }, {336 getBlockName: function () {337 return 'sub-block';338 }339 });340 var dom = $(341 '<div><div><div>' +342 '<div class="sub-block" data-block="sub-block">' +343 '<div class="sub-block__button"></div>' +344 '</div>' +345 '</div></div></div>'346 );347 var block = SubBlock.find(dom);348 SubBlock.getEmitter(dom).on('button-click', function (event) {349 event.target.should.equal(block);350 done();351 });352 dom.find('.sub-block__button').click();353 });354 it('should stop propagation', function (done) {355 var SubBlock = inherit(Block, {356 __constructor: function () {357 this.__base.apply(this, arguments);358 this._bindTo(this._findElement('button'), 'click', function () {359 this.emit('button-click');360 });361 }362 }, {363 getBlockName: function () {364 return 'sub-block';365 }366 });367 var subDom = $(368 '<div>' +369 '<div class="sub-block" data-block="sub-block">' +370 '<div class="sub-block__button"></div>' +371 '</div>' +372 '</div>'373 );374 var clickTriggered = false;375 var dom = $('<div></div>').append(subDom);376 SubBlock.find(dom); // init sub-block377 SubBlock.getEmitter(subDom).on('button-click', function (event) {378 clickTriggered = true;379 event.stopPropagation();380 });381 SubBlock.getEmitter(dom).on('button-click', function () {382 done(new Error('Stop propagation should work'));383 });384 dom.find('.sub-block__button').click();385 clickTriggered.should.be.true;386 done();387 });388 });389 describe('_getDomNodeDataStorage', function () {390 it('should return the same instance for the same DOM node', function () {391 var dom = $('<div></div>');392 Block._getDomNodeDataStorage(dom).should.equal(Block._getDomNodeDataStorage(dom));393 });394 });395 describe('state', function () {396 describe('_getState', function () {397 it('should return mod value', function () {398 var block = Block.fromDomNode(399 $('<div class="block _color_red"></div>')400 );401 block._getState('color').should.equal('red');402 block._getState('type').should.equal(false);403 });404 it('should return mod value after set', function () {405 var block = Block.fromDomNode(406 $('<div class="block _color_red"></div>')407 );408 block._getState('color').should.equal('red');409 block._setState('color', 'blue');410 block._getState('color').should.equal('blue');411 });412 it('should not return mod value after del', function () {413 var block = Block.fromDomNode(414 $('<div class="block _color_red"></div>')415 );416 block._getState('color').should.equal('red');417 block._removeState('color');418 block._getState('color').should.equal(false);419 });420 });421 describe('_setState', function () {422 it('should set mod value', function () {423 var block = Block.fromDomNode(424 $('<div class="block"></div>')425 );426 block._setState('color', 'red');427 block.getDomNode().attr('class').should.equal('block _init _color_red');428 block._setState('color', 'blue');429 block.getDomNode().attr('class').should.equal('block _init _color_blue');430 block._setState('color', null);431 block._setState('size', 'm');432 block.getDomNode().attr('class').should.equal('block _init _size_m');433 });434 });435 describe('_removeState', function () {436 it('should remove mod value', function () {437 var block = Block.fromDomNode(438 $('<div class="block _color_red"></div>')439 );440 block._removeState('color');441 block.getDomNode().attr('class').should.equal('block _init');442 block._setState('color', 'blue');443 block._removeState('color');444 block.getDomNode().attr('class').should.equal('block _init');445 });446 });447 describe('_getState', function () {448 it('should return mod value', function () {449 var block = Block.fromDomNode(450 $('<div class="block _color_red"></div>')451 );452 block._getState('color').should.equal('red');453 block._setState('color', 'blue');454 block._getState('color').should.equal('blue');455 block._setState('color', null);456 block._getState('color').should.equal(false);457 block._setState('color', undefined);458 block._getState('color').should.equal(false);459 });460 });461 describe('_toggleState', function () {462 it('should toggle mod value', function () {463 var block = Block.fromDomNode(464 $('<div class="block _color_red"></div>')465 );466 block._toggleState('color', 'red', false);467 block._getState('color').should.equal(false);468 block._toggleState('color', false, 'red');469 block._getState('color').should.equal('red');470 block._toggleState('color', 'red', 'blue');471 block._getState('color').should.equal('blue');472 block._toggleState('color', null, 'blue');473 block._toggleState('color', null, 'blue');474 block._getState('color').should.equal('blue');475 });476 });477 describe('_setElementState', function () {478 it('should set mod value', function () {479 var block = Block.fromDomNode($(480 '<div class="block">' +481 '<div class="block__button"></div>' +482 '</div>'483 ));484 block._setElementState(block._findElement('button'), 'color', 'red');485 block._findElement('button')486 .attr('class').should.equal('block__button _color_red');487 block._setElementState(block._findElement('button'), 'color', 'blue');488 block._findElement('button')489 .attr('class').should.equal('block__button _color_blue');490 block._setElementState(block._findElement('button'), 'color', '');491 block._findElement('button')492 .attr('class').should.equal('block__button');493 });494 it('should set true mod value', function () {495 var block = Block.fromDomNode($(496 '<div class="block">' +497 '<div class="block__button"></div>' +498 '</div>'499 ));500 block._setElementState(block._findElement('button'), 'active');501 block._findElement('button')502 .attr('class').should.equal('block__button _active');503 block._setElementState(block._findElement('button'), 'active', false);504 block._findElement('button')505 .attr('class').should.equal('block__button');506 });507 it('should set mod value with another view', function () {508 var block = Block.fromDomNode($(509 '<div class="block_red" data-block="block">' +510 '<div class="block_red__button"></div>' +511 '</div>'512 ));513 block._setElementState(block._findElement('button'), 'color', 'red');514 block._findElement('button')515 .attr('class').should.equal('block_red__button _color_red');516 block._setElementState(block._findElement('button'), 'color', 'blue');517 block._findElement('button')518 .attr('class').should.equal('block_red__button _color_blue');519 block._setElementState(block._findElement('button'), 'color', '');520 block._findElement('button')521 .attr('class').should.equal('block_red__button');522 });523 });524 describe('_removeElementState', function () {525 it('should remove mod value', function () {526 var block = Block.fromDomNode($(527 '<div class="block">' +528 '<div class="block__button _color_red"></div>' +529 '</div>'530 ));531 block._removeElementState(block._findElement('button'), 'color');532 block._findElement('button')533 .attr('class').should.equal('block__button');534 block._setElementState(block._findElement('button'), 'color', 'blue');535 block._removeElementState(block._findElement('button'), 'color');536 block._findElement('button')537 .attr('class').should.equal('block__button');538 });539 });540 describe('_getElementState', function () {541 it('should return mod value', function () {542 var block = Block.fromDomNode($(543 '<div class="block">' +544 '<div class="block__button _color_red"></div>' +545 '</div>'546 ));547 var button = block._findElement('button');548 block._getElementState(button, 'color').should.equal('red');549 block._setElementState(button, 'color', 'blue');550 block._getElementState(button, 'color').should.equal('blue');551 block._setElementState(button, 'color', null);552 block._getElementState(button, 'color').should.equal(false);553 block._setElementState(button, 'color', undefined);554 block._getElementState(button, 'color').should.equal(false);555 });556 });557 describe('_toggleElementState', function () {558 it('should toggle mod value', function () {559 var block = Block.fromDomNode($(560 '<div class="block">' +561 '<div class="block__button _color_red"></div>' +562 '</div>'563 ));564 var button = block._findElement('button');565 block._toggleElementState(button, 'color', 'red', false);566 block._getElementState(button, 'color').should.equal(false);567 block._toggleElementState(button, 'color', false, 'red');568 block._getElementState(button, 'color').should.equal('red');569 block._toggleElementState(button, 'color', 'red', 'blue');570 block._getElementState(button, 'color').should.equal('blue');571 block._toggleElementState(button, 'color', null, 'blue');572 });573 });574 });575 describe('options', function () {576 it('should return block options', function () {577 var block = Block.fromDomNode($(578 '<div class="block" data-options="{"options":{"level":5}}"></div>'579 ));580 block._getOptions().level.should.equal(5);581 });582 it('should return element options', function () {583 var block = Block.fromDomNode($(584 '<div class="block">' +585 '<div class="block__test" data-options="{"options":{"level":5}}"></div>' +586 '</div>'587 ));588 block._getElementOptions(block._findElement('test')).level.should.equal(5);589 });590 });591 describe('Block.fromDomNode()', function () {592 it('should return instance of block for given DOM node', function () {593 var elem = $('div');594 var block = Block.fromDomNode(elem);595 block.should.be.instanceof(Block);596 });597 it('should return same instance for same DOM node', function () {598 var elem = document.createElement('div');599 var block = Block.fromDomNode($(elem));600 Block.fromDomNode($(elem)).should.eq(block);601 });602 });...
actions.js
Source:actions.js
...119 throw new TypeError('.click() must receive valid element or CSS selector');120 }121 var _this = this;122 this._pushAction(this.click, function mouseDown() {123 return _this._findElement(element)124 .then(function(element) {125 return _this._driver.moveTo(element);126 })127 .then(function() {128 return _this._driver.click(button);129 });130 });131 return this;132 },133 doubleClick: function(element, button) {134 if (isInvalidMouseButton(button)) {135 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');136 }137 if (isInvalidElement(element)) {138 throw new TypeError('.doubleClick() must receive valid element or CSS selector');139 }140 var _this = this;141 this._pushAction(this.doubleClick, function() {142 return _this._findElement(element)143 .then(function() {144 return _this._driver.moveTo(element);145 })146 .then(function() {147 return _this._driver.doubleClick(element, button);148 });149 });150 return this;151 },152 dragAndDrop: function(element, dragTo) {153 if (isInvalidElement(element)) {154 throw new TypeError('.dragAndDrop() "element" argument should be valid element or CSS selector');155 }156 if (isInvalidElement(element)) {157 throw new TypeError('.dragAndDrop() "dragTo" argument should be valid element or CSS selector');158 }159 return this.mouseDown(element)160 .mouseMove(dragTo)161 .mouseUp();162 },163 mouseDown: function(element, button) {164 if (isInvalidMouseButton(button)) {165 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');166 }167 if (isInvalidElement(element)) {168 throw new TypeError('.mouseDown() must receive valid element or CSS selector');169 }170 var _this = this;171 this._pushAction(this.mouseDown, function mouseDown() {172 return _this._findElement(element)173 .then(function(element) {174 return _this._driver.moveTo(element);175 })176 .then(function() {177 return _this._driver.buttonDown(button);178 });179 });180 return this;181 },182 mouseUp: function(element, button) {183 if (isInvalidMouseButton(button)) {184 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');185 }186 if (isInvalidElement(element)) {187 throw new TypeError('.mouseUp() must receive valid element or CSS selector');188 }189 var _this = this;190 this._pushAction(this.mouseUp, function mouseDown() {191 return _this._findElement(element)192 .then(function(element) {193 return _this._driver.moveTo(element);194 })195 .then(function() {196 return _this._driver.buttonUp(button);197 });198 });199 return this;200 },201 mouseMove: function(element, offset) {202 if (isInvalidElement(element)) {203 throw new TypeError('.mouseMove() must receive valid element or CSS selector');204 }205 var _this = this;206 if (offset) {207 if ('x' in offset && typeof offset.x !== 'number') {208 throw new TypeError('offset.x should be a number');209 }210 if ('y' in offset && typeof offset.y !== 'number') {211 throw new TypeError('offset.y should be a number');212 }213 }214 this._pushAction(this.mouseMove, function mouseMove() {215 return _this._findElement(element).then(function(element) {216 if (offset) {217 return _this._driver.moveTo(element, offset.x, offset.y);218 }219 return _this._driver.moveTo(element);220 });221 });222 return this;223 },224 sendKeys: function(element, keys) {225 var _this = this,226 action;227 if (typeof keys === 'undefined' || keys === null) {228 keys = element;229 action = function sendKeys() {230 return _this._driver.keys(keys);231 };232 } else {233 if (isInvalidElement(element)) {234 throw new TypeError('.sendKeys() must receive valid element or CSS selector');235 }236 action = function sendKeys() {237 return _this._findElement(element).then(function(element) {238 return _this._driver.type(element, keys);239 });240 };241 }242 if (isInvalidKeys(keys)) {243 throw new TypeError('keys should be string or array of strings');244 }245 this._pushAction(this.sendKeys, action);246 return this;247 },248 sendFile: function(element, path) {249 var _this = this;250 if (typeof path !== 'string') {251 throw new TypeError('path must be string');252 }253 if (isInvalidElement(element)) {254 throw new TypeError('.sendFile() must receive valid element or CSS selector');255 }256 this._pushAction(this.sendFile, function sendFile() {257 return fs.isFile(path)258 .then(function(isFile) {259 if (!isFile) {260 return q.reject(new StateError(path + ' should be existing file'));261 }262 return _this._findElement(element);263 })264 .then(function(element) {265 return element.sendKeys(path);266 });267 });268 return this;269 },270 focus: function(element) {271 if (isInvalidElement(element)) {272 throw new TypeError('.focus() must receive valid element or CSS selector');273 }274 return this.sendKeys(element, '');275 },276 tap: function(element) {277 if (isInvalidElement(element)) {278 throw new TypeError('.tap() must receive valid element or CSS selector');279 }280 var _this = this;281 this._pushAction(this.tap, function tap() {282 return _this._findElement(element)283 .then(function(elem) {284 return _this._driver.tapElement(elem);285 });286 });287 return this;288 },289 flick: function(offsets, speed, element) {290 if (element && isInvalidElement(element)) {291 throw new TypeError('.flick() must receive valid element or CSS selector');292 }293 var _this = this;294 this._pushAction(this.flick, function flick() {295 if (element) {296 return _this._findElement(element)297 .then(function(elem) {298 return _this._driver.flick(elem, offsets.x, offsets.y, speed);299 });300 }301 return _this._driver.flick(offsets.x, offsets.y, speed);302 });303 return this;304 },305 executeJS: function(callback) {306 if (typeof callback !== 'function') {307 throw new TypeError('executeJS argument should be function');308 }309 var _this = this;310 this._pushAction(this.executeJS, function executeJS() {...
RadProgressArea.js
Source:RadProgressArea.js
...36Telerik.Web.UI.RadProgressArea.callBaseMethod(this,"dispose");37},_addSafariDefinition:function(d){d[d.length]=String.format("{0} = new RadUploadSafariProgressArea('{0}');",this.get_id());38},_setupControls:function(){this._clientId=this.get_id();39this._element=$get(this._clientId);40this._primaryProgressBarElement=this._findElement("PrimaryProgressElement");41this._primaryTotalElement=this._findElement("PrimaryTotal");42this._primaryValueElement=this._findElement("PrimaryValue");43this._primaryPercentElement=this._findElement("PrimaryPercent");44this._secondaryProgressBarElement=this._findElement("SecondaryProgressElement");45this._secondaryTotalElement=this._findElement("SecondaryTotal");46this._secondaryValueElement=this._findElement("SecondaryValue");47this._secondaryPercentElement=this._findElement("SecondaryPercent");48this._currentOperationElement=this._findElement("CurrentOperation");49this._timeElapsedElement=this._findElement("TimeElapsed");50this._timeEstimatedElement=this._findElement("TimeEstimated");51this._speedElement=this._findElement("Speed");52this._cancelButtonElement=a(this._element).find(".ruCancel")[0];53this._progressAreaHeader=this._findElement("ProgressAreaHeader");54this.updateTextIndicator(this._progressAreaHeader,this._headerText);55},_setupSafariProgressAreaControls:function(){if($telerik.RadUpload_isIFrameProgress){this._getSafariProgressArea()._primaryProgressBarElement=this._primaryProgressBarElement;56this._getSafariProgressArea()._primaryTotalElement=this._primaryTotalElement;57this._getSafariProgressArea()._primaryValueElement=this._primaryValueElement;58this._getSafariProgressArea()._primaryPercentElement=this._primaryPercentElement;59this._getSafariProgressArea()._secondaryProgressBarElement=this._secondaryProgressBarElement;60this._getSafariProgressArea()._secondaryTotalElement=this._secondaryTotalElement;61this._getSafariProgressArea()._secondaryValueElement=this._secondaryValueElement;62this._getSafariProgressArea()._secondaryPercentElement=this._secondaryPercentElement;63this._getSafariProgressArea()._currentOperationElement=this._currentOperationElement;64this._getSafariProgressArea()._timeElapsedElement=this._timeElapsedElement;65this._getSafariProgressArea()._timeEstimatedElement=this._timeEstimatedElement;66this._getSafariProgressArea()._speedElement=this._speedElement;67this._getSafariProgressArea()._cancelButtonElement=this._cancelButtonElement;...
controls.js
Source:controls.js
...16 /*jshint devel:true*/17 var Controls = inherit(YBlock, {18 __constructor: function () {19 this.__base.apply(this, arguments);20 var menu = this._findElement('menu');21 var params = extend({22 zoom: false,23 // Ðлина Ñвайпа в пикÑелаÑ
24 swipeLength: 2025 }, this._getOptions());26 this._trigger = this._findElement('trigger');27 this._bindTo(this._trigger, 'click', function () {28 this._toggleElementState(menu, 'state', 'opened', 'closed');29 });30 if (params.zoom) {31 this._initZoomControls();32 }33 if (params.footnotes) {34 this._initFootnotes();35 }36 if (params.pages) {37 this._initPageModes();38 }39 if (params.arrows) {40 this._initArrowControls();41 }42 },43 _initArrowControls: function () {44 this.arrowLeft = this._findElement('arrow-left');45 this.arrowRight = this._findElement('arrow-right');46 this._bindTo(this.arrowRight, 'click', function () {47 this.emit('next-page');48 });49 this._bindTo(this.arrowLeft, 'click', function () {50 this.emit('previous-page');51 });52 },53 _initZoomControls: function () {54 this._bindTo(this._findElement('plus'), 'click', function () {55 this.emit('zoom-in');56 });57 this._bindTo(this._findElement('minus'), 'click', function () {58 this.emit('zoom-out');59 });60 },61 /**62 * ÐниÑиализаÑÐ¸Ñ Ð±Ð»Ð¾ÐºÐ° Ñо ÑноÑками63 */64 _initFootnotes: function () {65 this._bindTo(this._findElement('footnotes'), 'click', function (e) {66 this._toggleElementState($(e.currentTarget), 'mode', 'appendix', 'inline');67 this.emit('footnotes-' + this._getElementState($(e.currentTarget), 'mode'));68 });69 },70 /**71 * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ñежим ÑноÑок в нÑжнÑй72 *73 * @param {String} mode74 */75 setFootnotesMode: function (mode) {76 this._setElementState(this._findElement('footnotes'), 'mode', mode);77 },78 /**79 * ÐниÑиализаÑÐ¸Ñ ÐºÐ¾Ð½ÑÑола ÑÑÑаниÑного оÑобÑажениÑ80 */81 _initPageModes: function () {82 var pages = this._findElement('pages');83 var modes = ['auto', 'one', 'two'];84 this._pageMode = modes.indexOf(this._getElementState(pages, 'mode'));85 this._bindTo(pages, 'click', function () {86 this._pageMode = (this._pageMode + 1) % 3;87 this._setElementState(pages, 'mode', modes[this._pageMode]);88 this.emit('pages-' + this._getElementState(pages, 'mode'));89 });90 },91 /**92 * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ñежим оÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð² нÑжнÑй93 *94 * @param {String} mode95 */96 setPageViewMode: function (mode) {97 var pages = this._findElement('pages');98 var modes = ['auto', 'one', 'two'];99 this._setElementState(pages, 'mode', mode);100 this._pageMode = modes.indexOf(mode);101 },102 resetZoomButtons: function () {103 this._removeElementState(104 this._findElement('plus'),105 'disabled'106 );107 this._removeElementState(108 this._findElement('minus'),109 'disabled'110 );111 },112 disableZoomIn: function () {113 this._setElementState(114 this._findElement('plus'),115 'disabled'116 );117 },118 disableZoomOut: function () {119 this._setElementState(120 this._findElement('minus'),121 'disabled'122 );123 },124 resetArrows: function () {125 this._removeElementState(126 this.arrowLeft,127 'disabled'128 );129 this._removeElementState(130 this.arrowRight,131 'disabled'132 );133 },134 disableArrowNext: function () {...
index.js
Source:index.js
...35 });36 return targetElement;37 }38 _removeOldElements (refToRemoveBy) {39 this._findElement(refToRemoveBy)40 .remove();41 }42 _initRemoveOldElements () {43 const removedNodes = [];44 for (const key in this._layoutFrom) {45 if (!this._layoutFrom.hasOwnProperty(key))46 continue;47 if (this._layoutFrom[key].childOf && removedNodes.includes(this._layoutFrom[key].childOf))48 continue;49 if (!this._layoutTo.hasOwnProperty(key)) {50 removedNodes.push(key);51 this._removeOldElements(key);52 };53 }54 }55 _addComponentElement (newElem, nodeName) {56 newElem.className = 'wyser-container__component-wrap';57 const component = Components.exists(nodeName) ?58 Components.use(nodeName) :59 Components.use(Tags.use(nodeName).getComponent(Router.currentRoute.uri))60 newElem.innerHTML = component.load();61 return newElem;62 }63 _addHTMLElement (newElem, classList) {64 newElem.className = Array.isArray(classList) ?65 classList.join(' ') :66 classList;67 return newElem;68 }69 _addNewElement (nodeName) {70 const node = this._layoutTo[nodeName];71 let newElem = document.createElement(node.node || 'div');72 if (node.type == 'component') 73 newElem = this._addComponentElement(newElem, nodeName);74 75 else76 newElem = this._addHTMLElement(newElem, node.classList)77 newElem.dataset.noderef = nodeName;78 const priorSibling = this._findPriorSibling(node.childOf, nodeName);79 if (priorSibling)80 return this._appendElementToSibling(priorSibling, newElem, nodeName);81 return this._appendElementToParent(node.childOf, newElem);82 };83 _updateElement (name) {84 if (Components.exists(name))85 return;86 const component = Components.use(Tags.use(name).getComponent(Router.currentRoute.uri));87 88 this._findElement(name)89 .innerHTML = component.load();90 }91 _appendElementToParent (parentRef, newElement) {92 const parent = this._findElement(parentRef);93 parent.append(newElement);94 this._setRefs();95 }96 _appendElementToSibling (siblingRef, newElement, nodeName) {97 const node = this._layoutTo[nodeName];98 const parent = this._findElement(node.childOf);99 const sibling = this._findElement(siblingRef)100 parent.insertBefore(newElement, sibling.nextSibling);101 }102 _findPriorSibling (parent, child) {103 let priorSibling = null;104 for (let i = 0; i < this._childNodes[parent].length; i++) {105 if (child == this._childNodes[parent][i])106 break; 107 priorSibling = this._childNodes[parent][i];108 }109 return priorSibling;110 }111 _rememberChildNodes () {112 Utils.iterate(this._layoutTo, (key) => {113 this._childNodes[this._layoutTo[key].childOf] =...
whatsapp.js
Source:whatsapp.js
...6 constructor(driver) {7 this.driver = driver;8 }9 get newChatButton() {10 return this._findElement(XPATH.NEW_CHAT_BUTTON);11 }12 get searchContactInputField() {13 return this._findElement(XPATH.CONTACT_SEARCH_INPUT);14 }15 get attachmentMenu() {16 return this._findElement(XPATH.ATTACHMENT_MENU);17 }18 get galleryButton() {19 return this._findElement(XPATH.GALLERY_BUTTON);20 }21 get imageCaptionInputField() {22 return this._findElement(XPATH.IMAGE_CAPTION_INPUT);23 }24 get lastMessageDoubleTicks() {25 return this._findElement(XPATH.LAST_MESSAGE_DOUBLE_TICK)26 }27 get loader() {28 return this._findElement(XPATH.LOADER_PROGRESS);29 }30 get retryButton() {31 return this._findElement(XPATH.RETRY_DIALOG_BOX);32 }33 get sidePanel() {34 return this._findElement(XPATH.SIDE_PANEL);35 }36 get messageBox() {37 return this._findElement(XPATH.MESSAGEBOX);38 }39 get lastMessage() {40 return this._findElement(XPATH.LAST_MESSAGE);41 }42 get qrCode() {43 return this._findElement(XPATH.QR_CODE);44 }45 get useHereButton() {46 return this._findElement(XPATH.USE_HERE_BUTTON);47 }48 async openPage() {49 try {50 await this.driver.get(WHATSAPP_URL);51 } catch (err) {52 console.error("Error while trying to load page", err);53 }54 }55 async findChatElementFor(name) {56 const chatXPath = XPATH.CHAT.replace(NAME_PLACEHOLDER, name);57 return await this._findElement(chatXPath);58 }59 async openChatWith(name) {60 await this.performContactSearchFor(name);61 await pause(500);62 const chat = await this.findChatElementFor(name);63 await chat.click();64 }65 async performContactSearchFor(name) {66 const button = await this.newChatButton;67 await button.click();68 const searchContactInputField = await this.searchContactInputField;69 await searchContactInputField.sendKeys(name);70 }71 async typeMessage(message) {72 const input = await this.messageBox;73 await input.sendKeys(message);74 }75 async uploadImage(path) {76 const menu = await this.attachmentMenu;77 await menu.click();78 const button = await this.galleryButton;79 await button.sendKeys(path);80 }81 async typeImageCaption(caption) {82 const input = await this.imageCaptionInputField;83 await input.sendKeys(caption);84 }85 async isLastMessageSent() {86 let sent = false;87 try {88 await this.lastMessageDoubleTicks;89 sent = true;90 } catch (err) { }91 return sent;92 }93 async isLoading() {94 let loading = false;95 try {96 await this.loader;97 loading = true;98 } catch (err) { }99 return loading;100 }101 async isRequireRetry() {102 let requireRetry = false;103 try {104 await this.retryButton;105 requireRetry = true;106 } catch (err) { }107 return requireRetry;108 }109 async isNeedLogin() {110 let qrPresent = false;111 try {112 await this.qrCode;113 qrPresent = true;114 } catch (err) { }115 return qrPresent116 }117 async isUseHere() {118 let isUseHere = false;119 try {120 await this.useHereButton;121 isUseHere = true;122 } catch (err) { }123 return isUseHere124 }125 async useHere() {126 const useHere = await this.useHereButton;127 await useHere.click();128 }129 _findElement(xpath) {130 return this.driver.getElement(xpath);131 }132}133module.exports = {134 WHATSAPP_URL,135 Whatsapp...
Card.js
Source:Card.js
...31 this._setTemplate(this._card, this._template);32 if (_id) {33 this._id = _id;34 }35 this._findElement(this._card, '.card__title').textContent = title;36 this._findElement(this._card, '.card__text').textContent = text;37 this._findElement(this._card, '.card__source').textContent = source;38 const markElement = this._findElement(this._card, '.card__mark');39 if (markElement) {40 markElement.textContent = keyword;41 }42 const cardDateElement = this._findElement(this._card, '.card__date');43 cardDateElement.setAttribute('datetime', date);44 cardDateElement.textContent = date;45 const cardImgElement = this._findElement(this._card, '.card__image');46 cardImgElement.src = image;47 cardImgElement.alt = title;48 this.setHandlers([49 {50 element: this._card,51 event: 'click',52 callback: () => {53 window.open(link, '_blank');54 },55 }56 ]);57 return this._card;58 }59 remove() {...
note.repository.js
Source:note.repository.js
...3class NoteRepository {4 constructor() {5 this.store = data6 }7 static _findElement(id) {8 return data.findIndex((i) => i.id === id)9 }10 static createNote(note) {11 data.push(note)12 }13 static deleteNote(id) {14 data.splice(this._findElement(id), 1)15 }16 static editNote(id, changes) {17 const note = data.find((note) => note.id === id)18 const merged = { ...note, ...changes }19 data.splice(this._findElement(id), 1, merged)20 }21 static getCurrentNote(id) {22 return data.find((note) => note.id === id)23 }24 static getAllNotes() {25 return data26 }27 static getStatisticsNotes() {28 return calcStats(data)29 }30}...
Using AI Code Generation
1const { Playwright } = require('playwright');2const playwright = new Playwright();3const browser = await playwright.chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const element = await page._findElement('input[name="q"]');7await element.click();8await browser.close();9const { Playwright } = require('playwright');10const playwright = new Playwright();11const browser = await playwright.chromium.launch();12const context = await browser.newContext();13const page = await context.newPage();14const elements = await page._findElements('input[name="q"]');15await elements[0].click();16await browser.close();17const { Playwright } = require('playwright');18const playwright = new Playwright();19const browser = await playwright.chromium.launch();20const context = await browser.newContext();21const page = await context.newPage();22const element = await page._findElementHandle('input[name="q"]');23await element.click();24await browser.close();25const { Playwright } = require('playwright');26const playwright = new Playwright();27const browser = await playwright.chromium.launch();28const context = await browser.newContext();29const page = await context.newPage();30const elements = await page._findElementHandles('input[name="q"]');31await elements[0].click();32await browser.close();33const { Playwright } = require('playwright');34const playwright = new Playwright();35const browser = await playwright.chromium.launch();36const context = await browser.newContext();37const page = await context.newPage();38const element = await page._waitForElement('input[name="q"]');39await element.click();40await browser.close();41const { Playwright } = require('playwright');
Using AI Code Generation
1const { _findElement } = require('@playwright/test/lib/server/dom');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 const element = await _findElement(page, {8 });9 await element.type('Playwright');10 await page.screenshot({ path: 'example.png' });11 await browser.close();12})();13 at DOMDispatcher.resolveNode (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\dom.js:1:2043)14 at DOMDispatcher.dispatch (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\dom.js:1:1478)15 at Connection.dispatch (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\connection.js:1:1640)16 at WebSocketTransport._dispatchMessage (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\transport.js:1:1475)17 at WebSocketTransport._onMessage (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\transport.js:1:1117)18 at WebSocketTransport._ws.addEventListener.event (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\transport.js:1:317)19 at WebSocket.onMessage (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\lib\server\webSocket.js:1:297)20 at WebSocket.emit (events.js:315:20)21 at Receiver.receiverOnMessage (C:\Users\abhishek\Documents\Playwright\playwright\packages\playwright-core\node_modules\ws\lib\websocket.js:789:20)
Using AI Code Generation
1const { _findElement } = require("playwright/lib/client/selectorEngine");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 const searchBox = await _findElement(page, "css=div[role='search'] input");8 console.log(searchBox);9 await browser.close();10})();11const { _findElement } = require("playwright/lib/client/selectorEngine");12const { chromium } = require("playwright");13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const searchBox = await _findElement(page, "css=div[role='search'] input");18 console.log(searchBox);19 await browser.close();20})();21const { _findElement } = require("playwright/lib/client/selectorEngine");22const { chromium } = require("playwright");23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 const searchBox = await _findElement(page, "css=div[role='search'] input");28 console.log(searchBox);29 await browser.close();30})();31const { _findElement } = require("playwright/lib/client/selectorEngine");32const { chromium } = require("playwright");33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 const searchBox = await _findElement(page, "css=div[role='search'] input");38 console.log(searchBox);39 await browser.close();40})();
Using AI Code Generation
1const { _findElement } = require('playwright/lib/server/chromium/crPage');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 const element = await _findElement(page, 'css=div');8 console.log(element);9 await browser.close();10})();11Output: ElementHandle { _channel: Channel, _page: Page, _context: BrowserContext }12To use the internal methods of Playwright in your project, you need to import the internal methods from the playwright module. For example, to use the _findElement method, you can import it as follows:13const { _findElement } = require('playwright/lib/server/chromium/crPage');14Your name to display (optional):
Using AI Code Generation
1const { chromium, webkit, firefox, devices } = require('playwright');2const assert = require('assert');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 let findElement = await page._findElement('input[name="q"]');8 await findElement.type('Hello');9 await browser.close();10})();
Using AI Code Generation
1const { _findElement } = require('playwright/lib/server/dom');2const { chromium } = require('playwright');3const fs = require('fs');4const path = require('path');5(async () => {6 const browser = await chromium.launch({ headless: false });7 const context = await browser.newContext();8 const page = await context.newPage();9 await page.screenshot({ path: 'google.png' });10 const element = await _findElement(page, 'input[name="q"]');11 await element.click();12 await element.type('Hello World!');13 await element.press('Enter');14 await page.screenshot({ path: 'google-search.png' });15 await browser.close();16})();17const { createJSHandle } = require('./domSnapshot');18const { assert } = require('../utils/utils');19module.exports = { _findElement };20async function _findElement(page, selector) {21 const handle = await page.evaluateHandle(selector => document.querySelector(selector), selector);22 const element = handle.asElement();23 assert(element, 'Node is not of type HTMLElement');24 return element;25}
Using AI Code Generation
1const { _findElement } = require('@playwright/test/lib/server/dom');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const element = await _findElement(page, 'css=div');5 console.log(element);6});
Using AI Code Generation
1const { _findElement } = require('playwright');2const { findElement } = require('playwright/lib/server/dom.js');3const { ElementHandle } = require('playwright/lib/server/dom.js');4const { JSHandle } = require('playwright/lib/server/dom.js');5const elementHandle = await _findElement(page, 'css=div');6console.log(elementHandle);7const { _findElements } = require('playwright');8const elementsHandle = await _findElements(page, 'css=div');9console.log(elementsHandle);10const { _querySelector } = require('playwright');11const queryHandle = await _querySelector(page, 'css=div');12console.log(queryHandle);13const { _querySelectorAll } = require('playwright');14const queryAllHandle = await _querySelectorAll(page, 'css=div');15console.log(queryAllHandle);16const { _adoptElementHandle } = require('playwright');17const adoptHandle = await _adoptElementHandle(page, 'css=div');18console.log(adoptHandle);19const { _adoptBackendNodeId } = require('playwright');20const adoptNodeHandle = await _adoptBackendNodeId(page, 'css=div');21console.log(adoptNodeHandle);22const { _adoptElementHandle } = require('playwright');23const adoptHandle = await _adoptElementHandle(page, 'css=div');24console.log(adoptHandle);25const { _adoptBackendNodeId } = require('playwright');26const adoptNodeHandle = await _adoptBackendNodeId(page, 'css=div');27console.log(adoptNodeHandle);28const { _adoptElementHandle } = require('playwright');29const adoptHandle = await _adoptElementHandle(page, 'css=div');30console.log(adoptHandle);31const { _adoptBackendNodeId } = require('playwright');32const adoptNodeHandle = await _adoptBackendNodeId(page
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await browser.close();6})();
Using AI Code Generation
1const { _findElement } = require('@playwright/test/lib/server/frames');2const { Locator } = require('@playwright/test');3const locator = Locator.from('text=Hello World');4const element = await _findElement(page, locator);5console.log(element);6const { _findElements } = require('@playwright/test/lib/server/frames');7const { Locator } = require('@playwright/test');8const locator = Locator.from('text=Hello World');9const elements = await _findElements(page, locator);10console.log(elements);11const { _findElement } = require('@playwright/test/lib/server/frames');12const { Locator } = require('@playwright/test');13module.exports = async () => {14 global._findElement = _findElement;15 global.Locator = Locator;16};17const element = await _findElement(page, Locator.from('text=Hello World'));18console.log(element);19from(selector: string): Locator20from(selector: string, options: LocatorOptions): Locator21from(selector: string, options: LocatorOptions, parent: Locator): Locator22from(selector: string): Locator23from(selector: string, options: LocatorOptions): Locator24from(selector: string, options: LocatorOptions, parent: Locator): Locator25from(selector: Locator | LocatorOptions): Locator26from(selector: Locator | LocatorOptions, options: LocatorOptions): Locator27from(selector: Locator | LocatorOptions, options: LocatorOptions, parent: Locator): Locator28element(): Locator29elements(): Locator30elementHandle(): Promise<ElementHandle>31elementHandles(): Promise<ElementHandle[]>
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!!