How to use launchBrowser method in Playwright Internal

Best JavaScript code snippet using playwright-internal

browserservice.js

Source:browserservice.js Github

copy

Full Screen

...75 done();76 });77 });78 it('should succeed if stoped with open browsers', function (done) {79 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {80 switch (event.name) {81 case 'onLaunched':82 assert.equal( id, event.browserID );83 _browserService.stop(done);84 break;85 }86 });87 });88 });89 describe('#isReady()', function() {90 beforeEach( function() {91 assert( _browserService.start(_cfg, _crashObserver, {'VK_ENTER': 13}) );92 });93 it('should emit ready events when htmlshellremote connects/disconnects', function(done) {94 assert( !_browserService.isReady() );95 var notReadyCalled = false;96 _browserService.on('ready', function(isReady) {97 if (isReady) {98 assert( _browserService.isReady() );99 _browserService.stop(function() {100 assert( !_browserService.isReady() );101 assert( notReadyCalled );102 done();103 });104 } else {105 notReadyCalled = true;106 }107 });108 });109 });110 describe('Browser methods and events', function () {111 beforeEach( function (done) {112 _browserService.once('ready', function (isReady) {113 if (isReady) {114 done();115 }116 });117 _cfg.htmlshell.unsupportedCodecs = ['webm'];118 assert( _browserService.start(_cfg, _crashObserver, {'VK_ENTER': 13}) );119 });120 afterEach( function (done) {121 _browserService.stop(done);122 });123 it('should throw a recovery error when receives an error from htmlshellremote', function (done) {124 Mocks.CheckRecoveryError('[BrowserService] Received remote error: TEST_REMOTE_ERROR', done);125 process.nextTick(function () {126 _htmlshell.emit('error', new Error('TEST_REMOTE_ERROR'));127 });128 });129 it('should close browser when remote disconnects and fail to send more messages', function (done) {130 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {131 switch (event.name) {132 case 'onLaunched':133 assert.equal( id, event.browserID );134 _htmlshell.emit('disconnected');135 break;136 case 'onClose':137 assert.equal( id, event.browserID );138 assert.equal( _browserService.launchBrowser('http://google.com.ar', {}), -1 );139 assert( !_browserService.closeBrowser(0) );140 assert( !_browserService.showBrowser(0) );141 done();142 break;143 }144 });145 assert.equal( id, 0 );146 });147 it('should succed to launch a browser when remote re-connects affter disconnection', function (done) {148 _htmlshell.emit('disconnected');149 assert.equal( _browserService.launchBrowser('http://google.com.ar', {}), -1 );150 _htmlshell.emit('connected');151 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {152 switch (event.name) {153 case 'onLaunched':154 assert.equal( id, event.browserID );155 done();156 break;157 }158 });159 assert.equal( id, 0 );160 });161 it('should launch a browser successfully from http url', function (done) {162 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {163 switch (event.name) {164 case 'onLaunched':165 assert.equal( id, event.browserID );166 done();167 break;168 }169 });170 assert.equal( id, 0 );171 });172 it('should launch a browser successfully from https url', function (done) {173 var id = _browserService.launchBrowser('https://google.com.ar', {}, function (event) {174 switch (event.name) {175 case 'onLaunched':176 assert.equal( id, event.browserID );177 done();178 break;179 }180 });181 assert.equal( id, 0 );182 });183 it('should launch a browser successfully from file url', function( done ) {184 var id = _browserService.launchBrowser('file://' + __dirname + '/resources/bin/basic.html', {}, function (event) {185 switch (event.name) {186 case 'onLaunched':187 assert.equal( id, event.browserID );188 done();189 break;190 }191 });192 assert.equal( id, 0 );193 });194 it('should launch a browser successfully from file url with params', function( done ) {195 var id = _browserService.launchBrowser('file://' + __dirname + '/resources/bin/basic.html?param=value', {}, function (event) {196 switch (event.name) {197 case 'onLaunched':198 assert.equal( id, event.browserID );199 done();200 break;201 }202 });203 assert.equal( id, 0 );204 });205 it('should launch a browser successfully with default options', function( done ) {206 let expectedInitJs = 'TacOnExit=c=>window.onbeforeunload=e=>{c(TacExit);e.returnValue="HTMLSHELL_ASYNC_EXIT";};' +207 'TacExit=()=>{window.onbeforeunload=null;HtmlShellCall("htmlshell","async_exit_complete");};' +208 'window.tacKeyboardLayout={"VK_ENTER":13};';209 _htmlshell.sendMessage = function (msg) {210 assert( msg.launchBrowser );211 var launchMsg = msg.launchBrowser;212 assert.equal( 0, launchMsg.options.bounds.x );213 assert.equal( 0, launchMsg.options.bounds.y );214 assert.equal( 0, launchMsg.options.bounds.w );215 assert.equal( 0, launchMsg.options.bounds.h );216 assert.equal( false, launchMsg.options.bgTransparent );217 assert.equal( true, launchMsg.options.focus );218 assert.equal( expectedInitJs, launchMsg.options.js );219 assert.equal( 0, launchMsg.options.plugins.length );220 };221 var id = _browserService.launchBrowser('https://google.com.ar', {}, function (event) {222 switch (event.name) {223 case 'onLaunched':224 assert.equal( id, event.browserID );225 done();226 break;227 }228 });229 assert.equal( id, 0 );230 });231 it('should launch a browser successfully with valid options', function( done ) {232 var expectedInitJs = 'TacOnExit=c=>window.onbeforeunload=e=>{c(TacExit);e.returnValue="HTMLSHELL_ASYNC_EXIT";};' +233 'TacExit=()=>{window.onbeforeunload=null;HtmlShellCall("htmlshell","async_exit_complete");};' +234 'function MakeApi(n,t,o){' +235 'var e=window;' +236 't.split(".").forEach(n=>{' +237 'e[n]=e[n]||{},' +238 'e=e[n]' +239 '}),' +240 'o.forEach(u=>{' +241 'e[u]=(...e)=>{' +242 'var o,i=e.length;' +243 'return i>0&&"function"==typeof e[--i]&&(o=e[i],e=e.slice(0,i)),HtmlShellCall("RemoteExtension",{id:n,name:t,method:u,params:e},o)' +244 '}' +245 '})' +246 '}' +247 'MakeApi("service.id","TestService",["method1","method2"]);' +248 'window.tacKeyboardLayout={' +249 '"VK_ENTER":13' +250 '};';251 _htmlshell.sendMessage = function (msg) {252 assert( msg.launchBrowser );253 var launchMsg = msg.launchBrowser;254 assert.equal( expectedInitJs, launchMsg.options.js );255 assert.equal( 10, launchMsg.options.bounds.x );256 assert.equal( 20, launchMsg.options.bounds.y );257 assert.equal( 200, launchMsg.options.bounds.w );258 assert.equal( 100, launchMsg.options.bounds.h );259 assert.equal( true, launchMsg.options.bgTransparent );260 assert.equal( false, launchMsg.options.focus );261 assert.equal( 2, launchMsg.options.plugins.length );262 assert.equal( 'PlugIn 1', launchMsg.options.plugins[0] );263 assert.equal( 'PlugIn 2', launchMsg.options.plugins[1] );264 };265 var id = _browserService.launchBrowser('https://google.com.ar', {266 apis:[{id:'service.id', name: 'TestService', exports: ['method1', 'method2']}],267 bounds: { x:10, y:20, w:200, h:100 },268 focus: false,269 bgTransparent: true,270 plugins: ['PlugIn 1', 'PlugIn 2']271 },272 function (event) {273 switch (event.name) {274 case 'onLaunched':275 assert.equal( id, event.browserID );276 done();277 break;278 }279 });280 assert.equal( id, 0 );281 });282 it('should launch browser with keyboard layout allways', function( done ) {283 var expectedInitJs = 'TacOnExit=c=>window.onbeforeunload=e=>{c(TacExit);e.returnValue="HTMLSHELL_ASYNC_EXIT";};' +284 'TacExit=()=>{window.onbeforeunload=null;HtmlShellCall("htmlshell","async_exit_complete");};' +285 'window.tacKeyboardLayout={"VK_ENTER":13};';286 _htmlshell.sendMessage = function (msg) {287 assert( msg.launchBrowser );288 assert.equal( expectedInitJs, msg.launchBrowser.options.js );289 };290 var id = _browserService.launchBrowser('https://google.com.ar', {},291 function (event) {292 switch (event.name) {293 case 'onLaunched':294 assert.equal( id, event.browserID );295 done();296 break;297 }298 });299 assert.equal( id, 0 );300 });301 it('should launch browser with disabled codecs', function( done ) {302 _htmlshell.sendMessage = function (msg) {303 assert( msg.launchBrowser );304 assert.equal(305 msg.launchBrowser.options.js,306 'TacOnExit=c=>window.onbeforeunload=e=>{c(TacExit);e.returnValue="HTMLSHELL_ASYNC_EXIT";};' +307 'TacExit=()=>{window.onbeforeunload=null;HtmlShellCall("htmlshell","async_exit_complete");};' +308 'window.tacKeyboardLayout={"VK_ENTER":13};' +309 'function DisableCodecs(e){function i(i,n){return void 0===n||e.some(function(e){return-1!=n.indexOf(e)})?"":i(n)}var n=document.createElement("video");n.__proto__.canPlayType=i.bind(this,n.canPlayType.bind(n));var o=window.MediaSource;void 0!==o&&(o.isTypeSupported=i.bind(this,o.isTypeSupported.bind(o)))}' +310 'DisableCodecs(["webm"]);'311 );312 };313 var id = _browserService.launchBrowser('https://google.com.ar', {hwCodecsOnly: true},314 function (event) {315 switch (event.name) {316 case 'onLaunched':317 assert.equal( id, event.browserID );318 done();319 break;320 }321 });322 assert.equal( id, 0 );323 });324 it('should emit error if a browser is launched for an inexistent id', function (done) {325 _browserService.on('BrowserServiceError', function (err) {326 assert.equal( 'Browser launched for inexisten id=5', err.message );327 done();328 });329 _htmlshell.evtCallback({330 type: 'onLaunched',331 browserID: 5332 });333 });334 it('should emit error if a browser is done loading when after browser was closed', function (done) {335 _browserService.on('BrowserServiceError', function (err) {336 assert.equal( 'Received browser loaded event for inexisten id=5', err.message );337 done();338 });339 _htmlshell.evtCallback({340 type: 'onLoaded',341 browserID: 5342 });343 });344 it('should fail to launch a browser from invalid urls', function() {345 _browserService.on('browserLaunched', function (/*id*/) {346 assert( false && 'Browser should fail to launch' );347 });348 assert.equal( -1, _browserService.launchBrowser('ftp://google.com.ar') );349 assert.equal( -1, _browserService.launchBrowser('file://' + __dirname + '/resources/bin/unexistent.html') );350 });351 it('should fail to launch a browser with invalid bounds parameter', function() {352 _browserService.on('browserLaunched', function (/*id*/) {353 assert( false && 'Browser should fail to launch' );354 });355 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {bounds:'invalid param'}) );356 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {bounds:{}}) );357 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {bounds:{x:0,y:0,w:-1,h:0}}) );358 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {bounds:{x:0,y:0}}) );359 });360 it('should fail to launch a browser with invalid plugins parameter', function() {361 _browserService.on('browserLaunched', function (/*id*/) {362 assert( false && 'Browser should fail to launch' );363 });364 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {plugins:'invalid param'}) );365 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {plugins:{}}) );366 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', {plugins:[1]}) );367 });368 it('should fail to launch a browser with invalid jsapis parameter', function() {369 _browserService.on('browserLaunched', function (/*id*/) {370 assert( false && 'Browser should fail to launch' );371 });372 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', null, 'invalid param') );373 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', null, {}) );374 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', null, ['']) );375 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', null, [{id: '', name: '', exports: []}]) );376 assert.equal( -1, _browserService.launchBrowser('http://google.com.ar', null, [{id: 'id', name: 'name', exports: ''}]) );377 });378 it('should launch two browsers successfully', function( done ) {379 var launched = 0;380 _browserService.on('browserLaunched', function (id) {381 launched++;382 switch (launched) {383 case 1:384 assert.equal( id1, id );385 break;386 case 2:387 assert.equal( id2, id );388 done();389 break;390 }391 });392 var id1 = _browserService.launchBrowser('http://google.com.ar');393 var id2 = _browserService.launchBrowser('file://' + __dirname + '/resources/bin/basic.html');394 assert.equal( id1, 0 );395 assert.equal( id2, 1 );396 });397 it('should show/hide a browser successfully', function (done) {398 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {399 switch (event.name) {400 case 'onLaunched':401 assert.equal( id, event.browserID );402 assert( _browserService.showBrowser(id, true) );403 assert( _browserService.showBrowser(id, false) );404 done();405 break;406 }407 });408 assert.equal( id, 0 );409 });410 it('should close a browser successfully after it was successfully launched if id is valid', function (done) {411 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {412 switch (event.name) {413 case 'onLaunched':414 assert.equal( id, event.browserID );415 assert( _browserService.closeBrowser(id) );416 break;417 case 'onClose':418 assert.equal( id, event.browserID );419 done();420 break;421 }422 });423 });424 it('should close a browser successfully inmediatly after it was launched if id is valid', function (done) {425 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {426 switch (event.name) {427 case 'onLaunched':428 done(new Error('Shouldn\'t call launched callback when browser is closed'));429 break;430 case 'onClose':431 assert.equal( id, event.browserID );432 done();433 break;434 }435 });436 assert( _browserService.closeBrowser(id) );437 });438 it('should close multiples browsers successfully', function (done) {439 var b2Closed = false;440 _browserService.on('browserClosed', function (id) {441 if (id === id1) {442 assert( b2Closed );443 done();444 }445 });446 var id1 = _browserService.launchBrowser('http://google.com.ar');447 var id2 = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {448 switch (event.name) {449 case 'onLaunched':450 assert( id1 != id2 );451 assert.equal( id2, event.browserID );452 assert( _browserService.closeBrowser(id2) );453 assert( _browserService.closeBrowser(id1) );454 break;455 case 'onClose':456 assert.equal( id2, event.browserID );457 b2Closed = true;458 break;459 }460 });461 });462 it('should fail to close a browser from an invalid id', function () {463 _browserService.on('browserClosed', function (/*id*/) {464 assert( false && 'Should not call onBrowserClosed if closeBrowser fail' );465 });466 assert( !_browserService.closeBrowser(2) );467 });468 it('should fail to close a browser twice', function () {469 var closed = 0;470 var id = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {471 switch (event.name) {472 case 'onClose':473 closed++;474 assert.equal( closed, 1 );475 assert.equal( id, event.browserID );476 break;477 }478 });479 assert( _browserService.closeBrowser(id) );480 assert( !_browserService.closeBrowser(id) );481 });482 it('should emit browserLaunched event when a browser is launched', function (done) {483 _browserService.once('browserLaunched', function (bId) {484 assert.equal( id, bId );485 assert( _browserService.closeBrowser(bId) );486 done();487 });488 var id = _browserService.launchBrowser('http://google.com.ar');489 assert.equal( id, 0 );490 });491 it('should emit browserLaunched event once for each browser launched', function (done) {492 var launched = 0;493 _browserService.on('browserLaunched', function (id) {494 launched++;495 if (id !== id1 && id !== id2) {496 done(new Error('browserLaunched emited with unexpected browser id'));497 }498 if (launched == 2) {499 assert( _browserService.closeBrowser(id1) );500 assert( _browserService.closeBrowser(id2) );501 done();502 }503 });504 var id1 = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {505 switch (event.name) {506 case 'onLaunched': assert.equal( id1, event.browserID ); break;507 }508 });509 var id2 = _browserService.launchBrowser('http://html5test.com', {}, function (event) {510 switch (event.name) {511 case 'onLaunched': assert.equal( id2, event.browserID ); break;512 }513 });514 });515 it('should emit browserClosed event when a browser is closed', function (done) {516 _browserService.once('browserClosed', function (id) {517 assert.equal( id, bId );518 done();519 });520 var bId = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {521 switch (event.name) {522 case 'onLaunched':523 assert.equal( bId, event.browserID );524 assert( _browserService.closeBrowser(bId) );525 break;526 }527 });528 });529 it('should emit browserClosed event for each browser closed', function (done) {530 var closed = 0;531 _browserService.on('browserClosed', function (id) {532 closed++;533 if (id !== bId1 && id !== bId2) done(new Error('Got bad id'));534 if (closed == 2) done();535 });536 var bId1 = _browserService.launchBrowser('http://google.com.ar', {}, function (event) {537 switch (event.name) {538 case 'onLaunched': assert.equal( bId1, event.browserID ); break;539 }540 });541 var bId2 = _browserService.launchBrowser('http://html5test.com', {}, function (event) {542 switch (event.name) {543 case 'onLaunched':544 assert.equal( bId2, event.browserID );545 assert( _browserService.closeBrowser(bId1) );546 assert( _browserService.closeBrowser(bId2) );547 break;548 }549 });550 });551 it('should emit browser closed for loaded browsers when remote disconnects', function (done) {552 _browserService.on('browserLaunched', function (id) {553 assert.equal( id, originalId );554 _htmlshell.emit('disconnected');555 });556 _browserService.on('browserClosed', function (id, error) {557 assert.equal( 'Htmlshell disconnected', error.message );558 assert.equal( id, originalId );559 done();560 });561 _htmlshell.shouldSendResponse = true;562 var originalId = _browserService.launchBrowser('http://google.com');563 assert.equal( originalId, 0 );564 });565 it('should emit browser closed for loading browsers when remote disconnects', function (done) {566 _browserService.on('browserClosed', function (id, error) {567 assert.equal( 'Htmlshell disconnected', error.message );568 assert.equal( id, originalId );569 done();570 });571 _htmlshell.shouldSendResponse = false;572 var originalId = _browserService.launchBrowser('http://google.com');573 assert.equal( originalId, 0 );574 _htmlshell.emit('disconnected');575 });576 it('should emit browser closed for closing browsers when remote disconnects', function (done) {577 _browserService.on('browserLaunched', function (id) {578 assert.equal( id, originalId );579 _htmlshell.shouldSendResponse = false;580 _browserService.closeBrowser(originalId);581 _htmlshell.shouldSendResponse = true;582 _htmlshell.emit('disconnected');583 });584 _browserService.on('browserClosed', function (id, error) {585 assert.equal( 'Htmlshell disconnected', error.message );586 assert.equal( id, originalId );587 done();588 });589 _htmlshell.shouldSendResponse = true;590 var originalId = _browserService.launchBrowser('http://google.com');591 assert.equal( originalId, 0 );592 });593 it('should not emit browser closed for closed browsers when remote disconnects', function () {594 _browserService.on('browserLaunched', function (id) {595 assert.equal( id, originalId );596 _browserService.closeBrowser(originalId);597 });598 _browserService.on('browserClosed', function (id) {599 assert.equal( id, originalId );600 _htmlshell.emit('disconnected');601 });602 var originalId = _browserService.launchBrowser('http://google.com');603 assert.equal( originalId, 0 );604 });605 it('apicall should return error if browser do not exist', function (done) {606 _htmlshell.sendMessage = function( msg ) {607 if (msg.jsResponse) {608 var evt = msg.jsResponse;609 assert.equal( 1, evt.queryID );610 assert.equal( 2, evt.browserID );611 assert.equal( 'Api call arrived from unexistent browser with id=2', evt.error );612 assert( !evt.response );613 assert( !evt.isSignal );614 done();615 }616 };617 _htmlshell.evtCallback({618 type: 'onAPI',619 browserID: '2',620 queryID: '1',621 params: '{"id":"ar.edu.unlp.info.lifia.tvd.FakeService","method":"test","params":["test_params"]}',622 });623 });624 it('apicall should return error if browser do not handle api call', function (done) {625 _htmlshell.sendMessage = function( msg ) {626 if (msg.jsResponse) {627 var evt = msg.jsResponse;628 assert.equal( bId, evt.browserID );629 assert.equal( 2, evt.queryID );630 assert.equal( 'Api call not handled by browser with id=' + bId, evt.error );631 assert( !evt.response );632 assert( !evt.isSignal );633 _browserService.closeBrowser(bId);634 }635 };636 _browserService.on('browserClosed', function (id) {637 assert.equal( bId, id );638 done();639 });640 _browserService.on('browserLaunched', function (id) {641 assert.equal( bId, id );642 _htmlshell.evtCallback({643 type: 'onAPI',644 browserID: bId,645 queryID: '2',646 params: '{"id":"ar.edu.unlp.info.lifia.tvd.FakeService","method":"test","params":["test_params"]}'647 });648 });649 var bId = _browserService.launchBrowser('http://google.com');650 });651 it('apicall should not remove callback if apicall is a signal', function (done) {652 var resultCB = null;653 var called = 0;654 _htmlshell.sendMessage = function( msg ) {655 if (msg.jsResponse) {656 var evt = msg.jsResponse;657 assert.equal( 2, evt.queryID );658 assert.equal( 0, evt.browserID );659 assert( !evt.error );660 assert.equal( 'Test signal', JSON.parse(evt.params) );661 assert( evt.isSignal );662 called++;663 }664 };665 var bId = _browserService.launchBrowser('http://google.com', {}, function (evt) {666 switch (evt.name) {667 case 'onLaunched':668 assert.equal( bId, evt.browserID );669 _htmlshell.evtCallback({670 type: 'onAPI',671 browserID: bId,672 queryID: 2,673 params: '{"id":"ar.edu.unlp.info.lifia.tvd.FakeService","method":"on","params":[]}'674 });675 break;676 case 'onClose':677 assert.equal( bId, evt.browserID );678 assert( !evt.error );679 done();680 break;681 case 'onAPI':682 assert.equal( bId, evt.browserID );683 assert.equal( 'ar.edu.unlp.info.lifia.tvd.FakeService', evt.serviceID );684 assert.equal( 'on', evt.method );685 assert.equal( evt.params, undefined );686 resultCB = evt.resultCB;687 }688 });689 process.nextTick(function() {690 assert( resultCB );691 resultCB({data:['Test signal'],isSignal:true});692 resultCB({data:['Test signal'],isSignal:true});693 assert.equal( 2, called );694 _browserService.closeBrowser(bId);695 });696 });697 it('apicall should call api handler correctly', function (done) {698 _htmlshell.sendMessage = function( msg ) {699 if (msg.jsResponse) {700 var evt = msg.jsResponse;701 assert.equal( 2, evt.queryID );702 assert.equal( bId, evt.browserID );703 assert.equal( 'test_response', JSON.parse(evt.params) );704 assert( !evt.error );705 assert( !evt.isSignal );706 _browserService.closeBrowser(bId);707 }708 };709 var bId = _browserService.launchBrowser('http://google.com', {}, function (evt) {710 switch (evt.name) {711 case 'onLaunched':712 assert.equal( bId, evt.browserID );713 _htmlshell.evtCallback({714 type: 'onAPI',715 browserID: bId,716 queryID: 2,717 params: '{"id":"ar.edu.unlp.info.lifia.tvd.FakeService","method":"test","params":["test_params"]}',718 });719 break;720 case 'onClose':721 assert.equal( bId, evt.browserID );722 assert( !evt.error );723 done();724 break;725 case 'onAPI':726 assert.equal( bId, evt.browserID );727 assert.equal( 'ar.edu.unlp.info.lifia.tvd.FakeService', evt.serviceID );728 assert.equal( 'test', evt.method );729 assert.equal( 'test_params', evt.params );730 evt.resultCB({data:['test_response'],isSignal:false});731 }732 });733 });734 it('key event should call onKey handler correctly', function (done) {735 var bId = _browserService.launchBrowser('http://google.com', {}, function (evt) {736 switch (evt.name) {737 case 'onLaunched':738 assert.equal( bId, evt.browserID );739 _htmlshell.evtCallback({740 type: 'onKey',741 browserID: bId,742 keyCode: 13,743 isUp: true744 });745 break;746 case 'onClose':747 assert.equal( bId, evt.browserID );748 assert( !evt.error );749 done();750 break;751 case 'onKey':752 assert.equal( bId, evt.browserID );753 assert.equal( "VK_ENTER", evt.code );754 assert.equal( true, evt.isUp );755 _browserService.closeBrowser(bId);756 break;757 }758 });759 });760 it('should emit error if a key event arrive for an inexsitent browser id', function (done) {761 _browserService.on('BrowserServiceError', function (err) {762 assert.equal( 'Received key event from invalid browser with id=5', err.message );763 done();764 });765 _htmlshell.evtCallback({766 type: 'onKey',767 browserID: 5,768 keyCode: 10,769 isUp: true770 });771 });772 it('error event should call onWebLog handler correctly', function (done) {773 var bId = _browserService.launchBrowser('http://google.com', {}, function (evt) {774 switch (evt.name) {775 case 'onLaunched':776 assert.equal( bId, evt.browserID );777 _htmlshell.evtCallback({778 type: 'onWebLog',779 browserID: bId,780 logData: {781 source: 'www.google.com.ar',782 line: 43,783 level: 2,784 message: 'Error description',785 }786 });787 break;788 case 'onClose':789 assert.equal( bId, evt.browserID );790 assert( !evt.error );791 done();792 break;793 case 'onWebLog':794 assert.equal( bId, evt.browserID );795 assert.equal( 'Error description', evt.logData.message );796 assert.equal( 'www.google.com.ar', evt.logData.source );797 assert.equal( 43, evt.logData.line );798 assert.equal( 2, evt.logData.level );799 _browserService.closeBrowser(bId);800 break;801 }802 });803 });804 it('should emit error if a webLog event arrive for an inexsitent browser id', function (done) {805 _browserService.on('BrowserServiceError', function (err) {806 assert.equal( 'Received weblog event from invalid browser with id=5', err.message );807 done();808 });809 _htmlshell.evtCallback({810 type: 'onWebLog',811 browserID: 5,812 logData: {813 message: 'Error description',814 source: 'www.google.com.ar',815 line: 43,816 level: 2817 }818 });819 });820 it('not handled message should emit error event', function (done) {821 _browserService.once('BrowserServiceError', function (err) {822 assert.equal( 'Received invalid message from htmlshell', err.message );823 done();824 });825 _htmlshell.evtCallback({826 type: 'badMsg'827 });828 });829 it('should check for minidumps when a browser is closed with error', function (done) {830 var bId = _browserService.launchBrowser('http://google.com', {}, function (evt) {831 switch (evt.name) {832 case 'onLaunched':833 assert.equal( bId, evt.browserID );834 _htmlshell.evtCallback({835 type: 'onLoaded',836 browserID: bId,837 });838 break;839 case 'onLoaded':840 _htmlshell.evtCallback({841 type: 'onClosed',842 browserID: bId,843 error: 'Renderer process crashed'844 });845 break;846 case 'onClose':847 assert.equal( bId, evt.browserID );848 assert.equal( evt.error.message, 'Renderer process crashed' );849 assert.equal( 1, _crashObserver.reports );850 done();851 break;852 }853 });854 });855 describe('dump', function() {856 it('should dump browser service state', function() {857 assert.equal( _browserService.launchBrowser('http://google.com'), 0 );858 var dump = _browserService.dumpState();859 assert.equal( dump.browsers.length, 1 );860 assert.equal( dump.browsers[0].id, 0 );861 assert.equal( dump.browsers[0].status, 'loading' );862 assert.equal( dump.browsers[0].url, 'http://google.com' );863 assert.equal( dump.browsers[0].apis.length, 0 );864 assert.equal( Object.keys(dump.crashes).length, 1 );865 assert.equal( dump.crashes['test.dmp'], 'ABCDE' );866 });867 });868 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...9const { dividendsScrappyHosts } = require('./utils/scrappyHosts')10class ScrappyRepository {11 async scrappyFundamentalsData(symbol) {12 const formattedSymbol = symbol.toLowerCase()13 const { browser, evaluate } = await launchBrowser({ url: `https://statusinvest.com.br/acoes/${formattedSymbol}` })14 const result = await evaluate(tryGetFundamentals)15 browser.close()16 return result17 }18 async scrappyDailyData(symbol) {19 console.log('Tentando ativo:' + symbol)20 let result = {}21 const formattedSymbol = symbol.toLowerCase()22 const { browser, page, evaluate } = await launchBrowser({ url: `https://statusinvest.com.br/acoes/${formattedSymbol}` })23 result = await evaluate(tryGetStockData)24 if (result.failed) {25 await page.goto(`https://statusinvest.com.br/fundos-imobiliarios/${formattedSymbol}`)26 await page.waitFor(1000)27 result = await evaluate(tryGetStockData)28 }29 // console.log(JSON.stringify(result))30 await updateDailyData(symbol, result)31 browser.close()32 return result33 }34 async scrappyBenchmarks() {35 const benchmarkSymbols = {36 IBOV: 'ibovespa',37 IFIX: 'ifix'38 }39 const ibovNavigation = await launchBrowser({ url: `https://statusinvest.com.br/indices/${benchmarkSymbols.IBOV}` })40 const ibovResult = await ibovNavigation.evaluate(tryGetBenchmarks)41 ibovNavigation.browser.close()42 // console.log(ibovResult)43 const ifixNavigation = await launchBrowser({ url: `https://statusinvest.com.br/indices/${benchmarkSymbols.IFIX}` })44 const ifixResult = await ifixNavigation.evaluate(tryGetBenchmarks)45 ifixNavigation.browser.close()46 // console.log(ifixResult)47 await updateDailyData(benchmarkSymbols.IBOV, ibovResult)48 await updateDailyData(benchmarkSymbols.IFIX, ifixResult)49 return {50 ibovResult,51 ifixResult52 }53 }54 async scrappyStockDataFromB3(symbol, isRetry = false) {55 const formattedSymbol = symbol.toUpperCase()56 console.log('Trying ' + formattedSymbol)57 const actionIdentifiers = {58 input: '#txtCampoPesquisa',59 button: '#btnBuscarOutrosAtivos'60 }61 const { browser, page, evaluate } = await launchBrowser({ url: 'http://www.b3.com.br/pt_br/market-data-e-indices/servicos-de-dados/market-data/cotacoes/outros-ativos.htm' })62 const delay = isRetry ? 3000 : 200063 await page.$eval(actionIdentifiers.input, (el, value) => { el.value = value }, formattedSymbol)64 await page.click(actionIdentifiers.button)65 await page.waitFor(delay)66 const result = await evaluate(tryGetStockDataFromB3)67 await updateDailyData(symbol, result)68 browser.close()69 return result70 }71 async scrappyLastStockDataUpdate(stock) {72 const defaultSymbol = 'ITSA4'73 const symbolToScrappy = stock || defaultSymbol74 const actionIdentifiers = {75 input: '#txtCampoPesquisa',76 button: '#btnBuscarOutrosAtivos'77 }78 const { browser, page, evaluate } = await launchBrowser({ url: 'http://www.b3.com.br/pt_br/market-data-e-indices/servicos-de-dados/market-data/cotacoes/outros-ativos.htm' })79 await page.$eval(actionIdentifiers.input, (el, value) => { el.value = value }, symbolToScrappy)80 await page.click(actionIdentifiers.button)81 await page.waitFor(2000)82 const result = await evaluate(tryGetLastStockDataUpdate)83 browser.close()84 return result85 }86 async scrappyStockClass(symbol) {87 const quoteAlreadyExists = await Daily.findOne({ symbol: symbol.toUpperCase() })88 const classAlreadyExists = !!quoteAlreadyExists && quoteAlreadyExists.class !== 'Não aplicável'89 if (classAlreadyExists) return quoteAlreadyExists.class90 try {91 console.log('Classe do ativo:' + symbol)92 let result = {}93 const formattedSymbol = symbol.toLowerCase()94 const { browser, page, evaluate } = await launchBrowser({ url: `https://statusinvest.com.br/acoes/${formattedSymbol}` })95 result = await evaluate(tryGetStockClass)96 if (result.failed) {97 await page.goto(`https://statusinvest.com.br/fundos-imobiliarios/${formattedSymbol}`)98 await page.waitFor(1000)99 result = await evaluate(tryGetStockClass)100 }101 if (result.failed) {102 await page.goto(`https://statusinvest.com.br/bdrs/${formattedSymbol}`)103 await page.waitFor(2000)104 result = await evaluate(tryGetStockClass)105 }106 if (result.failed) {107 await page.goto(`https://statusinvest.com.br/etfs/${formattedSymbol}`)108 await page.waitFor(2000)109 result = await evaluate(tryGetStockClass)110 }111 await Daily.findByIdAndUpdate(quoteAlreadyExists._id, { class: result.class })112 browser.close()113 return result.class114 } catch (error) {115 return 'not found'116 }117 }118 async scrappyStockDividends() {119 // We need improve it to scrappy data for all companies120 const { browser, page, evaluate } = await launchBrowser({ url: dividendsScrappyHosts.stocks })121 await page.waitForSelector('#result')122 const stockEarnings = await evaluate(tryGetDividends)123 const { datePayment: stocksPaymentSection } = JSON.parse(stockEarnings)124 !!stockEarnings && await createAllEarnings(stocksPaymentSection)125 browser.close()126 return stocksPaymentSection127 }128 async scrappyFiisDividends() {129 // We need improve it to scrappy data for all companies130 const { browser, page, evaluate } = await launchBrowser({ url: dividendsScrappyHosts.fiis })131 await page.waitForSelector('#result')132 const fiisEarnings = await evaluate(tryGetDividends)133 const { datePayment: fiisPaymentSection } = JSON.parse(fiisEarnings)134 !!fiisEarnings && await createAllEarnings(fiisPaymentSection)135 browser.close()136 return fiisPaymentSection137 }138}...

