Best JavaScript code snippet using taiko
googleBingScraper.js
Source:googleBingScraper.js
...27 await page.setViewport({28 width: 2000,29 height: 1000,30 });31 // await page.emulateTimezone("Asia/Singapore");32 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');33 // Replace with your Google Maps URL... Or Test the Microsoft one...34 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');35 const response = await page.goto(url, {36 waitUntil: 'networkidle2',37 // timeout: 038 }); // Define the Maps URL to Scrape...39 console.log('waiting for selector');40 await page.waitFor(2000);41 try {42 var relatedKeywordsGoogle = await page.$$eval("a.k8XOCe.R0xfCb.VCOFK.s8bAkb",43 elements => elements.map(item => item.textContent))44 //console.log(relatedKeywordsGoogle)45 var resultTitleGoogle = await page.$$eval("div.NJo7tc.Z26q7c.jGGQ5e > div.yuRUbf > a > h3.LC20lb.MBeuO.DKV0Md",46 elements => elements.map(item => item.textContent))47 //console.log(resultTitleGoogle)48 var resultDescriptionGoogle = await page.$$eval("div.NJo7tc.Z26q7c.uUuwM",49 elements => elements.map(item => item.textContent))50 //console.log(resultDescriptionGoogle)51 var resultUrlGoogle = await page.$$eval("div.NJo7tc.Z26q7c.jGGQ5e > div.yuRUbf > a",52 elements => elements.map(item => item.getAttribute("href")))53 //console.log(resultUrlGoogle)54 var richSnippetGoogle = await page.$$eval("div.V3FYCf > div.wDYxhc ",55 elements => elements.map(item => item.innerHTML))56 //console.log(resultUrlGoogle)57 const selectors = await page.$$('.iDjcJe.IX9Lgd.wwB5gf')58 try {59 for (var i = 1; i < selectors.length; i++) {60 await page.waitFor(1000);61 await selectors[i].click()62 }63 } catch (error) {64 console.log('Faq found for click')65 }66 // await page.waitForSelector('div.iDjcJe.IX9Lgd.wwB5gf span')67 await page.waitFor(3000);68 // remove some html from the DOM (Answers Link Class Remove)69 let div_selector_to_remove = "div.g";70 await page.evaluate((sel) => {71 var elements = document.querySelectorAll(sel);72 for (var i = 0; i < elements.length; i++) {73 elements[i].parentNode.removeChild(elements[i]);74 }75 }, div_selector_to_remove)76 let div_selector_to_remove_2 = "div.hwqd7e.d0fCJc.BOZ6hd";77 await page.evaluate((sel) => {78 var elements2 = document.querySelectorAll(sel);79 for (var i = 0; i < elements2.length; i++) {80 elements2[i].parentNode.removeChild(elements2[i]);81 }82 }, div_selector_to_remove_2)83 var linkTextsQuestions = await page.$$eval("div.iDjcJe.IX9Lgd.wwB5gf span",84 elements => elements.map(item => item.textContent))85 var linkTextsAnswers = await page.$$eval("div.MBtdbb",86 elements => elements.map(item => item.textContent))87 var finalResult = {88 'status': 'success',89 'questions': linkTextsQuestions,90 'answers': linkTextsAnswers,91 'richSnippetGoogle': richSnippetGoogle,92 'resultTitleGoogle': resultTitleGoogle,93 'resultDescriptionGoogle': resultDescriptionGoogle,94 'resultUrlGoogle': resultUrlGoogle,95 'relatedKeywordsGoogle': relatedKeywordsGoogle96 }97 return finalResult;98 } catch (err) {99 console.error(err);100 var finalResult = {101 'status': 'fail',102 'richSnippet': richSnippet,103 }104 return finalResult;105 process.exit(1);106 } finally {107 await page.close();108 await browser.close();109 }110 };111 scrape().then((value) => { // Scrape and output the results...112 res.send(value); // Yay, output the Results...113 });114})115app.get('/bing', (req, res) => {116 // Access the provided 'page' and 'limt' query parameters117 let url = req.query.url;118 let scrape = async () => { // Prepare scrape...119 const browser = await puppeteer.launch({120 // headless: false, //enable only when on localServer121 headless: true,122 ignoreDefaultArgs: ["--enable-automation"],123 ignoreHTTPSErrors: true,124 args: [125 '--no-sandbox',126 '--disable-setuid-sandbox',127 '--disable-accelerated-2d-canvas',128 '--no-zygote',129 '--renderer-process-limit=1',130 '--no-first-run',131 '--disable-dev-shm-usage',132 '--single-process', // <- this one doesn't works in Windows133 '--disable-gpu'134 ],135 }); // Prevent non-needed issues for *NIX136 const page = await browser.newPage(); // Create request for the new page to obtain...137 await page.setViewport({138 width: 2000,139 height: 1000,140 });141 // await page.emulateTimezone("Asia/Singapore");142 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');143 // Replace with your Google Maps URL... Or Test the Microsoft one...144 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');145 const response = await page.goto(url, {146 waitUntil: 'networkidle2',147 // timeout: 0148 }); // Define the Maps URL to Scrape...149 console.log('waiting for selector');150 await page.waitFor(3000);151 try {152 // remove some html from the DOM (Answers Link Class Remove)153 let div_selector_to_remove = "div.df_img.df_atct.tall";154 await page.evaluate((sel) => {155 var elements = document.querySelectorAll(sel);156 for (var i = 0; i < elements.length; i++) {157 elements[i].parentNode.removeChild(elements[i]);158 }159 }, div_selector_to_remove)160 let div_selector_to_remove_2 = "div.b_footnote.imgtt_ref";161 await page.evaluate((sel) => {162 var elements2 = document.querySelectorAll(sel);163 for (var i = 0; i < elements2.length; i++) {164 elements2[i].parentNode.removeChild(elements2[i]);165 }166 }, div_selector_to_remove_2)167 var resultTitle = await page.$$eval("div.b_title > h2",168 elements => elements.map(item => item.textContent))169 //console.log(resultTitle)170 var resultTitle_1 = await page.$$eval("li.b_algo >h2",171 elements => elements.map(item => item.textContent))172 //console.log(resultTitle)173 resultTitle = (!resultTitle.length) ? resultTitle_1 : resultTitle;174 var resultDescription = await page.$$eval("div.b_caption > p",175 elements => elements.map(item => item.textContent))176 //console.log(resultDescription)177 var resultUrl = await page.$$eval("div.b_title > h2 > a",178 elements => elements.map(item => item.getAttribute("href")))179 //console.log(resultUrl)180 var resultUrl_1 = await page.$$eval("li.b_algo >h2 > a",181 elements => elements.map(item => item.getAttribute("href")))182 //console.log(resultUrl)183 resultUrl = (!resultUrl.length) ? resultUrl_1 : resultUrl;184 var relatedKeywords = await page.$$eval("div.b_rs > ul.b_vList.b_divsec > li",185 elements => elements.map(item => item.textContent))186 //console.log(relatedKeywords)187 var mainQuestions = await page.$$eval("div.b_expansion_wrapper.b_expand.b_divsec.b_onpage_expansion",188 elements => elements.map(item => item.textContent))189 //console.log(mainQuestions)190 var mainAnswers = await page.$$eval("div.rwrl.rwrl_small.rwrl_padref",191 elements => elements.map(item => item.innerHTML))192 //console.log(mainAnswers)193 var richSnippet = await page.$$eval("div.rwrl.rwrl_pri.rwrl_padref",194 elements => elements.map(item => item.innerHTML))195 //console.log(richSnippet)196 var richSnippetLink = await page.$$eval("div.b_algo > h2 > a",197 elements => elements.map(item => item.getAttribute("href")))198 //console.log(richSnippetLink)199 var tabNav = await page.$$eval("div.tab-menu.tab-hasnav > ul > li",200 elements => elements.map(item => item.innerHTML))201 //console.log(tabNav)202 var tabContent = await page.$$eval("div.tab-content > div",203 elements => elements.map(item => item.innerHTML))204 //console.log(tabNav)205 var slideQuestions = await page.$$eval("div.b_insideSlide > div.b_title",206 elements => elements.map(item => item.textContent))207 //console.log(tabNav)208 var slideAnswers = await page.$$eval("div.b_insideSlide > div.b_text",209 elements => elements.map(item => item.textContent))210 //console.log(tabNav)211 var finalResult = {212 'status': 'success',213 'resultTitle': resultTitle,214 'resultDescription': resultDescription,215 'resultUrl': resultUrl,216 'mainQuestions': mainQuestions,217 'mainAnswers': mainAnswers,218 'richSnippet': richSnippet,219 'richSnippetLink': richSnippetLink,220 'slideQuestions': slideQuestions,221 'slideAnswers': slideAnswers,222 'relatedKeywords': relatedKeywords,223 }224 const selectors = await page.$$('.scs_icn')225 try {226 for (var i = 1; i < selectors.length; i++) {227 console.log(i)228 await selectors[i].click()229 await page.waitFor(1000);230 }231 } catch (error) {232 console.log('no icon found for click')233 }234 var popQuestions = await page.$$eval("div.scs_faAc > div.b_vPanel > div.b_module_expansion_control.b_module_head > div.b_module_expansion > div.b_expansion_wrapper.b_collapse.b_onpage_expansion",235 elements => elements.map(item => item.textContent))236 //console.log(popQuestions)237 var popAnswers = await page.$$eval("div.rwrl.rwrl_small.rwrl_resetFont",238 elements => elements.map(item => item.innerHTML))239 //console.log(popAnswers)240 finalResult.popQuestions = popQuestions241 finalResult.popAnswers = popAnswers242 const selectorsNav = await page.$$('div.tab-menu.tab-hasnav > ul > li')243 try {244 for (var i = 1; i < selectorsNav.length; i++) {245 console.log(i)246 await selectorsNav[i].click()247 await page.waitFor(1000);248 }249 } catch (error) {250 console.log('no NavBar found for click')251 }252 var tabNav = await page.$$eval("div.tab-menu.tab-hasnav > ul > li",253 elements => elements.map(item => item.innerHTML))254 //console.log(tabNav)255 var tabContent = await page.$$eval("div.tab-content > div",256 elements => elements.map(item => item.innerHTML))257 //console.log(tabNav)258 finalResult.tabNav = tabNav259 finalResult.tabContent = tabContent260 return finalResult;261 } catch (err) {262 console.error(err);263 return finalResult;264 process.exit(1);265 } finally {266 await page.close();267 await browser.close();268 }269 };270 scrape().then((value) => { // Scrape and output the results...271 res.send(value); // Yay, output the Results...272 });273})274app.get('/bing-thumb', (req, res) => {275 // Access the provided 'page' and 'limt' query parameters276 let url = req.query.url;277 let scrape = async () => { // Prepare scrape...278 const browser = await puppeteer.launch({279 // headless: false, //enable only when on localServer280 headless: true,281 ignoreDefaultArgs: ["--enable-automation"],282 ignoreHTTPSErrors: true,283 args: [284 '--no-sandbox',285 '--disable-setuid-sandbox',286 '--disable-accelerated-2d-canvas',287 '--no-zygote',288 '--renderer-process-limit=1',289 '--no-first-run',290 '--disable-dev-shm-usage',291 '--single-process', // <- this one doesn't works in Windows292 '--disable-gpu'293 ],294 }); // Prevent non-needed issues for *NIX295 const page = await browser.newPage(); // Create request for the new page to obtain...296 await page.setViewport({297 width: 2000,298 height: 1000,299 });300 // await page.emulateTimezone("Asia/Singapore");301 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');302 // Replace with your Google Maps URL... Or Test the Microsoft one...303 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');304 const response = await page.goto(url, {305 waitUntil: 'networkidle2',306 // timeout: 0307 }); // Define the Maps URL to Scrape...308 console.log('waiting for selector');309 await page.waitFor(3000);310 try {311 const result = await page.evaluate(() => { // Let's create variables and store values...312 let thumbnailClasses = document.querySelectorAll('a.iusc');313 let thumbnail = []314 for (let elements of thumbnailClasses) {315 thumbnail.push(elements.getAttribute('m'));316 }317 var thumbnail_j = JSON.parse(thumbnail[0]);318 return thumbnail_j.murl;319 });320 return result;321 } catch (err) {322 console.error(err);323 return null;324 process.exit(1);325 } finally {326 await page.close();327 await browser.close();328 }329 };330 scrape().then((value) => { // Scrape and output the results...331 res.send(value); // Yay, output the Results...332 });333})334app.get('/bing-images', (req, res) => {335 // Access the provided 'page' and 'limt' query parameters336 let url = req.query.url;337 let scrape = async () => { // Prepare scrape...338 const browser = await puppeteer.launch({339 // headless: false, //enable only when on localServer340 headless: true,341 ignoreDefaultArgs: ["--enable-automation"],342 ignoreHTTPSErrors: true,343 args: [344 '--no-sandbox',345 '--disable-setuid-sandbox',346 '--disable-accelerated-2d-canvas',347 '--no-zygote',348 '--renderer-process-limit=1',349 '--no-first-run',350 '--disable-dev-shm-usage',351 '--single-process', // <- this one doesn't works in Windows352 '--disable-gpu'353 ],354 }); // Prevent non-needed issues for *NIX355 const page = await browser.newPage(); // Create request for the new page to obtain...356 await page.setViewport({357 width: 2000,358 height: 1000,359 });360 // await page.emulateTimezone("Asia/Singapore");361 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');362 // Replace with your Google Maps URL... Or Test the Microsoft one...363 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');364 const response = await page.goto(url, {365 waitUntil: 'networkidle2',366 // timeout: 0367 }); // Define the Maps URL to Scrape...368 console.log('waiting for selector');369 await page.waitFor(3000);370 try {371 const result = await page.evaluate(() => { // Let's create variables and store values...372 let imagesClasses = document.querySelectorAll('a.iusc');373 let images = {374 'images': []375 }376 for (let elements of imagesClasses) {377 images['images'].push(elements.getAttribute('m'));378 }379 return images;380 });381 return result;382 } catch (err) {383 console.error(err);384 return null;385 process.exit(1);386 } finally {387 await page.close();388 await browser.close();389 }390 };391 scrape().then((value) => { // Scrape and output the results...392 res.send(value); // Yay, output the Results...393 });394})395app.get('/bing-news', (req, res) => {396 // Access the provided 'page' and 'limt' query parameters397 let url = req.query.url;398 let scrape = async () => { // Prepare scrape...399 const browser = await puppeteer.launch({400 // headless: false, //enable only when on localServer401 headless: true,402 ignoreDefaultArgs: ["--enable-automation"],403 ignoreHTTPSErrors: true,404 args: [405 '--no-sandbox',406 '--disable-setuid-sandbox',407 '--disable-accelerated-2d-canvas',408 '--no-zygote',409 '--renderer-process-limit=1',410 '--no-first-run',411 '--disable-dev-shm-usage',412 '--single-process', // <- this one doesn't works in Windows413 '--disable-gpu'414 ],415 }); // Prevent non-needed issues for *NIX416 const page = await browser.newPage(); // Create request for the new page to obtain...417 await page.setViewport({418 width: 2000,419 height: 1000,420 });421 // await page.emulateTimezone("Asia/Singapore");422 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');423 // Replace with your Google Maps URL... Or Test the Microsoft one...424 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');425 const response = await page.goto(url, {426 waitUntil: 'networkidle2',427 // timeout: 0428 }); // Define the Maps URL to Scrape...429 console.log('waiting for selector');430 await page.waitFor(3000);431 try {432 const result = await page.evaluate(() => { // Let's create variables and store values...433 let titleClasses = document.querySelectorAll('a.title');434 let title = []435 for (let elements of titleClasses) {436 title.push(elements.textContent);437 }438 let descriptionClasses = document.querySelectorAll('div.snippet');439 let description = []440 for (let elements of descriptionClasses) {441 description.push(elements.textContent);442 }443 return {444 title,445 description446 };447 });448 return result;449 } catch (err) {450 console.error(err);451 return null;452 process.exit(1);453 } finally {454 await page.close();455 await browser.close();456 }457 };458 scrape().then((value) => { // Scrape and output the results...459 res.send(value); // Yay, output the Results...460 });461})462app.get('/bing-videos', (req, res) => {463 // Access the provided 'page' and 'limt' query parameters464 let url = req.query.url;465 let scrape = async () => { // Prepare scrape...466 const browser = await puppeteer.launch({467 // headless: false, //enable only when on localServer468 headless: true,469 ignoreDefaultArgs: ["--enable-automation"],470 ignoreHTTPSErrors: true,471 args: [472 '--no-sandbox',473 '--disable-setuid-sandbox',474 '--disable-accelerated-2d-canvas',475 '--no-zygote',476 '--renderer-process-limit=1',477 '--no-first-run',478 '--disable-dev-shm-usage',479 '--single-process', // <- this one doesn't works in Windows480 '--disable-gpu'481 ],482 }); // Prevent non-needed issues for *NIX483 const page = await browser.newPage(); // Create request for the new page to obtain...484 await page.setViewport({485 width: 2000,486 height: 1000,487 });488 // await page.emulateTimezone("Asia/Singapore");489 // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');490 // Replace with your Google Maps URL... Or Test the Microsoft one...491 //await page.goto('https://www.google.com/maps/place/Microsoft/@36.1275216,-115.1728651,17z/data=!3m1!5s0x80c8c416a26be787:0x4392ab27a0ae83e0!4m7!3m6!1s0x80c8c4141f4642c5:0x764c3f951cfc6355!8m2!3d36.1275216!4d-115.1706764!9m1!1b1');492 const response = await page.goto(url, {493 waitUntil: 'networkidle0',494 // timeout: 0495 }); // Define the Maps URL to Scrape...496 console.log('waiting for selector');497 await page.waitFor(3000);498 try {499 const result = await page.evaluate(() => { // Let's create variables and store values...500 let videosClasses = document.querySelectorAll('div.vrhdata');501 let videos = []502 for (let elements of videosClasses) {...
emulation.spec.js
Source:emulation.spec.js
...150 it('should work', async({page, server}) => {151 page.evaluate(() => {152 globalThis.date = new Date(1479579154987);153 });154 await page.emulateTimezone('America/Jamaica');155 expect(await page.evaluate(() => date.toString())).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');156 await page.emulateTimezone('Pacific/Honolulu');157 expect(await page.evaluate(() => date.toString())).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');158 await page.emulateTimezone('America/Buenos_Aires');159 expect(await page.evaluate(() => date.toString())).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');160 await page.emulateTimezone('Europe/Berlin');161 expect(await page.evaluate(() => date.toString())).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');162 });163 it('should throw for invalid timezone IDs', async({page, server}) => {164 let error = null;165 await page.emulateTimezone('Foo/Bar').catch(e => error = e);166 expect(error.message).toBe('Invalid timezone ID: Foo/Bar');167 await page.emulateTimezone('Baz/Qux').catch(e => error = e);168 expect(error.message).toBe('Invalid timezone ID: Baz/Qux');169 });170 });...
emulate_timezone.js
Source:emulate_timezone.js
...15 // set viewport and user agent (just in case for nice viewing)16 await page.setViewport({width: 1920, height: 1080});17 await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');18 // America/New_York19 await page.emulateTimezone('America/New_York');20 // emulate to Asia/Makassar a.k.a GMT+821 //await page.emulateTimezone('Asia/Makassar');22 // go to the web23 //let shinycal_page = "http://localhost:6789";24 let shinycal_page = "https://rpodcast.shinyapps.io/shinycal"25 await page.goto('https://whatismytimezone.com');26 var ss = await page.screenshot({path: "screenshots/timezone_america_new_york_screenshot.png"});27 await page.goto(shinycal_page);28 await page.waitForTimeout(9000);29 var ss = await page.screenshot({path: "screenshots/shinycal_america_new_york_screenshot.png"});30 // America/Chicago31 await page.emulateTimezone('America/Chicago');32 // emulate to Asia/Makassar a.k.a GMT+833 //await page.emulateTimezone('Asia/Makassar');34 // go to the web35 await page.goto('https://whatismytimezone.com');36 var ss = await page.screenshot({path: "screenshots/timezone_america_chicago_screenshot.png"});37 await page.goto(shinycal_page);38 await page.waitForTimeout(9000);39 var ss = await page.screenshot({path: "screenshots/shinycal_america_chicago_screenshot.png"});40 // America/Denver41 await page.emulateTimezone('America/Denver');42 // emulate to Asia/Makassar a.k.a GMT+843 //await page.emulateTimezone('Asia/Makassar');44 // go to the web45 await page.goto('https://whatismytimezone.com');46 var ss = await page.screenshot({path: "screenshots/timezone_america_denver_screenshot.png"});47 await page.goto(shinycal_page);48 await page.waitForTimeout(9000);49 var ss = await page.screenshot({path: "screenshots/shinycal_america_denver_screenshot.png"});50 // America/Los_Angeles51 await page.emulateTimezone('America/Los_Angeles');52 // emulate to Asia/Makassar a.k.a GMT+853 //await page.emulateTimezone('Asia/Makassar');54 // go to the web55 await page.goto('https://whatismytimezone.com');56 var ss = await page.screenshot({path: "screenshots/timezone_america_los_angeles_screenshot.png"});57 await page.goto(shinycal_page);58 await page.waitForTimeout(9000);59 var ss = await page.screenshot({path: "screenshots/shinycal_america_los_angeles_screenshot.png"});60 await page.close();61 // close the browser62 await browser.close();...
browserAction.js
Source:browserAction.js
...98step('Set timezone <arg0>', async function(arg0) {99 await evaluate(() => {100 return (globalThis.date = new Date(1479579154987));101 });102 await emulateTimezone(arg0);...
timezone.test.js
Source:timezone.test.js
...20 test("set timezone", async (done) => {21 let page = await p.newPage(`http://${TEST_APP_HOST}:3000/public/examples`);22 let examplePage = new ExamplePage(page);23 // Set the initial timezone24 await examplePage.emulateTimezone("America/Los_Angeles");25 await examplePage.reload();26 let el = await examplePage.timezoneElement();27 let zone = await el.innerText();28 expect(zone).toMatch(/GMT-0800 \(Pacific Standard Time\)|GMT-0700 \(Pacific Daylight Time\)/);29 // https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt30 // use a different timezone31 await examplePage.emulateTimezone("America/New_York");32 await examplePage.reload();33 el = await examplePage.timezoneElement();34 zone = await el.innerText();35 expect(zone).not.toMatch(/GMT-0800 \(Pacific Standard Time\)|GMT-0700 \(Pacific Daylight Time\)/);36 expect(zone).toMatch(/GMT-0500 \(Eastern Standard Time\)|GMT-0400 \(Eastern Daylight Time\)/);37 await examplePage.reload();38 el = await examplePage.timezoneElement();39 zone = await el.innerText();40 expect(zone).not.toMatch(/GMT-0800 \(Pacific Standard Time\)|GMT-0700 \(Pacific Daylight Time\)/);41 expect(zone).toMatch(/GMT-0500 \(Eastern Standard Time\)|GMT-0400 \(Eastern Daylight Time\)/);42 // reset timezone to default43 await examplePage.emulateTimezone(null);44 await examplePage.reload();45 el = await examplePage.timezoneElement();46 zone = await el.innerText();47 // this will fail if your browser is not in America/Los_Angeles48 expect(zone).toMatch(/GMT-0800 \(Pacific Standard Time\)|GMT-0700 \(Pacific Daylight Time\)/);49 done();50 });...
index.js
Source:index.js
...16 if (!url.startsWith('https://') && !url.startsWith('http://')) {17 url = 'http://' + url;18 }19 const page = await browser.newPage();20 await page.emulateTimezone('Asia/Shanghai');21 await page.goto(url, {22 'waitUntil': 'networkidle2'23 });24 let path = '/tmp/example';25 let contentType;26 if (request.queries['pdf']) {27 contentType = 'application/pdf';28 await page.pdf({29 path: path,30 displayHeaderFooter: false31 });32 } else {33 contentType = 'image/png';34 await page.screenshot({ path: path, fullPage: true, type: 'png' });...
custom-timezones.js
Source:custom-timezones.js
...8 })9 const pptr = await browser.getPuppeteer()10 const page = (await pptr.pages())[0]11 console.log((await pptr.pages()).length);12 await page.emulateTimezone('Atlantic/Bermuda')13 await browser.url('https://whatismytimezone.com')14 const timezoneContainer = (await browser.$$('article'))[0]15 console.log(await timezoneContainer.getText())16 return browser.deleteSession()17})().catch((e) => {18 console.error(e)19 return browser.deleteSession()...
jest-e2e-environment.js
Source:jest-e2e-environment.js
1const PuppeteerEnvironment = require('jest-environment-puppeteer')2class CustomEnvironment extends PuppeteerEnvironment {3 async setup() {4 await super.setup()5 await this.global.page.emulateTimezone('UTC')6 }7 async teardown() {8 // Your teardown9 await super.teardown()10 }11}...
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('America/Los_Angeles');6 await closeBrowser();7 } catch (error) {8 console.error(error);9 }10})();11const { openBrowser, goto, emulateUserAgent, closeBrowser } = require('taiko');12(async () => {13 try {14 await openBrowser();15 await emulateUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36');16 await closeBrowser();17 } catch (error) {18 console.error(error);19 }20})();21const { openBrowser, goto, emulateViewport, closeBrowser } = require('taiko');22(async () => {23 try {24 await openBrowser();25 await emulateViewport('1200x800');26 await closeBrowser();27 } catch (error) {28 console.error(error);29 }30})();31const { openBrowser, goto, emulateNetwork, closeBrowser } = require('taiko');32(async () => {33 try {34 await openBrowser();35 await emulateNetwork('Good 3G');
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('America/Los_Angeles');6 await emulateTimezone('Asia/Kolkata');7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('America/Los_Angeles');6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12const { openBrowser, goto, emulateLocation, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await emulateLocation(39.952583, -75.165222);17 } catch (e) {18 console.error(e);19 } finally {20 await closeBrowser();21 }22})();23const { openBrowser, goto, emulateNetwork, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await emulateNetwork('Offline');28 } catch (e) {29 console.error(e);30 } finally {31 await closeBrowser();32 }33})();34const { openBrowser, goto, emulateMedia, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await emulateMedia('screen', 'dark');39 } catch (e) {40 console.error(e);41 } finally {42 await closeBrowser();43 }44})();45const { openBrowser, goto, emulate, closeBrowser } = require('taiko');46(async () => {47 try {48 await openBrowser();49 await emulate({50 viewport: {51 },52 userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',53 });54 } catch (e) {
Using AI Code Generation
1const { openBrowser, emulateTimezone } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('America/Los_Angeles');6 } catch (e) {7 console.error(e);8 } finally {9 closeBrowser();10 }11})();
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('Europe/Paris');6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();12const { openBrowser, goto, emulateMedia, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await emulateMedia('screen', 'print');17 await closeBrowser();18 } catch (e) {19 console.error(e);20 } finally {21 }22})();23const { openBrowser, goto, emulateDevice, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await emulateDevice('iPhone X');28 await closeBrowser();29 } catch (e) {30 console.error(e);31 } finally {32 }33})();34const { openBrowser, goto, emulateNetwork, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await emulateNetwork('Good 3G');39 await closeBrowser();40 } catch (e) {41 console.error(e);42 } finally {43 }44})();45const { openBrowser, goto, emulate, closeBrowser } = require('taiko');46(async () => {47 try {48 await openBrowser();49 await emulate('iPhone X', 'Good 3G');50 await closeBrowser();51 } catch (e) {52 console.error(e);53 } finally {54 }55})();56const { openBrowser, goto, emulate, closeBrowser } = require('taiko');57(async () => {58 try {59 await openBrowser();60 await emulate('iPhone X', 'Good
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await emulateTimezone('America/Los_Angeles');6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();12const { openBrowser, goto, emulateUserAgent, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await emulateUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36');17 await closeBrowser();18 } catch (e) {19 console.error(e);20 } finally {21 }22})();23const { openBrowser, goto, emulateViewport, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await emulateViewport({width: 800, height: 600, deviceScaleFactor: 1, isMobile: true, hasTouch: true, isLandscape: false});28 await closeBrowser();29 } catch (e) {30 console.error(e);31 } finally {32 }33})();34const { openBrowser, goto, emulate, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await emulate({viewport: {width: 800, height: 600, deviceScaleFactor: 1, isMobile: true, hasTouch: true, isLandscape: false}, userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36', timezoneId: 'America/Los_Angeles'});39 await closeBrowser();40 } catch (e) {
Using AI Code Generation
1const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser({ headless: false });5 await emulateTimezone("Europe/London");6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();12const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser({ headless: false });16 await emulateTimezone("Europe/London");17 await closeBrowser();18 } catch (e) {19 console.error(e);20 } finally {21 }22})();23const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser({ headless: false });27 await emulateTimezone("Europe/London");28 await closeBrowser();29 } catch (e) {30 console.error(e);31 } finally {32 }33})();34const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser({ headless: false });38 await emulateTimezone("Europe/London");39 await closeBrowser();40 } catch (e) {41 console.error(e);42 } finally {43 }44})();45const { openBrowser, goto, emulateTimezone, closeBrowser } = require('taiko');46(async () => {47 try {48 await openBrowser({ headless: false });49 await emulateTimezone("Europe/London");50 await closeBrowser();51 } catch (e) {52 console.error(e);53 } finally {54 }55})();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!