Best JavaScript code snippet using playwright-internal
gulpfile.js
Source:gulpfile.js
1'use strict';2var _ = require( 'lodash' );3var path = require( 'path' );4var fs = require( 'fs' );5var del = require( 'del' );6var argv = require( 'yargs' ).argv;7var gulp = require( 'gulp' );8var gulpif = require( 'gulp-if' );9var gutil = require( 'gulp-util' );10var gzip = require( 'gulp-gzip' );11var connect = require( 'gulp-connect' );12var awspublish = require( 'gulp-awspublish' );13var through2 = require( 'through2' );14var cloudfront = require( 'cloudfront' );15var concat = require( 'gulp-concat' );16var minifyCss = require( 'gulp-minify-css' );17var gulpSwig = require( 'gulp-swig' );18var data = require( 'gulp-data' );19var embedlr = require( 'gulp-embedlr' );20var livereload = require( 'gulp-livereload' );21var minifyHtml = require( 'gulp-minify-html' );22var rev = require( 'gulp-rev' );23var streamify = require( 'gulp-streamify' );24var imagemin = require( 'gulp-imagemin' );25var rename = require( 'gulp-rename' );26var filter = require( 'gulp-filter' );27var listen = require( 'listen' );28var traverse = require( 'traverse' );29var swig = require( 'swig' );30var cssurl = require( 'cssurl' );31var hash = require( 'object-hash' );32var browserify = require( 'browserify' );33var exorcist = require( 'exorcist' );34var watchify = require( 'watchify' );35var source = require( 'vinyl-source-stream' );36var concatStream = require( 'concat-stream' );37var isDev = false;38var isStage = false;39var isProd = false;40var manifest;41var content;42var distDir = './dist';43var buildManifest = 'build.manifest.json';44var manifestFilepath = path.resolve( __dirname, buildManifest );45var markupRoot = './src/html/';46var markupPages = markupRoot + 'pages/';47var markupWatch = [ markupRoot + '**/*.html', 'node_modules/djed/marketing/components/**/*.html', './content.js', 'config.dev.js' ];48var markupSrc = [ markupPages + '**/*.html' ];49var bundleConfig = require( './bundle.config.js' );50var srcBase = path.resolve( __dirname, 'src' );51var cssSrc = [ './src/**/*.css', './node_modules/ladda/dist/ladda.min.css' ];52var staticSrc = [ './src/img/**/*', './src/fonts/**/*' ];53var outputCSSFilepath = 'styles.css';54var devConfig = require( './config.dev.js' );55var stageConfig = require( './config.stage.js' );56var prodConfig = require( './config.prod.js' );57var isDeployable = function () {58 return isStage || isProd;59};60var swapAssets = function ( manifest, content ) {61 traverse( content ).forEach( function ( val ) {62 var url;63 if ( _.isString( val ) && val.indexOf( '/' ) === 0 ) {64 url = manifest[ val.substring( 1 ) ];65 if ( url ) {66 this.update( '/' + url.replace( '.gz', '' ) );67 }68 }69 } );70};71var getDeployData = function () {72 var genDeployData = function ( config ) {73 var accessKey = process.env[ config.accessKeyName ];74 var secretKey = process.env[ config.secretKeyName ];75 var distributionId = process.env[ config.distributionId ];76 if ( !accessKey || !secretKey ) {77 throw new gutil.PluginError( 'deploy', 'AWS environment variables not set for deploy.' );78 }79 return {80 key: accessKey,81 secret: secretKey,82 bucket: config.bucket,83 style: 'path',84 distributionId: distributionId85 };86 };87 if ( isProd ) {88 return genDeployData( prodConfig.deploy );89 } else if ( isStage ) {90 return genDeployData( stageConfig.deploy );91 }92};93var getPageData = function ( vinyl ) {94 var data = {};95 var pageContent = {};96 var pageConfig = _.find( content.pages, function ( page ) {97 return vinyl.path === path.resolve( __dirname, page.template );98 } );99 if ( pageConfig ) {100 pageContent.useAppCache = pageConfig.useAppCache;101 pageContent.content = content.stories[ pageConfig.story ];102 pageContent.story = pageConfig.story;103 pageContent.stories = _.map( pageConfig.stories, function ( key ) {104 return _.extend( {105 id: key106 }, content.stories[ key ] );107 } );108 }109 if ( isProd ) {110 data.page = prodConfig.page;111 } else if ( isStage ) {112 data.page = stageConfig.page;113 } else {114 data.page = devConfig.page;115 }116 data.page.isDeploying = isDeployable();117 _.extend( data, pageContent );118 return data;119};120var bundleError = _.template(121 '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' +122 'PARSE ERROR in\n' +123 '<%= filename %>\n' +124 'on line <%= lineNumber %> at column <%= column %>\n\n' +125 '<%= description %>' +126 '\n¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡' );127var logBundleError = function ( err ) {128 try {129 gutil.log( gutil.colors.red( bundleError( err ) ) );130 } catch ( e ) {131 gutil.log( gutil.colors.red( err.toString() ) );132 }133};134var writeJS = function ( doWatch, doneListener ) {135 return function ( bundlerConfig ) {136 var bundleStream = bundlerConfig.bundler137 .bundle()138 .on( 'error', function ( err ) {139 logBundleError( err );140 this.end();141 } )142 .pipe(143 exorcist(144 './dist/' + bundlerConfig.config.output + '.map',145 '/' + bundlerConfig.config.output + '.map' )146 ) // (file, url)147 .pipe( source( bundlerConfig.config.output ) )148 .pipe( streamify( rev( isDeployable() ) ) )149 .pipe( gulpif( isDeployable(), gzip( {150 gzippedOnly: true151 } ) ) )152 .pipe( gulp.dest( distDir ) )153 .pipe( rev.manifest( manifestFilepath, {154 merge: true,155 } ) )156 .pipe( gulp.dest( __dirname ) );157 if ( doneListener ) {158 bundleStream.on( 'end', doneListener() );159 }160 if ( doWatch ) {161 bundleStream.on( 'end', function () {162 livereload.changed( bundlerConfig.config.output );163 } );164 }165 };166};167var toArrayOfDependentModules = function ( bundleConfig ) {168 return function ( memo, key ) {169 return memo.concat( bundleConfig[ key ].modules );170 };171};172var getDependentBundleExternals = function ( bundleConfig, moduleKey ) {173 return _( bundleConfig[ moduleKey ].deps || [] )174 .reduce( toArrayOfDependentModules( bundleConfig ), [] );175};176var entryModules = function ( config ) {177 return _.intersection( config.modules, config.entryModules );178};179var nonEntryModules = function ( config ) {180 return _.difference( config.modules, config.entryModules );181};182var toConfigureBundler = function ( bundleConfig, doWatch ) {183 return function ( config, key ) {184 var bundler, bundlerOutput, entry;185 var opts = ( doWatch ? config.options : config.prodOptions ) || {};186 var entryOpts = {187 entry: true188 };189 // entry option only applies on entry bundles190 var requireOpts = config.isEntry && entryOpts;191 if ( doWatch ) {192 // add necessary options for watchify193 _( opts ).defaults( {194 cache: {},195 packageCache: {}196 } );197 }198 // init bundler199 bundler = browserify( opts );200 // apply the transforms201 _( config.transforms ).each( function ( transformArgs ) {202 bundler.transform.apply( bundler, transformArgs );203 } );204 // apply the plugins205 _( config.plugins ).each( function ( pluginArgs ) {206 bundler.plugin.apply( bundler, pluginArgs );207 } );208 // define the externals209 bundler.external( getDependentBundleExternals( bundleConfig, key ) );210 // define excludes if set211 _( config.exclude ).each( function ( module ) {212 bundler.exclude( module );213 } );214 // require entry modules215 entry = entryModules( config );216 if ( entry.length ) {217 bundler.require( entry, entryOpts );218 }219 // require non-entry modules220 bundler.require( nonEntryModules( config ), requireOpts );221 // define output config222 bundlerOutput = {223 config: config,224 bundler: bundler225 };226 // add watchify event handler, if flag passed227 if ( doWatch ) {228 bundler = watchify( bundler );229 bundler.on( 'update', function () {230 writeJS( doWatch )( bundlerOutput );231 } );232 } else {233 // apply the prodTransforms234 _( config.prodTransforms ).each( function ( transformArgs ) {235 bundler.transform.apply( bundler, transformArgs );236 } );237 }238 return bundlerOutput;239 };240};241var bundleJS = function ( bundleConfig, doWatch, doneListener ) {242 _( bundleConfig )243 .map( toConfigureBundler( bundleConfig, doWatch ) )244 .each( writeJS( doWatch, doneListener ) );245};246var buildMarkup = function ( done ) {247 try {248 manifest = JSON.parse( fs.readFileSync( buildManifest, 'utf8' ) );249 } catch ( e ) {250 manifest = {};251 }252 delete require.cache[ path.resolve( process.cwd(), 'content.js' ) ];253 content = require( './content.js' );254 if ( isDeployable() ) {255 swapAssets( manifest, content );256 }257 gulp.src( markupSrc, {258 base: markupPages259 } )260 .pipe( data( getPageData ) )261 .pipe( gulpSwig( {262 defaults: {263 cache: false264 },265 setup: function ( swig ) {266 swig.setFilter( 'static', function ( input ) {267 var key = input.indexOf( '/' ) === 0 ? input.substring( 1 ) : input;268 var entry = manifest[ key ];269 var manifestEntry = entry && entry.replace( '.gz', '' );270 return manifestEntry ? '/' + manifestEntry : input;271 } );272 swig.setDefaults( {273 loader: {274 resolve: function ( to ) {275 var p = path.resolve( __dirname, to );276 return p;277 },278 load: function ( identifier ) {279 return fs.readFileSync( identifier, {280 encoding: 'utf-8'281 } );282 }283 }284 } );285 }286 } ) )287 .pipe( gulpif( isDev, embedlr() ) )288 .pipe( minifyHtml() )289 .pipe( gulpif( isDeployable(), gzip( {290 gzippedOnly: true291 } ) ) )292 .pipe( gulp.dest( distDir ) )293 .pipe( livereload() )294 .on( 'end', function () {295 // write manifest296 var manifestTpl = swig.compileFile( './app.manifest.tpl' );297 var manifestFilepath = path.resolve( distDir, 'app.manifest' );298 var files = _.values( manifest ).map( function ( file ) {299 return file.replace( '.gz', '' );300 } );301 var h = hash( JSON.stringify( files ) + _.random( 0, 10000 ) );302 var content = manifestTpl( {303 files: files,304 hash: h305 } );306 fs.writeFileSync( manifestFilepath, content );307 // replace urls in css308 var rewriter = new cssurl.URLRewriter( function ( url ) {309 var relativeUrl = url.substring( 1 );310 var versionedUrl = manifest[ relativeUrl ];311 return versionedUrl ? '/' + versionedUrl.replace( '.gz', '' ) : url;312 } );313 var cssFilepath = path.resolve( distDir, manifest[ outputCSSFilepath ] );314 var css = fs.readFileSync( cssFilepath, 'utf8' );315 var newCss = rewriter.rewrite( css );316 fs.writeFileSync( cssFilepath, newCss );317 // gzip 'em318 gulp.src( [ cssFilepath, manifestFilepath ] )319 .pipe( gulpif( isDeployable(), gzip( {320 gzippedOnly: true321 } ) ) )322 .pipe( gulp.dest( distDir ) )323 .on( 'end', done );324 } );325};326gulp.task( 'default', [ 'dev' ] );327gulp.task( 'dev', [ 'set-dev-flag', 'clean', 'webserver', 'livereload', 'watch-js', 'watch-css', 'watch-static', 'watch-markup' ] );328gulp.task( 'deploy', [ 'set-env-flag', 'build' ], function () {329 var config = getDeployData();330 var publisher = awspublish.create( config );331 var gzipFilter = filter( '**/*.gz' );332 var pageFilter = filter( '**/*.html' );333 var cf = cloudfront.createClient( config.key, config.secret );334 return gulp.src( distDir + '/**' )335 .pipe( gzipFilter )336 .pipe( rename( function ( path ) {337 path.extname = '';338 } ) )339 .pipe( publisher.publish( {340 'x-amz-acl': 'private',341 'content-encoding': 'gzip',342 'cache-control': 'max-age=600'343 } ) )344 .pipe( publisher.cache() )345 .pipe( awspublish.reporter() )346 .pipe( pageFilter )347 .pipe( through2.obj( function ( vinyl, enc, callback ) {348 this.push( {349 path: '/' + path.relative( distDir, vinyl.path )350 } );351 callback();352 } ) )353 .pipe( concatStream( function ( paths ) {354 var cachedPaths = _.pluck( paths, 'path' );355 cf.createInvalidation( config.distributionId, _.random( 0, 10000000 ), cachedPaths, function ( err, invalidation ) {356 if ( err ) {357 gutil.log( 'Could not invalidate ' + cachedPaths.join( ', ' ) );358 } else {359 gutil.log( 'Invalidation success for ' + invalidation.paths.join( ', ' ) );360 }361 } );362 } ) );363} );364gulp.task( 'build', [ 'clean', 'build-js', 'build-css', 'build-static' ], function ( done ) {365 buildMarkup( done );366} );367gulp.task( 'build-markup', function ( done ) {368 buildMarkup( done );369} );370gulp.task( 'build-js', function ( done ) {371 var listener = listen();372 bundleJS( bundleConfig.toBrowserify, false, listener );373 listener.then( done );374} );375gulp.task( 'build-css', function () {376 return gulp.src( cssSrc, {377 base: srcBase378 } )379 .pipe( concat( outputCSSFilepath ) )380 .pipe( minifyCss() )381 .pipe( rev( isDeployable() ) )382 .pipe( gulp.dest( distDir ) )383 .pipe( livereload() )384 .pipe( rev.manifest( manifestFilepath, {385 merge: true,386 } ) )387 .pipe( gulp.dest( __dirname ) );388} );389gulp.task( 'build-static', function () {390 return gulp.src( staticSrc, {391 base: srcBase392 } )393 .pipe( rev( isDeployable() ) )394 .pipe( imagemin() )395 .pipe( gulpif( isDeployable(), gzip( {396 gzippedOnly: true397 } ) ) )398 .pipe( gulp.dest( distDir ) )399 .pipe( livereload() )400 .pipe( rev.manifest( manifestFilepath, {401 merge: true402 } ) )403 .pipe( gulp.dest( __dirname ) );404} );405gulp.task( 'watch-js', function () {406 bundleJS( bundleConfig.toBrowserify, true );407} );408gulp.task( 'watch-markup', [ 'build-markup' ], function () {409 gulp.watch( markupWatch, [ 'build-markup' ] );410} );411gulp.task( 'watch-css', [ 'build-css' ], function () {412 gulp.watch( cssSrc, [ 'build-css' ] );413} );414gulp.task( 'watch-static', [ 'build-static' ], function () {415 gulp.watch( staticSrc, [ 'build-static' ] );416} );417gulp.task( 'clean', function ( done ) {418 del( './dist', function () {419 fs.mkdir( './dist', function () {420 done();421 } );422 } );423} );424gulp.task( 'webserver', function () {425 connect.server( {426 root: distDir,427 port: 10000428 } );429} );430gulp.task( 'livereload', function () {431 livereload.listen( {432 quiet: true433 } );434} );435gulp.task( 'set-dev-flag', function () {436 isDev = true;437} );438gulp.task( 'set-env-flag', function () {439 if ( argv.staging ) {440 isStage = true;441 } else if ( argv.production ) {442 isProd = true;443 } else {444 throw new gutil.PluginError( 'deploy', 'To deploy, you must set either a --staging or --production flag. `gulp deploy --staging`' );445 }...
sseClient.js
Source:sseClient.js
...30 this.eventApi = apiBase + "/watch/";31 }32 connect() {33 if (!this.connected) {34 Object.keys(this.pending).forEach(id => this.doWatch(id, this.pending[id]));35 this.pending = {};36 }37 this.connected = true;38 }39 disconnect() {40 console.log("SSE disconnect");41 Object.keys(this.watches).forEach(id => {42 const sub = this.watches[id];43 if (sub) {44 sub.eventSource.close();45 }46 });47 this.watches = {};48 this.monitors = {};49 this.connected = false;50 }51 monitor(resource, handler) {52 this.monitors[resource] = handler;53 return this.lastMsg[resource];54 }55 unmonitor(resource) {56 const monitor = this.monitors[resource];57 if (monitor) {58 monitor(null);59 }60 }61 doWatch(id, watch) {62 const {resource, filter, handler} = watch;63 console.log("SSE watch", {resource, filter});64 const qFilter = encodeURIComponent(JSON.stringify(filter));65 const url = this.eventApi + resource + '?filter=' + qFilter + '&window=' + this.windowId;66 const eventSource = new EventSource(url, {withCredentials: true});67 watch.eventSource = eventSource;68 this.watches[id] = watch;69 eventSource.addEventListener("watch", evt => {70 // only receives messages with specified type71 const msg = JSON.parse(evt.data);72 const handled = handler(msg);73 this.lastMsg[resource] = msg;74 const monitor = this.monitors[resource];75 if (!handled && monitor) {76 monitor(msg);77 }78 });79 // evtSource.onopen = e => {80 // console.log("XXX open event", e);81 // };82 //83 // evtSource.onerror = e => {84 // console.log("XXX error event", e);85 // };86 //87 // evtSource.onmessage = e => {88 // // only receives messages with no type89 // console.log("XXX message event", e);90 // };91 }92 watch = (resource, filter, handler) => {93 const id = this.subId++;94 const watch = {resource, filter, handler};95 if (this.connected) {96 this.doWatch(id, watch);97 } else {98 this.pending[id] = watch;99 }100 return id;101 }102 unwatch = (id) => {103 const watch = this.watches[id];104 if (watch) {105 console.log("SSE unwatch", {id, ...watch});106 watch.eventSource.close();107 delete this.watches[id];108 return true;109 }110 return false;...
mapTiles.client.service.js
Source:mapTiles.client.service.js
1(function() {2 'use strict';3 var module = angular.module('map');4 /**5 * @name wdTiles6 * @memberOf angularModule.map7 * @description8 * Serves map tiles9 */10 module.service('mapTiles', function(Restangular,$log) {11 var self = this;12 // Default layer if the server does not work somehow.13 this.baseLayers = [ {14 name : "osm",15 url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",16 type : "xyz",17 layerOptions: { attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'18 }}];19 this.defaultLayer = this.baseLayers[0];20 Restangular.all('tiles').getList({size:100,active:true,orderBy:"-modified"}).then(function(layers) {21 $log.debug("[mapTiles:getList] results:");22 _.assignDelete(self.baseLayers, _.cloneDeep(layers));23 //self.defaultLayer = self.baseLayers[0];24 });25 this.settings = {26 center: {27 lat: 46.78,28 lng: 9.9,29 zoom:13,30 autoDiscover: true31 },32 defaults: {33 scrollWheelZoom: true,34 doubleClickZoom: false,35 maxZoom : 16,36 worldCopyJump : true,37 touchZoom : true,38 dragging: true,39 tap : true,40 map: {41 editable : true42 } 43 //zoomControl : false44 },45 events: {46 map: {47 enable: ['dblclick'],48 logic: 'emit'49 },50 markers: {51 enable: [],52 logic: 'emit'53 }54 },55 watchOptions: {56 markers: {57 // changes in master58 // new match-options59 // old markers-watch-options60 type: 'watchCollection', // new61 doWatch: true, //old62 isDeep: true, //old63 individual: {64 type: null,//'watch'65 doWatch: false, //old66 isDeep: false //old67 }68 },69 paths: {70 type: null,71 doWatch : false,72 isDeep: false,73 individual: {74 type: null,75 doWatch: false, //old76 isDeep: false //old77 }78 }79 },80 //tiles: tilesDict.OfflineHike,81 layers: {82 baselayers: self.baseLayers83 }84 }85 /// END86 });...
controller.js
Source:controller.js
...36 () => { },37 e => {38 log(`Watch Shutdown ${e ? e : ''}`);39 clearTimeout(timeout);40 doWatch();41 }42 );43 timeout = setTimeout(() => {44 log('!!! Manually aborting watch !!!!!');45 watchRequest.abort();46 doWatch();47 }, 8 * 60 * 1000); // if we get to 8 minutes we need to kill it and restart something didn't close correctly48 setTimeout(async () => {49 log(`Patching ${pod}`);50 await k8Core.patchNamespacedPod(pod, 'default',51 [52 {53 op : 'replace',54 path : '/metadata/labels/change',55 value: (change += 1).toString()56 }57 ],58 undefined, undefined, undefined, undefined,59 { headers: { 'Content-Type': 'application/json-patch+json' } }60 );61 }, 2 * 1000); // 2 seconds62};63const delay = t => new Promise(resolve => setTimeout(resolve, t));64const start = async () => {65 await delay(1000);66 startTime = new Date();67 await doWatch();68};...
copy.js
Source:copy.js
1import path from 'path';2import watch from 'gulp-watch';3function fonts(gulp, settings) {4 const fontsSrc = path.resolve(__dirname, '..', settings.build.paths.source.fonts, '**/*');5 const fontsDest = path.resolve(__dirname, '..', settings.main.destination, settings.build.paths.destination.fonts);6 const copyFonts = function (doWatch) {7 if (!settings.build.paths.source.fonts || !settings.build.paths.destination.fonts) {8 return Promise.resolve(null);9 }10 let chain = gulp.src(fontsSrc);11 if (doWatch) {12 chain = chain.pipe(watch(fontsSrc));13 }14 chain.pipe(gulp.dest(fontsDest));15 if (!doWatch) {16 return new Promise((resolve) => {17 chain.on('end', resolve);18 });19 }20 return Promise.resolve(null);21 };22 gulp.task('fonts', () => copyFonts(false));23 gulp.task('fonts-watch', () => copyFonts(true));24}25function images(gulp, settings) {26 const imagesSrc = path.resolve(__dirname, '..', settings.build.paths.source.images, '**/*');27 const imagesDest = path.resolve(__dirname, '..', settings.main.destination, settings.build.paths.destination.images);28 const copyImages = function (doWatch) {29 if (!settings.build.paths.source.images || !settings.build.paths.destination.images) {30 return Promise.resolve(null);31 }32 let chain = gulp.src(imagesSrc);33 if (doWatch) {34 chain = chain.pipe(watch(imagesSrc));35 }36 chain.pipe(gulp.dest(imagesDest));37 if (!doWatch) {38 return new Promise((resolve) => {39 chain.on('end', resolve);40 });41 }42 return Promise.resolve(null);43 };44 gulp.task('images', () => copyImages(false));45 gulp.task('images-watch', () => copyImages(true));46}47export default function (gulp, settings) {48 fonts(gulp, settings);49 images(gulp, settings);50 return null;...
dev-server.js
Source:dev-server.js
...30 return false;31 }32 }33 let backoff = 0;34 function doWatch() {35 try {36 let watcher = fs.watch('spasm-imgui', (event, filename)=>{37 if (event == 'change')38 notifyClients();39 else if (event == 'rename') {40 if (exists('spasm-material')) {41 notifyClients();42 } else {43 watcher.close();44 backoff = 100;45 setTimeout(doWatch, backoff);46 }47 }48 });49 if (backoff != 0) {50 notifyClients();51 backoff = 0;52 }53 } catch (e) {54 backoff = Math.min(backoff * 2, 60000);55 setTimeout(doWatch, backoff);56 }57 }58 doWatch();...
index.js
Source:index.js
...17 response.send("ok");18 });19});20exports.doWatch = functions.https.onRequest((request, response) => {21 return doWatch().then(() => {22 response.send("ok");23 });24});25process.on('unhandledRejection', (reason, p) => {26 console.error('Unhandled Rejection at: Promise', p);27 console.error('Unhandled Rejection at: Reason', reason);28 // application specific logging, throwing an error, or other logic here...
userbar.js
Source:userbar.js
...20 }21 })22 return false23 }24 $('a[href*="furaffinity.net/unwatch"]').on("click",function(){return doWatch(this,"Unwatched!")})25 $('a[href*="furaffinity.net/watch"]').on("click",function(){return doWatch(this,"Watched!")})...
Using AI Code Generation
1const { doWatch } = require('playwright/lib/server/browserContext');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.fill('input[aria-label="Search"]', 'Hello');8 await page.keyboard.press('Enter');9 await doWatch(page, 'test', { timeout: 10000 });10 await browser.close();11})();12- [Playwright Internal API](
Using AI Code Generation
1const { doWatch } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');2const { chromium } = require('playwright-core');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await doWatch(page);8})();
Using AI Code Generation
1const { doWatch } = require('playwright/lib/server/browserContext');2const fs = require('fs');3const { chromium } = require('playwright');4const path = require('path');5const { promisify } = require('util');6const writeFile = promisify(fs.writeFile);7(async () => {8 const browser = await chromium.launch();9 const context = await browser.newContext();10 await doWatch.call(context, path.join(__dirname, 'test.html'), async () => {11 const page = await context.newPage();12 await page.waitForSelector('text=Hello world!');13 await writeFile(path.join(__dirname, 'test.html'), '<h1>Hello world!</h1>');14 });15 await browser.close();16})();17### `doWatch(fileOrDirectory, callback, options)`18[Apache 2.0](LICENSE)
Using AI Code Generation
1const { doWatch } = require('@playwright/test/lib/test');2const { test } = require('@playwright/test');3test.describe('Test', () => {4 test('My Test', async ({ page }) => {5 await doWatch('**/*.js', async () => {6 });7 });8});9### `doWatch(glob, callback)`10const { doWatch } = require('@playwright/test/lib/test');11const { test } = require('@playwright/test');12test.describe('Test', () => {13 test('My Test', async ({ page }) => {14 await doWatch('test.spec.js', async () => {15 });16 });17});18const { doWatch } = require('@playwright/test/lib/test');19const { test } = require('@playwright/test');20test.describe('Test', () => {21 test('My Test', async ({ page }) => {22 await doWatch('*.spec.js', async () => {23 });24 });25});26const { doWatch } = require('@playwright/test/lib/test');27const { test } = require('@playwright/test');28test.describe('Test', () => {29 test('My Test', async ({ page }) => {30 await doWatch('tests/*.spec.js', async () => {31 });32 });33});34const { doWatch } = require('@playwright/test/lib/test');35const { test } = require('@playwright/test');36test.describe('Test', () => {37 test('My Test', async ({ page }) => {38 await doWatch('tests/**/*.spec.js', async () => {
Using AI Code Generation
1const { doWatch } = require('@playwright/test/lib/server/watcher');2doWatch({3 onFileListChanged: (files) => {4 console.log(`Files changed: ${files}`);5 },6 onFileModified: (file) => {7 console.log(`File modified: ${file}`);8 },9 onReady: () => {10 console.log('Ready');11 }12});13### `doWatch(options)`
Using AI Code Generation
1const { doWatch } = require("@playwright/test/lib/utils/testrunner/TestRunner");2doWatch();3test("My First Test", async ({ page }) => {4 await page.screenshot({ path: "screenshot.png" });5});6module.exports = {7};8test("My First Test", async ({ page }) => {9 await page.screenshot({ path: "screenshot.png" });10});
Using AI Code Generation
1const { doWatch } = require('@playwright/test/lib/test');2const { test } = require('@playwright/test');3test.only('test', async ({ page }) => {4});5test.skip('test', async ({ page }) => {6});7test('test', async ({ page }) => {8});9const { test } = require('@playwright/test');10test.fixme('test', async ({ page }) => {11});12const { test } = require('@playwright/test');13test.describe('test', () => {14 test('test1', async ({ page }) => {15 });16 test('test2', async ({ page }) => {17 });18});19const { test } = require('@playwright/test');20test.describe.each([
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2const fs = require('fs');3const path = require('path');4const { doWatch } = require('@playwright/test/lib/test');5test('test', async ({ page }) => {6 doWatch([7 path.join(__dirname, 'test.js'),8 path.join(__dirname, 'test2.js'),9 ]);10 const title = page.locator('text=Playwright');11 expect(await title.isVisible()).toBe(true);12});
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!!