How to use spawnAsync method in Playwright Internal

Best JavaScript code snippet using playwright-internal

android-shell-app.js

Source:android-shell-app.js Github

copy

Full Screen

...15} = ExponentTools;16async function sedInPlaceAsync(...args) {17 const isDarwin = /^darwin/.test(process.platform);18 if (isDarwin) {19 await spawnAsync(`sed`, ['-i', `''`, ...args]);20 } else {21 await spawnAsync(`sed`, ['-i', ...args]);22 }23}24exports.createAndroidShellAppAsync = async function createAndroidShellAppAsync(25 args26) {27 let {28 url,29 sdkVersion,30 androidPackage,31 privateConfigFile,32 keystore,33 alias,34 keystorePassword,35 keyPassword,36 outputFile,37 } = args;38 let manifest = await getManifestAsync(url, {39 'Exponent-SDK-Version': sdkVersion,40 'Exponent-Platform': 'android',41 });42 if (!privateConfigFile) {43 crayon.yellow.warn('Warning: No config file specified.');44 }45 let fullManifestUrl = `${url.replace('exp://', 'https://')}/index.exp`;46 let javaPackage;47 let versionCode = 1;48 if (!manifest.android) {49 javaPackage = androidPackage;50 } else {51 javaPackage = manifest.android.package || androidPackage;52 if (manifest.android.versionCode) {53 versionCode = manifest.android.versionCode;54 }55 }56 if (!javaPackage) {57 throw new Error(58 'Must specify androidPackage option (either from manifest or on command line).'59 );60 }61 let name = manifest.name;62 let iconUrl = manifest.android && manifest.android.iconUrl63 ? manifest.android.iconUrl64 : manifest.iconUrl;65 let scheme = manifest.scheme;66 let bundleUrl = manifest.bundleUrl;67 let notificationIconUrl = manifest.notification68 ? manifest.notification.iconUrl69 : null;70 let version = manifest.version ? manifest.version : '0.0.0';71 let shellPath = '../android-shell-app/';72 await spawnAsync(`/bin/rm`, ['-rf', shellPath]);73 await spawnAsync(`/bin/mkdir`, [shellPath]);74 await spawnAsync(75 `../../tools-public/generate-dynamic-macros-android.sh`,76 [],77 {78 stdio: 'inherit',79 cwd: path.join(__dirname, '..', 'android', 'app'),80 }81 ); // populate android template files now since we take out the prebuild step later on82 await spawnAsync(`/bin/cp`, [83 '-r',84 '../android/expoview',85 `${shellPath}/expoview`,86 ]);87 await spawnAsync(`/bin/cp`, [88 '-r',89 '../android/ReactCommon',90 `${shellPath}/ReactCommon`,91 ]);92 await spawnAsync(`/bin/cp`, [93 '-r',94 '../android/ReactAndroid',95 `${shellPath}/ReactAndroid`,96 ]);97 await spawnAsync(`/bin/cp`, ['../android/android.iml', `${shellPath}/`]);98 await spawnAsync(`/bin/cp`, ['-r', '../android/app', `${shellPath}/app`]);99 await spawnAsync(`/bin/cp`, ['../android/build.gradle', `${shellPath}/`]);100 await spawnAsync(`/bin/cp`, [101 '-r',102 '../android/gradle',103 `${shellPath}/gradle`,104 ]);105 await spawnAsync(`/bin/cp`, [106 '../android/gradle.properties',107 `${shellPath}/`,108 ]);109 await spawnAsync(`/bin/cp`, ['../android/gradlew', `${shellPath}/`]);110 await spawnAsync(`/bin/cp`, ['../android/local.properties', `${shellPath}/`]);111 await spawnAsync(`/bin/cp`, ['../android/settings.gradle', `${shellPath}/`]);112 // Clean build directories113 await spawnAsync(`/bin/rm`, ['-rf', `${shellPath}app/build/`]);114 // Package115 shell.sed(116 '-i',117 `applicationId 'host.exp.exponent'`,118 `applicationId '${javaPackage}'`,119 `${shellPath}app/build.gradle`120 );121 await sedInPlaceAsync(122 '-e',123 `s/android:name="host.exp.exponent"/android:name="${javaPackage}"/g`,124 `${shellPath}app/src/main/AndroidManifest.xml`125 );126 // Versions127 let buildGradleFile = await fs.promise.readFile(128 `${shellPath}app/build.gradle`,129 'utf8'130 );131 let androidVersion = buildGradleFile.match(/versionName '(\S+)'/)[1];132 shell.sed(133 '-i',134 'VERSION_NAME = null',135 `VERSION_NAME = "${androidVersion}"`,136 `${shellPath}expoview/src/main/java/host/exp/exponent/Constants.java`137 );138 await sedInPlaceAsync(139 '-e',140 `/BEGIN\ VERSIONS/,/END\ VERSIONS/d`,141 `${shellPath}app/build.gradle`142 );143 shell.sed(144 '-i',145 '// ADD VERSIONS HERE',146 `versionCode ${versionCode}147 versionName '${version}'`,148 `${shellPath}app/build.gradle`149 );150 // Remove Exponent build script151 shell.sed(152 '-i',153 `preBuild.dependsOn generateDynamicMacros`,154 ``,155 `${shellPath}expoview/build.gradle`156 );157 // change javaMaxHeapSize158 shell.sed(159 '-i',160 `javaMaxHeapSize "8g"`,161 `javaMaxHeapSize "6g"`,162 `${shellPath}app/build.gradle`163 );164 // Push notifications165 shell.sed(166 '-i',167 '"package_name": "host.exp.exponent"',168 `"package_name": "${javaPackage}"`,169 `${shellPath}app/google-services.json`170 ); // TODO: actually use the correct file171 // TODO: probably don't need this in both places172 await sedInPlaceAsync(173 '-e',174 `s/host.exp.exponent.permission.C2D_MESSAGE/${javaPackage}.permission.C2D_MESSAGE/g`,175 `${shellPath}app/src/main/AndroidManifest.xml`176 );177 await sedInPlaceAsync(178 '-e',179 `s/host.exp.exponent.permission.C2D_MESSAGE/${javaPackage}.permission.C2D_MESSAGE/g`,180 `${shellPath}expoview/src/main/AndroidManifest.xml`181 );182 // Set INITIAL_URL and SHELL_APP_SCHEME183 shell.sed(184 '-i',185 'INITIAL_URL = null',186 `INITIAL_URL = "${url}"`,187 `${shellPath}expoview/src/main/java/host/exp/exponent/Constants.java`188 );189 if (scheme) {190 shell.sed(191 '-i',192 'SHELL_APP_SCHEME = null',193 `SHELL_APP_SCHEME = "${scheme}"`,194 `${shellPath}expoview/src/main/java/host/exp/exponent/Constants.java`195 );196 }197 // App name198 shell.sed(199 '-i',200 '"app_name">Expo',201 `"app_name">${name}`,202 `${shellPath}app/src/main/res/values/strings.xml`203 );204 // Remove exp:// scheme205 await sedInPlaceAsync(206 '-e',207 `/DELETE\ AFTER/,/DELETE\ BEFORE/d`,208 `${shellPath}app/src/main/AndroidManifest.xml`209 );210 // Add shell app scheme211 if (scheme) {212 shell.sed(213 '-i',214 '<!-- ADD SHELL SCHEME HERE -->',215 `<intent-filter>216 <data android:scheme="${scheme}"/>217 <action android:name="android.intent.action.VIEW"/>218 <category android:name="android.intent.category.DEFAULT"/>219 <category android:name="android.intent.category.BROWSABLE"/>220 </intent-filter>`,221 `${shellPath}app/src/main/AndroidManifest.xml`222 );223 }224 // OAuth redirect scheme225 shell.sed(226 '-i',227 '<data android:scheme="host.exp.exponent" android:path="oauthredirect"/>',228 `<data android:scheme="${javaPackage}" android:path="oauthredirect"/>`,229 `${shellPath}app/src/main/AndroidManifest.xml`230 );231 // Embed manifest and bundle232 await fs.promise.writeFile(233 `${shellPath}app/src/main/assets/shell-app-manifest.json`,234 JSON.stringify(manifest)235 );236 await saveUrlToPathAsync(237 bundleUrl,238 `${shellPath}app/src/main/assets/shell-app.bundle`239 );240 shell.sed(241 '-i',242 '// ADD EMBEDDED RESPONSES HERE',243 `244 embeddedResponses.add(new EmbeddedResponse("${fullManifestUrl}", "assets://shell-app-manifest.json", "application/json"));245 embeddedResponses.add(new EmbeddedResponse("${bundleUrl}", "assets://shell-app.bundle", "application/javascript"));`,246 `${shellPath}expoview/src/main/java/host/exp/exponent/Constants.java`247 );248 // Icon249 if (iconUrl) {250 await spawnAsync(`find`, [251 `${shellPath}app/src/main/res`,252 '-iname',253 'ic_launcher.png',254 '-delete',255 ]);256 await saveUrlToPathAsync(257 iconUrl,258 `${shellPath}app/src/main/res/mipmap-hdpi/ic_launcher.png`259 );260 await spawnAsync(`find`, [261 `${shellPath}expoview/src/main/res`,262 '-iname',263 'ic_launcher.png',264 '-delete',265 ]);266 await saveUrlToPathAsync(267 iconUrl,268 `${shellPath}expoview/src/main/res/mipmap-hdpi/ic_launcher.png`269 );270 }271 if (notificationIconUrl) {272 await spawnAsync(`find`, [273 `${shellPath}app/src/main/res`,274 '-iname',275 'shell_notification_icon.png',276 '-delete',277 ]);278 await saveUrlToPathAsync(279 notificationIconUrl,280 `${shellPath}app/src/main/res/drawable-hdpi/shell_notification_icon.png`281 );282 await spawnAsync(`find`, [283 `${shellPath}expoview/src/main/res`,284 '-iname',285 'shell_notification_icon.png',286 '-delete',287 ]);288 await saveUrlToPathAsync(289 notificationIconUrl,290 `${shellPath}expoview/src/main/res/drawable-hdpi/shell_notification_icon.png`291 );292 }293 let certificateHash = '';294 let googleAndroidApiKey = '';295 if (privateConfigFile) {296 let configJsonFile = new JsonFile(privateConfigFile);297 let branch = await configJsonFile.getAsync('branch', null);298 let fabric = await configJsonFile.getAsync('fabric', null);299 let googleMaps = await configJsonFile.getAsync('googleMaps', null);300 let googleSignIn = await configJsonFile.getAsync('googleSignIn', null);301 // Branch302 if (branch) {303 shell.sed(304 '-i',305 '<!-- ADD BRANCH CONFIG HERE -->',306 `<meta-data307 android:name="io.branch.sdk.BranchKey"308 android:value="${branch.apiKey}"/>`,309 `${shellPath}app/src/main/AndroidManifest.xml`310 );311 }312 // Fabric313 if (fabric) {314 await fs.promise.unlink(`${shellPath}app/fabric.properties`);315 await fs.promise.writeFile(316 `${shellPath}app/fabric.properties`,317 `apiSecret=${fabric.buildSecret}\n`318 );319 await sedInPlaceAsync(320 '-e',321 `/BEGIN\ FABRIC\ CONFIG/,/END\ FABRIC\ CONFIG/d`,322 `${shellPath}app/src/main/AndroidManifest.xml`323 );324 shell.sed(325 '-i',326 '<!-- ADD FABRIC CONFIG HERE -->',327 `<meta-data328 android:name="io.fabric.ApiKey"329 android:value="${fabric.apiKey}"/>`,330 `${shellPath}app/src/main/AndroidManifest.xml`331 );332 }333 // Google Maps334 if (googleMaps) {335 await sedInPlaceAsync(336 '-e',337 `/BEGIN\ GOOGLE\ MAPS\ CONFIG/,/END\ GOOGLE\ MAPS\ CONFIG/d`,338 `${shellPath}app/src/main/AndroidManifest.xml`339 );340 shell.sed(341 '-i',342 '<!-- ADD GOOGLE MAPS CONFIG HERE -->',343 `<meta-data344 android:name="com.google.android.geo.API_KEY"345 android:value="${googleMaps.apiKey}"/>`,346 `${shellPath}app/src/main/AndroidManifest.xml`347 );348 }349 // Google Login350 if (googleSignIn) {351 certificateHash = googleSignIn.certificateHash;352 googleAndroidApiKey = googleSignIn.apiKey;353 }354 }355 // Google sign in356 shell.sed(357 '-i',358 /"current_key": "(.*?)"/,359 `"current_key": "${googleAndroidApiKey}"`,360 `${shellPath}app/google-services.json`361 );362 shell.sed(363 '-i',364 /"certificate_hash": "(.*?)"/,365 `"certificate_hash": "${certificateHash}"`,366 `${shellPath}app/google-services.json`367 );368 if (keystore && alias && keystorePassword && keyPassword) {369 await spawnAsync(`/bin/rm`, [`shell-unaligned.apk`]);370 await spawnAsync(`/bin/rm`, [`shell.apk`]);371 await spawnAsyncThrowError(`./gradlew`, [`assembleProdRelease`], {372 stdio: 'inherit',373 cwd: shellPath,374 });375 await spawnAsync(`/bin/cp`, [376 `${shellPath}app/build/outputs/apk/app-prod-release-unsigned.apk`,377 `shell-unaligned.apk`,378 ]);379 await spawnAsync(`jarsigner`, [380 '-verbose',381 '-sigalg',382 'SHA1withRSA',383 '-digestalg',384 'SHA1',385 '-storepass',386 keystorePassword,387 '-keypass',388 keyPassword,389 '-keystore',390 keystore,391 'shell-unaligned.apk',392 alias,393 ]);394 await spawnAsync(`zipalign`, [395 '-v',396 '4',397 'shell-unaligned.apk',398 'shell.apk',399 ]);400 await spawnAsync(`/bin/rm`, ['shell-unaligned.apk']);401 await spawnAsync(`jarsigner`, [402 '-verify',403 '-verbose',404 '-certs',405 '-keystore',406 keystore,407 'shell.apk',408 ]);409 await spawnAsyncThrowError(`/bin/cp`, [410 'shell.apk',411 outputFile || '/tmp/shell-signed.apk',412 ]);413 } else {414 await spawnAsync(`/bin/cp`, ['../android/debug.keystore', `${shellPath}/`]);415 await spawnAsync(`/bin/rm`, ['shell-debug.apk']);416 await spawnAsyncThrowError(`./gradlew`, ['assembleDevRemoteKernelDebug'], {417 stdio: 'inherit',418 cwd: shellPath,419 });420 await spawnAsyncThrowError(`/bin/cp`, [421 `${shellPath}app/build/outputs/apk/app-devRemoteKernel-debug.apk`,422 `/tmp/shell-debug.apk`,423 ]);424 }...

Full Screen

Full Screen

cli.mjs

Source:cli.mjs Github

copy

Full Screen

2describe('CLI', function () {3 describe('Basic commands', function () {4 this.timeout(8000);5 it('Gets help', async function () {6 const {stdout, stderr} = await spawnAsync('./bin/pop.js', ['--help']);7 expect(stderr).to.equal('');8 expect(stdout).to.contain('Usage: pop [options]');9 });10 it('Ignores empty command', async function () {11 const {stdout, stderr} = await spawnAsync('./bin/pop.js', ['--']);12 expect(stderr).to.equal('user is required!\n');13 expect(stdout).to.contain('Usage: pop [options]');14 });15 it('Times out', async function () {16 this.timeout(40000);17 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [18 '--config',19 'pop.config.json',20 '--method',21 'LIST',22 '--timeout',23 '10'24 ]);25 expect(stderr).to.contain('Error: timeout');26 expect(stdout).to.equal('');27 });28 });29 describe('POP commands', function () {30 this.timeout(60000);31 it('Override config to run without TLS', async function () {32 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [33 '--config',34 'pop.config.json',35 '--no-tls',36 '--method',37 'QUIT'38 ]);39 expect(stderr).to.equal('');40 expect(stdout).to.equal("'Bye'\n");41 });42 it('Runs QUIT', async function () {43 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [44 '--config',45 'pop.config.json',46 '--method',47 'QUIT'48 ]);49 expect(stderr).to.equal('');50 expect(stdout).to.equal("'Bye'\n");51 });52 // Todo: For RETR, TOP, and LIST, we should really seed the account with an53 // email to ensure one exists (could add `emailjs` as a dependency)54 it('Runs RETR', async function () {55 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [56 '--config',57 'pop.config.json',58 '--method',59 'RETR',60 '1'61 ]);62 expect(stderr).to.equal('');63 expect(stdout).to.contain('Received:');64 });65 it('Runs TOP', async function () {66 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [67 '--config',68 'pop.config.json',69 '--method',70 'TOP',71 '1',72 '1'73 ]);74 expect(stderr).to.equal('');75 expect(stdout).to.contain('Received:');76 });77 it('Runs LIST', async function () {78 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [79 '--config',80 'pop.config.json',81 '--method',82 'LIST'83 ]);84 expect(stderr).to.equal('');85 expect(stdout).to.match(/'\d+ messages:'/u).and.match(/'\d+ \d+(\\r\\n\d+ \d+)*'/u);86 });87 it('Runs UIDL', async function () {88 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [89 '--config',90 'pop.config.json',91 '--method',92 'UIDL'93 // '1'94 ]);95 expect(stderr).to.equal('');96 expect(stdout).to.contain("[ [ '1',");97 });98 it('Runs NOOP', async function () {99 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [100 '--config',101 'pop.config.json',102 '--method',103 'NOOP'104 // '1'105 ]);106 expect(stderr).to.equal('');107 expect(stdout).to.equal("[ '', null ]\n");108 });109 it('Runs STAT', async function () {110 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [111 '--config',112 'pop.config.json',113 '--method',114 'STAT'115 ]);116 expect(stderr).to.equal('');117 expect(stdout).to.match(/\[ '\d+ \d+', null \]\n/u);118 });119 it('Runs RSET', async function () {120 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [121 '--config',122 'pop.config.json',123 '--method',124 'RSET'125 // '1'126 ]);127 expect(stderr).to.equal('');128 expect(stdout).to.contain("[ '', null ]\n");129 });130 it('Runs DELE', async function () {131 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [132 '--config',133 'pop.config.json',134 '--method',135 'DELE',136 '1'137 ]);138 expect(stderr).to.equal('');139 expect(stdout).to.contain("[ 'Marked to be deleted.', null ]\n");140 });141 // Todo: Test APOP142 });143 describe('CLI Errors', function () {144 it('Errs with bad user/pass', async function () {145 this.timeout(10000);146 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [147 '--user',148 'brett@example.name',149 '--password',150 '123456',151 '--host',152 'example.name',153 '--method',154 'NOOP'155 // '1'156 ]);157 expect(stderr).to.contain('getaddrinfo ENOTFOUND');158 expect(stdout).to.equal('');159 });160 it('Errs upon invalid alias', async function () {161 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [162 '-x'163 ]);164 expect(stderr).to.equal('Invalid alias x\n');165 expect(stdout).to.equal('');166 });167 it('Errs upon invalid argument', async function () {168 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [169 'xyz'170 ]);171 expect(stderr).to.equal('Invalid argument xyz\n');172 expect(stdout).to.equal('');173 });174 it('Errs upon missing method', async function () {175 let {stdout, stderr} = await spawnAsync('./bin/pop.js', [176 '--config',177 'pop.config.json'178 ]);179 expect(stderr).to.equal('method is required!\n');180 expect(stdout).to.contain('Usage: pop [options]');181 ({stdout, stderr} = await spawnAsync('./bin/pop.js', [182 '--config',183 'pop.config.json',184 '-u',185 'brett@example.name'186 ]));187 expect(stderr).to.equal('method is required!\n');188 expect(stdout).to.contain('Usage: pop [options]');189 });190 it('Errs on bad RETR', async function () {191 this.timeout(60000);192 const {stdout, stderr} = await spawnAsync('./bin/pop.js', [193 '--config',194 'pop.config.json',195 '--method',196 'RETR',197 '0'198 ]);199 expect(stderr).to.contain("There's no message 0");200 expect(stdout).to.equal('');201 });202 });...

Full Screen

Full Screen

benchmark.js

Source:benchmark.js Github

copy

Full Screen

...85 });86 });87}88async function cleanUp() {89 return spawnAsync(hexoBin, ['clean'], { cwd: testDir });90}91async function gitClone(repo, dir, depth = 1) {92 return spawnAsync('git', ['clone', repo, dir, `--depth=${depth}`]);93}94async function init() {95 if (await exists(testDir)) {96 log.info(`"${testDir}" already exists. Skipping benchmark environment setup.`);97 } else {98 log.info('Setting up a dummy hexo site with 500 posts');99 await gitClone('https://github.com/hexojs/hexo-theme-unit-test.git', testDir);100 await gitClone('https://github.com/hexojs/hexo-theme-landscape', resolve(testDir, 'themes', 'landscape'));101 await gitClone('https://github.com/SukkaLab/hexo-many-posts.git', resolve(testDir, 'source', '_posts', 'hexo-many-posts'));102 }103 log.info('Installing dependencies');104 // Always re-install dependencies105 if (await exists(resolve(testDir, 'node_modules'))) await rmdir(resolve(testDir, 'node_modules'));106 await spawnAsync(npmScript, ['install', '--silent'], { cwd: testDir });107 log.info('Replacing hexo');108 await rmdir(resolve(testDir, 'node_modules', 'hexo'));109 if (isWin32) {110 await spawnAsync('cmd', [111 '/s', '/c', 'mklink', '/D',112 resolve(testDir, 'node_modules', 'hexo'),113 resolve(__dirname, '..')114 ]);115 await rmdir(resolve(testDir, 'node_modules', 'hexo-cli'));116 await spawnAsync('cmd', [117 '/s', '/c', 'mklink', '/D',118 resolve(testDir, 'node_modules', 'hexo-cli'),119 resolve(__dirname, '..', 'node_modules', 'hexo-cli')120 ]);121 } else {122 await spawnAsync('ln', [123 '-sf',124 resolve(__dirname, '..'),125 resolve(testDir, 'node_modules', 'hexo')126 ]);127 }128}129async function profiling() {130 // Clean up 0x dir before profiling131 if (await exists(zeroEksDir)) await rmdir(zeroEksDir);132 const zeroEksOpts = {133 argv: [hexoBin, 'g', '--cwd', testDir],134 workingDir: '.', // A workaround for https://github.com/davidmarkclements/0x/issues/228135 outputDir: zeroEksDir,136 title: 'Hexo Flamegraph'...

Full Screen

Full Screen

montage.js

Source:montage.js Github

copy

Full Screen

...23const convert = args => {24 if (DEBUG) {25 console.debug(`magick convert ${args.join(" ")}`);26 }27 return spawnAsync("magick", ["convert", ...args]);28};29const composite = args => {30 const allArgs = ["composite", "-colorspace", "RGB", ...args];31 if (DEBUG) {32 console.debug(`magick ${allArgs.join(" ")}`);33 }34 return spawnAsync("magick", allArgs);35};36const processScreenshot = async (37 { src, dest, tmp },38 { profileDir, phoneWidth, title, width, height, screenshot }39) => {40 const tmpDevice = `${tmp}/device.png`;41 const tmpBackground = `${tmp}/background.png`;42 const tmpScreenshot = `${tmp}/screenshot.png`;43 const tmpScreenshotComposite = `${tmp}/screenshot-composite.png`;44 const [_, rotate, label] = path45 .basename(src, ".png")46 .match(/^\d+\s*(rotLeft|rotRight)?[ -]*(.+)$/);47 // background48 await convert([49 "-size",50 `${width}x${height}`,51 `canvas:${backgroundColor}`,52 "-font",53 fontPath,54 "-weight",55 fontWeight,56 "-pointsize",57 fontSize,58 "-fill",59 fontColor,60 "-gravity",61 "North",62 "-annotate",63 `+0+${title.marginTop}`,64 label,65 tmpBackground66 ]);67 // phone image68 await convert([69 profileDir + "/device.png",70 "-resize",71 `${phoneWidth}x`,72 tmpDevice73 ]);74 // screenshot resize75 await convert([76 src,77 "-resize",78 screenshot.width,79 "-gravity",80 "North",81 tmpScreenshot82 ]);83 // phone with screenshot84 // compose dst-over with inversion of background & front because final size is the src size85 await composite(86 [87 !!rotate && "-rotate",88 !!rotate && "-30",89 "-compose",90 "dst-over",91 "-background",92 "transparent",93 "-gravity",94 "center",95 tmpScreenshot,96 tmpDevice,97 tmpScreenshotComposite98 ].filter(arg => arg)99 );100 if (rotate) {101 const geometryLeft =102 rotate == "rotLeft"103 ? `+${screenshot.rotation.marginLeft}`104 : screenshot.rotation.marginLeft - width;105 composite([106 "-gravity",107 "West",108 tmpScreenshotComposite,109 "-geometry",110 `${geometryLeft}+${screenshot.rotation.marginTop}`,111 tmpBackground,112 dest113 ]);114 } else {115 composite([116 "-gravity",117 "center",118 tmpScreenshotComposite,119 "-geometry",120 `+0+${screenshot.marginTop}`,121 tmpBackground,122 dest123 ]);124 }125};126const processProfile = dir => {127 const profileName = path.basename(dir);128 console.log("Profile " + profileName + " in " + dir);129 const profileDir = "./profiles/" + profileName;130 const config = require(profileDir + "/config.json");131 const destDir = `./screenshots/${profileName}`;132 rmkDir(destDir);133 return spawnAsync("find", [dir, "-name", "*.png", "-depth", "1"])134 .then(findResult)135 .then(imgs => {136 const transf = imgs.map((src, index) => {137 const dest = `${destDir}/${profileName} ${index + 1}.png`;138 const tmp = `./tmp/${profileName}-${index}`;139 rmkDir(tmp);140 return processScreenshot({ src, dest, tmp }, { profileDir, ...config })141 .then(() => {142 console.log("Wrote " + dest);143 })144 .catch(error => {145 console.error("Error during processing " + src, error);146 });147 });148 return Promise.all(transf);149 });150};151spawnAsync("find", ["sources", "-type", "d", "-depth", "1"])152 .then(findResult)153 .then(profiles => {154 profiles.forEach(profile => {155 processProfile(profile);156 });157 })158 .catch(error => {159 console.error(error);...

Full Screen

Full Screen

spawn.js

Source:spawn.js Github

copy

Full Screen

...82 process.exit(1)83 }84 const fullCommand = process.argv.slice(2).join(' ')85 const [command, ...args] = fullCommand.split(' ')86 spawnAsync(command, args)87 .then( result => {88 //if (result.code === 0)89 console.log( result /*.stdout*/ ) // print the attribute stdout of resolve object90 //else91 // console.error( `command ${result.fullcmd} failed with exit code: ${result.code}` )92 93 })94 .catch( data => console.log( `command failed. See: ${data}` ))95}96if (require.main === module) 97 main()...

Full Screen

Full Screen

update-sdks.js

Source:update-sdks.js Github

copy

Full Screen

...9 '@applitools/eyes-images',10 '@applitools/visual-grid-client',11]12async function upgradeSDKs() {13 await spawnAsync('yarn', ['upgrade', ...SDKS_TO_UPGRADE, '--json'])14}15async function upgradeEyesSeleniumSdk() {16 const EYES_SELENIUM_SDK_NAME = '@applitools/eyes-selenium'17 const PLUGIN_MANIFEST_PATH = './src/background/plugin-manifest.json'18 const latestVersion = await getLatestSdkVersion(EYES_SELENIUM_SDK_NAME)19 const pkg = JSON.parse((await fs.readFile(PLUGIN_MANIFEST_PATH)).toString())20 pkg.dependencies[EYES_SELENIUM_SDK_NAME] = latestVersion21 await fs.writeFile(PLUGIN_MANIFEST_PATH, JSON.stringify(pkg, undefined, 2))22}23async function getLatestSdkVersion(sdk) {24 const info = JSON.parse(await spawnAsync('yarn', ['info', sdk, '--json']))25 return info.data['dist-tags'].latest26}27async function writeChangelog() {28 const [pkg, changelog] = await Promise.all([29 JSON.parse((await fs.readFile('./package.json')).toString()),30 (await fs.readFile('./CHANGELOG.md')).toString(),31 ])32 await fs.writeFile(33 './CHANGELOG.md',34 changelog.replace(35 '# Changelog',36 `# Changelog\n\n## v${pkg.version}\n- Updated underlying Applitools SDKs`37 )38 )39}40async function stageFiles(files) {41 await spawnAsync('git', ['add', ...files])42}43async function versionAndTag() {44 await spawnAsync('yarn', ['version', '--patch'])45}46async function amendCommit() {47 await spawnAsync('git', ['commit', '--amend', '--no-edit'])48}49async function pushCommit() {50 await spawnAsync('git', ['push', 'origin', 'master', '--tags'])51}52;(async () => {53 if (isCwdCorrect()) {54 console.log('upgrading SDKs')55 await Promise.all([upgradeEyesSeleniumSdk(), upgradeSDKs()])56 console.log('preparing commit')57 await stageFiles(['yarn.lock', 'src/background/plugin-manifest.json'])58 console.log('commiting and creating tags')59 await versionAndTag()60 console.log('writing changelog')61 await writeChangelog()62 await stageFiles(['CHANGELOG.md'])63 await amendCommit()64 console.log('pushing...')...

Full Screen

Full Screen

saofile.js

Source:saofile.js Github

copy

Full Screen

...7 .sort((a, b) => a.match(/\d+/)[0] - b.match(/\d+/)[0])8const d = (days.length == 0) ?9 1 :10 parseInt(days[days.length-1].match(/\d+/)[0]) + 111function spawnAsync(cmd, ...args) {12 return new Promise((resolve, reject) => {13 const child = spawn(cmd, args, {14 stdio: 'inherit'15 })16 child.on('error', reject)17 child.on('exit', code => {18 if (code === 0) {19 resolve()20 }21 reject(new Error(`Child died with: ${code}`))22 })23 })24}25module.exports = {26 actions: [27 {28 type: 'add',29 files: '**'30 },31 {32 type: 'move',33 patterns: {34 'template.js': `day${d}.js`,35 'test/day.tests': `test/day${d}.tests`,36 'lines.pegjs': `day${d}.pegjs`,37 'input.txt': `day${d}.txt`38 }39 }40 ],41 async completed() {42 await spawnAsync('curl',43 '-b', '.cookies',44 '-o', `inputs/day${d}.txt`,45 `https://adventofcode.com/2020/day/${d}/input`)46 await spawnAsync('code', `day${d}.js`)47 await spawnAsync('code', `day${d}.pegjs`)48 await spawnAsync('code', `inputs/day${d}.txt`)49 await spawnAsync('code', `test/day${d}.tests`)50 await spawnAsync('npm', 'test')51 }...

Full Screen

Full Screen

saofile.cjs

Source:saofile.cjs Github

copy

Full Screen

...5 .sort((a, b) => a.match(/\d+/)[0] - b.match(/\d+/)[0]);6const d = (days.length === 0)7 ? 18 : parseInt(days[days.length - 1].match(/\d+/)[0], 10) + 1;9function spawnAsync(cmd, ...args) {10 return new Promise((resolve, reject) => {11 const child = spawn(cmd, args, {12 stdio: "inherit",13 });14 child.on("error", reject);15 child.on("exit", code => {16 if (code === 0) {17 resolve();18 }19 reject(new Error(`Child died with: ${code}`));20 });21 });22}23module.exports = {24 actions: [25 {26 type: "add",27 files: "**",28 },29 {30 type: "move",31 patterns: {32 "template.ts": `day${d}.ts`,33 "test/day.tests": `test/day${d}.tests`,34 "lines.peggy": `day${d}.peggy`,35 "input.txt": `day${d}.txt`,36 },37 },38 ],39 async completed() {40 await spawnAsync("curl",41 "-b",42 ".cookies",43 "-o",44 `inputs/day${d}.txt`,45 `https://adventofcode.com/2021/day/${d}/input`);46 await spawnAsync("code", `day${d}.ts`);47 await spawnAsync("code", `day${d}.peggy`);48 await spawnAsync("code", `inputs/day${d}.txt`);49 await spawnAsync("code", `test/day${d}.tests`);50 await spawnAsync("npm", "test");51 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('@playwright/test/lib/utils/process');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 { stdout, stderr } = await spawnAsync('ls', ['-la'], {8 env: {9 },10 });11 console.log(stdout);12 console.error(stderr);13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright-core/lib/utils/childProcess');2const path = require('path');3const { chromium } = require('playwright-core');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const { process, kill } = await spawnAsync(9 path.join(__dirname, 'server.js'),10 {11 env: { ...process.env, ...{ PORT: '8080' } },12 }13 );14 process.stdout.on('data', (data) => console.log(data.toString()));15 process.stderr.on('data', (data) => console.log(data.toString()));16 process.on('exit', (code) => {17 console.log(`child process exited with code ${code}`);18 });19 await page.waitForSelector('#hello');20 console.log(await page.innerText('#hello'));21 await browser.close();22 kill();23})();24const http = require('http');25const PORT = process.env.PORT || 8080;26const server = http.createServer((req, res) => {27 res.writeHead(200);28 res.end('<h1 id="hello">Hello World</h1>');29});30server.listen(PORT, () => {31 console.log(`Server listening on port ${PORT}!`);32});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright/lib/utils/spawn');2const { firefox } = require('playwright');3(async () => {4 const firefoxProcess = await spawnAsync({5 executablePath: firefox.executablePath(),6 });7 firefoxProcess.stdout.on('data', (data) => {8 console.log(`stdout: ${data}`);9 });10 firefoxProcess.stderr.on('data', (data) => {11 console.error(`stderr: ${data}`);12 });13 firefoxProcess.on('close', (code) => {14 console.log(`child process exited with code ${code}`);15 });16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright/lib/server/processLauncher');2spawnAsync('node', ['--version'], {3 cwd: process.cwd(),4 attemptToGracefullyClose: () => Promise.resolve(),5}).then(result => {6 console.log(result);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright/lib/utils/child_process');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const title = await page.title();7 console.log('Page title: ' + title);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright-core/lib/utils/child_process');2const { spawn } = require('child_process');3async function main() {4 const { process } = await spawnAsync('node', ['test2.js'], {5 });6 process.stdout.on('data', (data) => {7 console.log(`stdout: ${data}`);8 });9 process.stderr.on('data', (data) => {10 console.error(`stderr: ${data}`);11 });12 process.on('close', (code) => {13 console.log(`child process exited with code ${code}`);14 });15}16main();17const { spawn } = require('child_process');18const { spawnAsync } = require('playwright-core/lib/utils/child_process');19async function main() {20 const { process } = await spawnAsync('node', ['test3.js'], {21 });22 process.stdout.on('data', (data) => {23 console.log(`stdout: ${data}`);24 });25 process.stderr.on('data', (data) => {26 console.error(`stderr: ${data}`);27 });28 process.on('close', (code) => {29 console.log(`child process exited with code ${code}`);30 });31}32main();33const { spawn } = require('child_process');34const { spawnAsync } = require('playwright-core/lib/utils/child_process');35async function main() {36 const { process } = await spawnAsync('node', ['test4.js'], {37 });38 process.stdout.on('data', (data) => {39 console.log(`stdout: ${data}`);40 });41 process.stderr.on('data', (data) => {42 console.error(`stderr: ${data}`);43 });44 process.on('close', (code) => {45 console.log(`child process exited with code ${code}`);46 });47}48main();49const { spawn } = require('child_process');50const { spawnAsync } = require('playwright-core/lib/utils/child_process');51async function main() {52 const { process } = await spawnAsync('node', ['test5.js'], {53 });54 process.stdout.on('data', (data) => {55 console.log(`stdout:

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright-core/lib/utils/child_process');2(async() => {3 const { code, stdout, stderr } = await spawnAsync('ls', ['-l']);4 console.log('code', code);5 console.log('stdout', stdout);6 console.log('stderr', stderr);7})();8const { spawnAsync } = require('playwright-core/lib/utils/child_process');9(async() => {10 const { code, stdout, stderr } = await spawnAsync('ls', ['-l']);11 console.log('code', code);12 console.log('stdout', stdout);13 console.log('stderr', stderr);14})();15const { spawnAsync } = require('playwright-core/lib/utils/child_process');16(async() => {17 const { code, stdout, stderr } = await spawnAsync('ls', ['-l']);18 console.log('code', code);19 console.log('stdout', stdout);20 console.log('stderr', stderr);21})();22const { spawnAsync } = require('playwright-core/lib/utils/child_process');23(async() => {24 const { code, stdout, stderr } = await spawnAsync('ls', ['-l']);25 console.log('code', code);26 console.log('stdout', stdout);27 console.log('stderr', stderr);28})();29const { spawnAsync } = require('playwright-core/lib/utils/child_process');30(async() => {31 const { code, stdout, stderr } = await spawnAsync('ls', ['-l']);32 console.log('code', code);33 console.log('stdout', stdout);34 console.log('stderr', stderr);35})();36const { spawnAsync } = require('playwright-core/lib/utils/child_process');37(async() => {38 const {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { spawnAsync } = require('playwright/lib/utils/child_process');2const { spawn } = require('child_process');3spawnAsync('node', ['--version'])4 .then((process) => {5 process.stdout.on('data', (data) => {6 console.log(`stdout: ${data}`);7 });8 process.stderr.on('data', (data) => {9 console.error(`stderr: ${data}`);10 });11 process.on('close', (code) => {12 console.log(`child process exited with code ${code}`);13 });14 });15const child = spawn('node', ['--version']);16child.stdout.on('data', (data) => {17 console.log(`stdout: ${data}`);18});19child.stderr.on('data', (data) => {20 console.error(`stderr: ${data}`);21});22child.on('close', (code) => {23 console.log(`child process exited with code ${code}`);24});25const { spawnAsync } = require('playwright/lib/utils/child_process');26const { spawn } = require('child_process');27spawnAsync('node', ['--version'])28 .then((process) => {29 process.stdout.on('data', (data) => {30 console.log(`stdout: ${data}`);31 });32 process.stderr.on('data', (data) => {33 console.error(`stderr: ${data}`);34 });35 process.on('close', (code) => {36 console.log(`child process exited with code ${code}`);37 });38 });39const child = spawn('node', ['--version']);40child.stdout.on('data', (data) => {41 console.log(`stdout: ${data}`);42});43child.stderr.on('data', (data)

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