Full Screen

Full Screen

右键添加“在IE中打开”.uc.js

Source:右键添加“在IE中打开”.uc.js Github

copy

Full Screen

1// ==UserScript==2// @name View in other browser3// @include main4// @author Cye3s5// @version 1.0.201007156// ==/UserScript==7var LaunchBrowser = {8 browserName:"IE",9 browserPath:"C:\\Program Files\\Internet Explorer\\iexplore.exe",10 mSchemes: ["file", "ftp", "http", "https"],11 browser: Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile),12 shellServicr:Cc["@mozilla.org/browser/shell-service;1"].getService(Ci.nsIShellService),13 init: function()14 {15 this.initialized = true;16 var menuLabel = "\u5728"+this.browserName+"\u4E2D\u6253\u5F00";17 this.browser.initWithPath(this.browserPath);18 this.mItem = document.createElement("menuitem");19 this.mItem.setAttribute("id", "context-LaunchBrowser");20 this.mItem.setAttribute("label", menuLabel);21 this.mItem.setAttribute("accesskey", "U");22 this.mItemPlace = document.createElement("menuitem");23 this.mItemPlace.setAttribute("id", "placesContext-LaunchBrowser");24 this.mItemPlace.setAttribute("label", menuLabel);25 this.mItemPlace.setAttribute("accesskey", "U");26 this.mItemPlace.setAttribute("selection","link");27 this.mItemPlace.setAttribute("selectiontype","single");28 document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { LaunchBrowser.onPopupShowing(this); }, false);29 document.getElementById("placesContext").addEventListener("popupshowing", function() { LaunchBrowser.onPopupShowingPlace(); }, false);30 document.getElementById("sidebar-box").addEventListener("load", function(event) {31 var doc = event.target;32 if (doc.location == "chrome://browser/content/history/history-panel.xul"||doc.location == "chrome://browser/content/bookmarks/bookmarksPanel.xul") {33 var context = doc.getElementById("placesContext");34 context.addEventListener("popupshowing", function() {35 window.parent.LaunchBrowser.mItemPlace.setAttribute("oncommand", "try {var LaunchBrowserSideBar=window.parent.LaunchBrowser;var node=document.popupNode;node = node.parentNode.view.nodeForTreeIndex(node.parentNode.view.selection.currentIndex);LaunchBrowserSideBar.shellServicr.openApplicationWithURI(LaunchBrowserSideBar.browser,node.uri);} catch (ex) { alert(ex.message);}");36 context.insertBefore(window.parent.LaunchBrowser.mItemPlace,doc.getElementById("placesContext_open:newwindow"));37 }, false);38 }39 }, true);40 41 this.mItemTab = document.createElement("menuitem");42 this.mItemTab.setAttribute("id", "tab-context-LaunchBrowser");43 this.mItemTab.setAttribute("label", menuLabel);44 this.mItemTab.setAttribute("accesskey", "U");45 this.mItemTab.setAttribute("oncommand", "LaunchBrowser.launch(gBrowser.getBrowserForTab(document.popupNode).currentURI);");46 gBrowser.mStrip.childNodes[1].appendChild(this.mItemTab);47 },48 onPopupShowing: function(aPopup)49 {50 aPopup.insertBefore(this.mItem, document.getElementById("context-sep-" + ((gContextMenu.onLink)?"open":"stop")));51 this.mItem.setAttribute("oncommand", "LaunchBrowser.launch(" + ((gContextMenu.onLink)?"gContextMenu.linkURI":"gBrowser.currentURI") + ");");52 this.mItem.hidden = !gContextMenu.onLink && (gContextMenu.isTextSelected || gContextMenu.onImage || gContextMenu.onTextInput);53 this.mItem.setAttribute("disabled", this.mItem.hidden || !this.isSupported((gContextMenu.onLink)?gContextMenu.linkURI:gBrowser.currentURI));54 },55 onPopupShowingPlace: function()56 {57 this.mItemPlace.setAttribute("oncommand", "LaunchBrowser.placesLaunch();");58 document.getElementById("placesContext").insertBefore(this.mItemPlace,document.getElementById("placesContext_open:newtab"));59 },60 launch: function(aURI)61 {62 if (!this.isSupported(aURI))63 {64 throw new Error("LaunchBrowser: unsupported URI scheme '" + aURI.scheme + "'!");65 }66 this.shellServicr.openApplicationWithURI(this.browser,aURI.spec);67 },68 isSupported: function(aURI)69 {70 return this.mSchemes.indexOf(aURI.scheme) > -1;71 },72 placesLaunch: function()73 {74 var n = document.popupNode;75 if (n.node && n.node.uri)76 {77 this.shellServicr.openApplicationWithURI(this.browser,n.node.uri);78 }79 else if (n._placesNode && n._placesNode.uri)80 {81 this.shellServicr.openApplicationWithURI(this.browser,n._placesNode.uri);82 }83 }84};...

Full Screen

Full Screen

cron.js

Source:cron.js Github

copy

Full Screen

...12!(async () => {13 console.log(new Date(), process.argv)14 let browser = null;15 if (process.argv.includes('latest')) {16 browser = await launchBrowser()17 await fetchLatest(browser)18 //if (browser) await browser.close()19 }20 else if (process.argv.includes('novels')) {21 browser = await launchBrowser()22 await fetchNovels(browser)23 //if (browser) await browser.close()24 }25 else if (process.argv.includes('track')) {26 browser = await launchBrowser()27 await trackNovels(browser)28 if (!process.argv.includes('all'))29 setTimeout(async () => {30 process.exit()31 }, 170 * 1000)32 }33 else if (process.argv.includes('announce')) {34 await announceNovels()35 }36 else if (process.argv.includes('raw')) {37 browser = await launchBrowser()38 await checkRaw(browser)39 }40 else if (process.argv.includes('update')) {41 let params = {42 min: 0,43 max: 10000,44 cron: true,45 reqGroupID: 'updateChapters'46 };47 let queryStr = {48 where: {49 chapterContent: {50 [Sequelize.Op.not]: null51 }52 },53 group: ['novel.id'],54 attributes: [[Sequelize.fn('COUNT', 'id'), 'count']],55 include: ['novel']56 }57 const novel_ids = await Chapter.findAll(queryStr).then(chapters =>58 chapters.filter(c =>59 c.dataValues.count > numerics.update_chapter_limit && (!params.greed || c.novel.token == "greed")60 ).map(c => c.novel.id)61 )62 const novels = await Novel.findAll({63 where: {64 id: {65 [Sequelize.Op.in]: novel_ids66 }67 },68 include: ['trackers'],69 order: ['canonicalName']70 });71 browser = await launchBrowser()72 await scrapeNovels(novels, params)73 }74 if (browser) await browser.disconnect()75 process.exit()76 //await browser.close()...

Full Screen

Full Screen

simulate.js

Source:simulate.js Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation. All rights reserved.2/*eslint-env node */3var Simulator = require('./server/simulator');4var launchBrowser = function (target, url) {5 return require('cordova-serve').launchBrowser({ target: target, url: url });6};7var simulate = function (opts) {8 if(opts.generateids) {9 require('./devices/make-uuids');10 }11 var target = opts.target || 'default';12 var simulator = new Simulator(opts);13 return simulator.startSimulation()14 .then(function () {15 return launchBrowser(target, simulator.appUrl());16 })17 .then(function () {18 return launchBrowser(target, simulator.simHostUrl());19 })20 .then(function () {21 return simulator;22 })23 .catch(function (error) {24 // Ensure server is closed, then rethrow so it can be handled by downstream consumers.25 simulator.stopSimulation();26 if (error instanceof Error) {27 throw error;28 } else {29 throw new Error(error);30 }31 });32};...

Full Screen

Full Screen

browsers.js

Source:browsers.js Github

copy

Full Screen

1import React from 'react';2import PropTypes from 'prop-types';3import {connect} from 'react-redux';4import Browser from './browser.js';5const byNameThenVersion = (a, b) => {6 if (a.name < b.name) return -1;7 if (a.name > b.name) return 1;8 if (a.version < b.version) return -1;9 if (a.version > b.version) return 1;10 return 0;11};12const Browsers = ({browsers, launchBrowser}) => {13 const browserElements = browsers14 .sort(byNameThenVersion)15 .map((browser, index) => {16 return <Browser browser={browser} launchBrowser={launchBrowser} key={index} />;17 });18 return <div className="browsers">{browserElements}</div>;19};20Browsers.propTypes = {21 browsers: PropTypes.array,22 launchBrowser: PropTypes.func.isRequired23};24import { launchBrowser } from '../../../common/actions/browsers.js';25import { getBrowsers } from '../../reducers/browsers.js';26const mapStateToProps = (state) => ({27 browsers: getBrowsers(state)28});29const mapDispatchToProps = {30 launchBrowser31};...

Full Screen

Full Screen

browser.js

Source:browser.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.launchBrowser = void 0;6const puppeteer = require("puppeteer");7const launchBrowser = async () => {8 const option = {9 args: ["--no-sandbox", "--disable-setuid-sandbox"]10 };11 return await puppeteer.launch(option);12};...

Full Screen

Full Screen

given.js

Source:given.js Github

copy

Full Screen

1import { Given } from 'cucumber';2import launchBrowser from '../support/action/launchBrowser';3Given(4 /^I launch "([^"]*)?" browser$/,5 launchBrowser...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2(async () => {3 const browser = await playwright.launchBrowser();4 const page = await browser.newPage();5 await page.screenshot({ path: 'screenshot.png' });6 await browser.close();7})();8const browserServer = require('./browserServer');9exports.launchBrowser = browserServer.launchBrowser;10exports.launchBrowser = async function() {11 const browser = await chromium.launch();12 return browser;13};14const playwright = require('playwright/lib/server/playwright');15const browser = await playwright.chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright-internal');2playwright.launchBrowser({headless: false});3const playwright = require('playwright');4playwright.launchBrowser({headless: false});5const playwright = require('playwright-internal');6const browser = await playwright.launchBrowser({headless: false});7const context = await browser.newContext();8const page = await context.newPage();9#### browser.close()10#### browser.newContext([options])11#### browser.version()12#### browserContext.close()13#### browserContext.clearCookies()14#### browserContext.clearPermissions()15#### browserContext.overridePermissions(origin, permissions)16#### browserContext.newPage()17#### browserContext.cookies([urls])18#### browserContext.addCookies(cookies)19#### browserContext.clearCookies()20#### browserContext.setGeolocation(geolocation)21#### browserContext.setOffline(offline)22#### browserContext.setHTTPCredentials(httpCredentials)23#### browserContext.setExtraHTTPHeaders(headers)24#### browserContext.addInitScript(source[, arg])

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2(async () => {3 const browser = await playwright.launchBrowser({4 });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: 'google.png' });8 await browser.close();9})();10const playwright = require('playwright');11(async () => {12 const browser = await playwright.launchBrowser({13 });14 const context = await browser.newContext();15 const page = await context.newPage();16 await page.screenshot({ path: 'google.png' });17 await browser.close();18})();19const playwright = require('playwright');20(async () => {21 const browser = await playwright.launchBrowser({22 });23 const context = await browser.newContext();24 const page = await context.newPage();25 await page.screenshot({ path: 'google.png' });26 await browser.close();27})();28const playwright = require('playwright');29(async () => {30 const browser = await playwright.launchBrowser({31 });32 const context = await browser.newContext();33 const page = await context.newPage();34 await page.screenshot({ path: 'google.png' });35 await browser.close();36})();37const playwright = require('playwright');38(async () => {39 const browser = await playwright.launchBrowser({40 });41 const context = await browser.newContext();42 const page = await context.newPage();43 await page.screenshot({ path: 'google

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launchBrowser } = require('playwright-internal');2const browser = await launchBrowser({ headless: false });3const context = await browser.newContext();4const page = await context.newPage();5const { launchBrowser } = require('playwright-internal');6const browser = await launchBrowser({ headless: false });7const context = await browser.newContext();8const page = await context.newPage();9const { launchBrowser } = require('playwright-internal');10const browser = await launchBrowser({ headless: false });11const context = await browser.newContext();12const page = await context.newPage();13const { launchBrowser } = require('playwright-internal');14const browser = await launchBrowser({ headless: false });15const context = await browser.newContext();16const page = await context.newPage();17const { launchBrowser } = require('playwright-internal');18const browser = await launchBrowser({ headless: false });19const context = await browser.newContext();20const page = await context.newPage();21const { launchBrowser } = require('playwright-internal');22const browser = await launchBrowser({ headless: false });23const context = await browser.newContext();24const page = await context.newPage();25const { launchBrowser } = require('playwright-internal');26const browser = await launchBrowser({ headless: false });27const context = await browser.newContext();28const page = await context.newPage();29const { launchBrowser } = require('playwright-internal');30const browser = await launchBrowser({ headless: false });31const context = await browser.newContext();32const page = await context.newPage();33const { launchBrowser } = require('playwright-internal');34const browser = await launchBrowser({ headless: false });35const context = await browser.newContext();36const page = await context.newPage();37const { launchBrowser } = require('playwright-

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2(async () => {3 const browser = await playwright.launchBrowser();4 console.log(browser);5})();6const playwright = require('playwright');7(async () => {8 const browser = await playwright.launchBrowser();9 console.log(browser);10})();11const playwright = require('playwright');12(async () => {13 const browser = await playwright.launchBrowser();14 console.log(browser);15})();16const playwright = require('playwright');17(async () => {18 const browser = await playwright.launchBrowser();19 console.log(browser);20})();21const playwright = require('playwright');22(async () => {23 const browser = await playwright.launchBrowser();24 console.log(browser);25})();26const playwright = require('playwright');27(async () => {28 const browser = await playwright.launchBrowser();29 console.log(browser);30})();31const playwright = require('playwright');32(async () => {33 const browser = await playwright.launchBrowser();34 console.log(browser);35})();36const playwright = require('playwright');37(async () => {38 const browser = await playwright.launchBrowser();39 console.log(browser);40})();41const playwright = require('playwright');42(async () => {43 const browser = await playwright.launchBrowser();44 console.log(browser);45})();46const playwright = require('playwright');47(async () => {48 const browser = await playwright.launchBrowser();49 console.log(browser);50})();51const playwright = require('playwright');52(async () => {53 const browser = await playwright.launchBrowser();54 console.log(browser);55})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const browser = await playwright.launchBrowser({3});4const context = await browser.newContext();5const page = await context.newPage();6await page.screenshot({ path: `example.png` });7await browser.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launchBrowser } = require('@playwright/test/lib/server/playwright');2const browserServer = await launchBrowser({3});4const browser = await browserServer.connect();5const context = await browser.newContext();6const page = await context.newPage();7await page.screenshot({ path: 'google.png' });8await browser.close();9await browserServer.close();10 at async Playwright._launchServer (/home/runner/work/PlaywrightTest/PlaywrightTest/node_modules/playwright-core/lib/cjs/server/playwright.js:39:9)11 at async Playwright.launch (/home/runner/work/PlaywrightTest/PlaywrightTest/node_modules/playwright-core/lib/cjs/server/playwright.js:33:9)

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2(async () => {3 const browser = await playwright.launchBrowser();4 const page = await browser.newPage();5 await browser.close();6})();7const browser = await playwright.launchBrowser(options);

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('@playwright/test');2const { launchBrowser } = require('@playwright/test/lib/server/browserType');3const browser = await launchBrowser({4});5const playwright = require('@playwright/test');6const { launchBrowser } = require('@playwright/test/lib/server/browserType');7playwright.use({8 async launchBrowser(options) {9 return launchBrowser({10 });11 },12});

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