Best JavaScript code snippet using puppeteer
jiwu.test.js
Source:jiwu.test.js
...21}22describe('http://www.jiwu.com', () => {23 it('YL1-åºååæ¢', async () => {24 await page.goto('http://nj.jiwu.com/');25 const ele = await page.waitForXPath(26 '/html/body/header/div[2]/div[1]/div[3]',27 );28 await ele.click();29 await page.waitForNavigation();30 expect(page.url()).toBe('http://www.jiwu.com/');31 await screenshotPage(page);32 });33 it('YL2-åºåäºä¸çº§åç»æç¹å»', async () => {34 await page.goto('http://www.jiwu.com/');35 const ele = await page.waitForXPath('/html/body/div[4]/dl[1]/dd[1]/a[1]');36 const url = await (await ele.getProperty('href')).jsonValue();37 await ele.click();38 await page.waitForNavigation();39 expect(page.url()).toBe(url);40 await screenshotPage(page);41 });42 it('YL3-ä»·æ ¼æ»è§æ°æ®', async () => {43 const page = await browser.newPage();44 await page.goto('http://nj.jiwu.com/fangjia/');45 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]`);46 await ele.screenshot({47 path: getPath(getCaseName()),48 });49 });50 it('YL4-ä»·æ ¼æ»è§ææ¡', async () => {51 const page = await browser.newPage();52 await page.goto('http://nj.jiwu.com/fangjia/');53 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[1]`);54 await ele.screenshot({55 path: getPath(getCaseName()),56 });57 });58 it('YL5-ä»·æ ¼æ»è§ä»·æ ¼åå¨æé®', async () => {59 const page = await browser.newPage();60 await page.goto('http://nj.jiwu.com/fangjia/');61 const ele = await page.waitForXPath(62 `/html/body/div[5]/div[1]/div[1]/div[3]`,63 );64 await ele.click();65 await page.$('.pop-box');66 await screenshotPage(page, false);67 });68 it('YL6-æ¿ä»·èµ°å¿å¾', async () => {69 const page = await browser.newPage();70 await page.goto('http://nj.jiwu.com/fangjia/');71 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[2]`);72 await page.waitForTimeout(500);73 await ele.screenshot({74 path: getPath(getCaseName()),75 });76 });77 it('YL7-æ¿ä»·èµ°å¿å¾é¼ æ 移å¨', async () => {78 const page = await browser.newPage();79 await page.goto('http://nj.jiwu.com/fangjia/');80 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[2]`);81 const box = await ele.boundingBox();82 await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);83 await page.waitForTimeout(500);84 await ele.screenshot({85 path: getPath(getCaseName()),86 });87 });88 it('YL8-æ¿ä»·èµ°å¿å¾å¹´ä»½åæ¢', async () => {89 const page = await browser.newPage();90 await page.goto('http://nj.jiwu.com/fangjia/');91 const button = await page.waitForXPath(92 `/html/body/div[5]/div[1]/div[2]/div[2]/a[2]`,93 );94 await button.click();95 await page.waitForTimeout(500);96 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[2]`);97 await ele.screenshot({98 path: getPath(getCaseName()),99 });100 });101 it('YL9-æ¿ä»·å°å¾æ°æ¿ç»è®¡', async () => {102 const page = await browser.newPage();103 await page.goto('http://nj.jiwu.com/fangjia/');104 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[2]`);105 const box = await ele.boundingBox();106 await page.waitForTimeout(500);107 await page.mouse.click(box.x + box.width / 2 + 30, box.y + box.height - 10);108 await page.waitForTimeout(500);109 await ele.screenshot({110 path: getPath(getCaseName()),111 });112 });113 it('YL10-æ¿ä»·å°å¾äºææ¿ç»è®¡', async () => {114 const page = await browser.newPage();115 await page.goto('http://nj.jiwu.com/fangjia/');116 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[2]`);117 const box = await ele.boundingBox();118 await page.waitForTimeout(500);119 await page.mouse.click(box.x + box.width / 2 - 30, box.y + box.height - 10);120 await page.waitForTimeout(500);121 await ele.screenshot({122 path: getPath(getCaseName()),123 });124 });125 it('YL11-åºåæ¿ä»·æè¡æ°æ¿äºææ¿åæ¢', async () => {126 const page = await browser.newPage();127 await page.goto('http://nj.jiwu.com/fangjia/');128 const button = await page.waitForXPath(129 `/html/body/div[5]/div[1]/div[4]/div[2]/a[2]`,130 );131 await button.click();132 await page.waitForTimeout(500);133 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[4]`);134 await ele.screenshot({135 path: getPath(getCaseName()),136 });137 });138 it('YL12-åºåæ¿ä»·æè¡åºå跳转', async () => {139 const page = await browser.newPage();140 await page.goto('http://nj.jiwu.com/fangjia/');141 const button = await page.waitForXPath(142 `/html/body/div[5]/div[1]/div[4]/div[3]/div[1]/ul/li[2]/span[2]/a`,143 );144 const url = await (await button.getProperty('href')).jsonValue();145 await button.click();146 await page.waitForNavigation();147 expect(page.url()).toBe(url);148 await page.waitForTimeout(500);149 await screenshotPage(page);150 });151 it('YL13-åºåæ¿ä»·æè¡æ´å¤æé®', async () => {152 const page = await browser.newPage();153 await page.goto('http://nj.jiwu.com/fangjia/');154 const button = await page.waitForXPath(155 `/html/body/div[5]/div[1]/div[4]/div[3]/div[1]/a`,156 );157 await button.click();158 await page.waitForTimeout(100);159 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[4]`);160 await ele.screenshot({161 path: getPath(getCaseName()),162 });163 });164 it('YL14-åºåå¨å®æ¥¼çæè¡æ°æ¿äºææ¿åæ¢', async () => {165 const page = await browser.newPage();166 await page.goto('http://nj.jiwu.com/fangjia/');167 const button = await page.waitForXPath(168 `/html/body/div[5]/div[1]/div[5]/div[2]/a[2]`,169 );170 await button.click();171 await page.waitForTimeout(500);172 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[5]`);173 await ele.screenshot({174 path: getPath(getCaseName()),175 });176 });177 it('YL15-åºåå¨å®æ¥¼çæè¡åºå跳转', async () => {178 const page = await browser.newPage();179 await page.goto('http://nj.jiwu.com/fangjia/');180 const button = await page.waitForXPath(181 `/html/body/div[5]/div[1]/div[5]/div[3]/div[1]/ul/li[2]/span[2]/a`,182 );183 const url = await (await button.getProperty('href')).jsonValue();184 await button.click();185 await page.waitForNavigation();186 expect(page.url()).toBe(url);187 await page.waitForTimeout(500);188 await screenshotPage(page);189 });190 it('YL16-åºåå¨å®æ¥¼çæè¡æ´å¤æé®', async () => {191 const page = await browser.newPage();192 await page.goto('http://nj.jiwu.com/fangjia/');193 const button = await page.waitForXPath(194 `/html/body/div[5]/div[1]/div[5]/div[3]/div[1]/a`,195 );196 await button.click();197 await page.waitForTimeout(100);198 const ele = await page.waitForXPath(`/html/body/div[5]/div[1]/div[5]`);199 await ele.screenshot({200 path: getPath(getCaseName()),201 });202 });203 it('YL17-ä»·æ ¼åå¸è¶å¿å¾', async () => {204 const page = await browser.newPage();205 await page.goto('http://nj.jiwu.com/fangjia/');206 const ele = await page.waitForXPath('/html/body/div[5]/div[1]/div[6]');207 await page.waitForTimeout(500);208 await ele.screenshot({209 path: getPath(),210 });211 });212 it('YL18-ä»·æ ¼åå¸æ°æ¿äºææ¿åæ¢', async () => {213 const page = await browser.newPage();214 await page.goto('http://nj.jiwu.com/fangjia/');215 const ele = await page.waitForXPath('/html/body/div[5]/div[1]/div[6]');216 const button = await page.waitForXPath(217 '/html/body/div[5]/div[1]/div[6]/div[2]/a[2]',218 );219 await button.click();220 await page.waitForTimeout(500);221 await ele.screenshot({222 path: getPath(),223 });224 });225 it('YL19-äºææ¿æ交信æ¯å±ç¤ºæ°æ®', async () => {226 const page = await browser.newPage();227 await page.goto('http://nj.jiwu.com/fangjia/');228 const ele = await page.waitForXPath('/html/body/div[5]/div[1]/div[7]');229 await ele.screenshot({230 path: getPath(),231 });232 });233 it('YL20-äºææ¿æ交信æ¯æ¥çæ´å¤è·³è½¬', async () => {234 const page = await browser.newPage();235 await page.goto('http://nj.jiwu.com/fangjia/');236 const button = await page.waitForXPath(237 '/html/body/div[5]/div[1]/div[7]/div[1]/a',238 );239 await button.click();240 await page.waitForNavigation();241 await screenshotPage(page);242 });243 it('YL21-äºææ¿æ交信æ¯ç¿»é¡µ', async () => {244 const page = await browser.newPage();245 await page.goto('http://nj.jiwu.com/jilu/');246 const button = await page.waitForXPath('//*[@id="pagination"]/div/a[4]');247 await button.click();248 await page.waitForNavigation();249 await screenshotPage(page);250 });251 it('YL22-æ¿äº§å¿«è®¯', async () => {252 const page = await browser.newPage();253 await page.goto('http://nj.jiwu.com/fangjia/');254 const ele = await page.waitForXPath('/html/body/div[5]/div[2]/div[1]');255 await ele.screenshot({256 path: getPath(),257 });258 });259 it('YL23-æ¿äº§å¿«è®¯é¼ æ 移å¨é«äº®', async () => {260 const page = await browser.newPage();261 await page.goto('http://nj.jiwu.com/fangjia/');262 const ele = await page.waitForXPath('/html/body/div[5]/div[2]/div[1]');263 const button = await page.waitForXPath(264 '/html/body/div[5]/div[2]/div[1]/ul/li[1]/a',265 );266 const box = await button.boundingBox();267 await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);268 await ele.screenshot({269 path: getPath(),270 });271 });272 it('YL24-æ¿äº§å¿«è®¯ç¹å»è·³è½¬', async () => {273 const page = await browser.newPage();274 await page.goto('http://nj.jiwu.com/fangjia/');275 const button = await page.waitForXPath(276 '/html/body/div[5]/div[2]/div[1]/ul/li[1]/a',277 );278 const url = await (await button.getProperty('href')).jsonValue();279 await page.goto(url);280 await screenshotPage(page);281 });282 it('YL25-ä¼éæ°æ¿ææ¡', async () => {283 const page = await browser.newPage();284 await page.goto('http://nj.jiwu.com/fangjia/');285 const ele = await page.waitForXPath('/html/body/div[5]/div[2]/div[2]');286 await ele.screenshot({287 path: getPath(),288 });289 });290 it('YL26-ä¼éæ°æ¿æ¥çå
¨å±', async () => {291 const page = await browser.newPage();292 await page.goto('http://nj.jiwu.com/fangjia/');293 const button = await page.waitForXPath(294 '/html/body/div[5]/div[2]/div[2]/div/a',295 );296 await button.click();297 await page.waitForNavigation();298 await screenshotPage(page);299 });300 it('YL27-ä¼éæ°æ¿è¯¦ç»é¡µ', async () => {301 const page = await browser.newPage();302 await page.goto('http://nj.jiwu.com/fangjia/');303 const button = await page.waitForXPath(304 '/html/body/div[5]/div[2]/div[2]/ul/li[1]/a',305 );306 const url = await (await button.getProperty('href')).jsonValue();307 await page.goto(url);308 await screenshotPage(page);309 });310 it('YL28-ä¼éæ°æ¿è¯¦æ
页缩ç¥å¾', async () => {311 const page = await browser.newPage();312 await page.goto('http://nj.jiwu.com/fangjia/');313 const button = await page.waitForXPath(314 '/html/body/div[5]/div[2]/div[2]/ul/li[1]/a',315 );316 const url = await (await button.getProperty('href')).jsonValue();317 await page.goto(url);318 const thumb = await page.waitForXPath(319 `//*[@id="lpan_banner"]/div[2]/div[3]`,320 );321 await thumb.screenshot({322 path: getPath(),323 });324 });325 it('YL29-ä¼éæ°æ¿è¯¦æ
页缩ç¥å¾ç¹å»åæ¢', async () => {326 const page = await browser.newPage();327 await page.goto('http://nj.jiwu.com/fangjia/');328 const button = await page.waitForXPath(329 '/html/body/div[5]/div[2]/div[2]/ul/li[1]/a',330 );331 const url = await (await button.getProperty('href')).jsonValue();332 await page.goto(url);333 const thumbButton = await page.waitForXPath(334 `//*[@id="lpan_banner"]/div[2]/div[3]/ul/li[2]/img`,335 );336 await thumbButton.click();337 const ele = await page.waitForXPath(`//*[@id="lpan_banner"]`);338 await ele.screenshot({339 path: getPath(),340 });341 });342 it('YL30-ä¼éäºææ¿ææ¡', async () => {343 const page = await browser.newPage();344 await page.goto('http://nj.jiwu.com/fangjia/');345 const ele = await page.waitForXPath('/html/body/div[5]/div[2]/div[3]');346 await ele.screenshot({347 path: getPath(),348 });349 });350 it('YL31-ä¼éäºææ¿æ¥çå
¨é¨', async () => {351 const page = await browser.newPage();352 await page.goto('http://nj.jiwu.com/fangjia/');353 const button = await page.waitForXPath(354 '/html/body/div[5]/div[2]/div[3]/div/a',355 );356 await button.click();357 await page.waitForNavigation();358 await screenshotPage(page);359 });360 it('YL32-ä¼éäºææ¿è¯¦ç»é¡µ', async () => {361 const page = await browser.newPage();362 await page.goto('http://nj.jiwu.com/fangjia/');363 const button = await page.waitForXPath(364 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',365 );366 const url = await (await button.getProperty('href')).jsonValue();367 await page.goto(url);368 await screenshotPage(page);369 });370 it('YL33-ä¼éäºææ¿ç¼©ç¥å¾', async () => {371 const page = await browser.newPage();372 await page.goto('http://nj.jiwu.com/fangjia/');373 const button = await page.waitForXPath(374 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',375 );376 const url = await (await button.getProperty('href')).jsonValue();377 await page.goto(url);378 const thumb = await page.waitForXPath(`//*[@id="imgs-box"]/div[2]/div[2]`);379 await thumb.screenshot({380 path: getPath(),381 });382 });383 it('YL34-ä¼éäºææ¿è¯¦æ
页缩ç¥å¾ç¹å»åæ¢', async () => {384 const page = await browser.newPage();385 await page.goto('http://nj.jiwu.com/fangjia/');386 const button = await page.waitForXPath(387 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',388 );389 const url = await (await button.getProperty('href')).jsonValue();390 await page.goto(url);391 const thumbButton = await page.waitForXPath(392 `//*[@id="imgs-box"]/div[2]/div[2]/div/ul/li[2]/a/img`,393 );394 await thumbButton.click();395 // çå¾
effect ææ396 await page.waitForTimeout(200);397 const ele = await page.waitForXPath(398 '/html/body/div[3]/div[1]/div[2]/div[1]/div[1]/div',399 );400 await ele.screenshot({401 path: getPath(),402 });403 });404 it('YL35-ä¼éäºææ¿å
³æ³¨æ¿æº', async () => {405 const page = await browser.newPage();406 await page.goto('http://nj.jiwu.com/fangjia/');407 const link = await page.waitForXPath(408 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',409 );410 const url = await (await link.getProperty('href')).jsonValue();411 await page.goto(url);412 const button = await page.waitForXPath(413 '/html/body/div[3]/div[1]/div[1]/div[2]/span[1]/a',414 );415 await button.click();416 const modal = await page.$('.pop-wrap');417 const title = await page.evaluate(418 (ele) => ele.textContent,419 await modal.$('.tit'),420 );421 await screenshotPage(page, false);422 expect(title).toBe('å
³æ³¨æ¿æº');423 });424 it('YL36-ä¼éäºææ¿è·ååºä»·', async () => {425 const page = await browser.newPage();426 await page.goto('http://nj.jiwu.com/fangjia/');427 const link = await page.waitForXPath(428 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',429 );430 const url = await (await link.getProperty('href')).jsonValue();431 await page.goto(url);432 const button = await page.waitForXPath(433 '/html/body/div[3]/div[1]/div[1]/div[2]/span[2]/a',434 );435 await button.click();436 const modal = await page.$('.pop-wrap');437 const title = await page.evaluate(438 (ele) => ele.textContent,439 await modal.$('.tit'),440 );441 await screenshotPage(page, false);442 expect(title).toBe('è·ååºä»·');443 });444 it('YL37-ä¼éäºææ¿é¢çº¦çæ¿', async () => {445 const page = await browser.newPage();446 await page.goto('http://nj.jiwu.com/fangjia/');447 const link = await page.waitForXPath(448 '/html/body/div[5]/div[2]/div[3]/ul/li[1]/a',449 );450 const url = await (await link.getProperty('href')).jsonValue();451 await page.goto(url);452 const button = await page.waitForXPath(453 '/html/body/div[3]/div[1]/div[2]/div[2]/div[1]/ul[2]/li[4]/a',454 );455 await button.click();456 const modal = await page.$('.pop-wrap');457 const title = await page.evaluate(458 (ele) => ele.textContent,459 await modal.$('.tit'),460 );461 await screenshotPage(page, false);462 expect(title).toBe('é¢çº¦çæ¿');463 });464 it('YL38-ç½®ä¸ç®¡å®¶é¡¾é®ä¿¡æ¯', async () => {465 const page = await browser.newPage();466 await page.goto('http://suzhou.jiwu.com/zygj/');467 await screenshotPage(page);468 });469 it('YL39-ç½®ä¸ç®¡å®¶è·³è½¬ä¿¡æ¯è¯¦ç»é¡µ', async () => {470 const page = await browser.newPage();471 await page.goto('http://suzhou.jiwu.com/zygj/');472 const button = await page.waitForXPath(473 '/html/body/div[2]/div/div[1]/div[1]/ul/li[1]/div[1]/p[1]/a[1]',474 );475 await button.click();476 await page.waitForNavigation();477 await screenshotPage(page);478 });479 it('YL40-ç½®ä¸ç®¡å®¶å¨è¯¢æé®', async () => {480 const page = await browser.newPage();481 await page.goto('http://suzhou.jiwu.com/zygj/');482 const button = await page.waitForXPath(483 '/html/body/div[2]/div/div[1]/div[1]/ul/li[1]/div[1]/p[1]/a[1]',484 );485 await button.click();486 await page.waitForNavigation();487 const zixunButton = await page.waitForXPath(488 '/html/body/div[3]/div[1]/div[1]/div/div[1]/a',489 );490 await page.$eval('.panel-login', (ele) => {491 return ele.style.display === 'none';492 });493 await zixunButton.click();494 await page.$eval('.panel-login', (ele) => {495 return ele.style.display !== 'none';496 });497 await screenshotPage(page, false);498 });499 it('YL41-ç½®ä¸ç®¡å®¶æ»å¨æ¡ä¿¡æ¯', async () => {500 const page = await browser.newPage();501 await page.goto('http://suzhou.jiwu.com/zygj/');502 const button = await page.waitForXPath(503 '/html/body/div[2]/div/div[1]/div[1]/ul/li[1]/div[1]/p[1]/a[1]',504 );505 await button.click();506 await page.waitForNavigation();507 const dynamicInfo = await page.waitForXPath(508 '/html/body/div[3]/div[1]/div[2]/div',509 );510 await dynamicInfo.screenshot({511 path: getPath(`${getCaseName()}-æ»å¨å`),512 });513 const box = await dynamicInfo.boundingBox();514 // å±ç¤ºæ»å¨æ¡515 await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);516 // æåæ¬¡ç©ºæ ¼æ»å¨517 await Promise.all(518 [...Array(10)].map(() => {519 page.keyboard.press('Space');520 }),521 );...
authereum.js
Source:authereum.js
...33 await password[0].click()34 await password[0].type('password')35 const singIn = await authPage.$x('//span[contains(text(),"Sign in")]/parent::button')36 await singIn[0].click()37 const sendBtn = await authPage.waitForXPath('//span[contains(text(),"Send")]/ancestor::button')38 expect(sendBtn).toBeDefined()39 authPage.close()40 }, 30000)41 test('Login in Gnosis', async () => {42 console.log('Login in gnosis')43 await gnosisPage.waitForXPath("//span[contains(text(),'Accept All')]/parent::a")44 const cookies = (await gnosisPage.$x("//span[contains(text(),'Accept All')]/parent::a"))[0]45 await cookies.click()46 await gnosisPage.waitForXPath("//span[contains(text(),'Connect')]/parent::button")47 const connect = (await gnosisPage.$x("//span[contains(text(),'Connect')]/parent::button"))[0]48 await connect.click()49 await gnosisPage.waitForXPath("//div[contains(text(),'Authereum')]/parent::div")50 const authereum = (await gnosisPage.$x("//div[contains(text(),'Authereum')]/parent::div"))[0]51 await authereum.click()52 await gnosisPage.waitFor(2000)53 const authConnect = (await browser.pages())[1]54 await authConnect.waitForXPath("//span[contains(text(),'Log in')]/parent::button")55 const logInAuth = (await authConnect.$x("//span[contains(text(),'Log in')]/parent::button"))[0]56 await logInAuth.click()57 await authConnect.screenshot({path: 'after signing in authereum'})58 await authConnect.waitFor(4000)59 try {60 await authConnect.close()61 } catch (error) {}62 await gnosisPage.waitForXPath("//span[contains(text(),'Connect')]/parent::button")63 await connect.click()64 await gnosisPage.waitForXPath("//div[contains(text(),'Authereum')]/parent::div")65 await authereum.click()66 await gnosisPage.waitForXPath("//div[contains(text(),'Create new Safe')]/ancestor::a")67 const create = (await gnosisPage.$x("//div[contains(text(),'Create new Safe')]/ancestor::a"))[0]68 await create.click()69 }, 30000)70 const create_safe = sels.xpSelectors.create_safe71 test('Naming The Safe', async (done) => {72 console.log('Naming The Safe\n')73 await gnosisPage.waitForSelector(sels.cssSelectors.create_safe_name_input)74 await gnosisPage.screenshot({path: '1 Naming The Safe.png'})75 const textInp = await gnosisPage.$(sels.cssSelectors.create_safe_name_input)76 // await gnosisPage.evaluate(x=>x.click(), textInp)77 await gnosisPage.type(sels.cssSelectors.create_safe_name_input, accountsSelectors.safeNames.create_safe_name)78 const text = await gnosisPage.$eval(sels.cssSelectors.create_safe_name_input, x => x.value)79 await gnosisPage.screenshot({path: '2 Naming The Safe.png'})80 console.log('Texto escrito = ', text)81 try {82 expect(text).toMatch(accountsSelectors.safeNames.create_safe_name)83 } catch (e) {84 done(e)85 }86 await gnosisPage.waitForXPath(create_safe.start_btn)87 const strBtn = (await gnosisPage.$x(create_safe.start_btn))[0]88 await strBtn.click()89 await gnosisPage.waitForXPath("//p[contains(text(),'Your Safe will have')]")90 const infoText = await gnosisPage.evaluate(91 x => x.innerText,92 (await gnosisPage.$x("//p[contains(text(),'Your Safe will have')]"))[0]93 )94 try {95 expect(infoText).toMatch('Your Safe will have')96 await gnosisPage.screenshot({path: '3 Naming The Safe.png'})97 done()98 } catch (e) {99 await gnosisPage.screenshot({path: '3 Naming The Safe.png'})100 done(e)101 }102 // await gFunc.clickSomething(create_safe.start_btn, gnosisPage)103 // await gFunc.assertTextPresent(create_safe.required_error_input, gnosisPage, 'Required')...
detailProd.js
Source:detailProd.js
...43 const page = pages[0] 44 await page.goto(url, {waitUntil:"domcontentloaded", timeout:0}); 45 while(true){46 try {47 await page.waitForXPath("//div[contains(@class, '2v0Hgx')]") 48 await page.waitForXPath("//div[contains(@class, 'flex _3qYU_y _6Orsg5')]/div") 49 await page.waitForXPath("//div[contains(@class, '_2riwuv')]") 50 break51 } catch (error) {52 console.log("Reload")53 await page.reload({waitUntil:"domcontentloaded", timeout:0}) 54 } 55 }56 //get price product57 const priceProduct = await page.$x(`//div[contains(@class, '2v0Hgx')]`) 58 const priceTextProduct = await (await priceProduct[0].getProperty("textContent")).jsonValue() 59 //get varian product60 const varianProduct = await page.$x(`//div[contains(@class, 'flex _3qYU_y _6Orsg5')]/div`)61 const childrenElementVarian = await varianProduct[0].getProperty('children')62 const lengElementVarian = await (await childrenElementVarian.getProperty("length")).jsonValue() 63 const templateDetailProduct = {64 price :"",65 totalVarian : 0,66 varian : [],67 media : []68 } 69 templateDetailProduct.price = priceTextProduct 70 for(let i=1;i<=lengElementVarian-1;i++){71 const item = await page.$x(`//div[contains(@class, 'flex _3qYU_y _6Orsg5')]/div/div[${i}]/div`)72 const childrenButton = await item[0].getProperty('children')73 const lengChildrenVarian = await (await childrenButton.getProperty("length")).jsonValue() 74 for(let j=1;j<=lengChildrenVarian;j++){ 75 76 const obVarian = {77 name : "",78 price: "",79 image:"",80 isActive : false81 }82 const buttonVarian = await page.$x(`//div[contains(@class, 'flex _3qYU_y _6Orsg5')]/div/div[${i}]/div/button[${j}]`)83 const textButtonVarian = await (await buttonVarian[0].getProperty("textContent")).jsonValue() 84 const statusButtonVarian = await page.$x(`//div[contains(@class, 'flex _3qYU_y _6Orsg5')]/div/div[${i}]/div/button[${j}]/@aria-disabled`)85 const status = await (await statusButtonVarian[0].getProperty("value")).jsonValue() 86 await buttonVarian[0].click() 87 try {88 await page.waitForXPath("//div[contains(@class, '_3rslob _1vc1W7')]", {timeout:10000}) 89 } catch (error) {90 //error dan tidak ada image yang terambil91 } 92 93 await delay(100)94 const priceProductVarian = await page.$x(`//div[contains(@class, '2v0Hgx')]`)95 const priceVarian = await (await priceProductVarian[0].getProperty("textContent")).jsonValue()96 const itemImage = await page.$x(`//div[contains(@class, '_3rslob _1vc1W7')]`) 97 if(itemImage[0] === null || typeof itemImage[0] === "undefined") {98 image = ""99 }100 else{101 image = await itemImage[0].evaluate((element)=>{102 return element.getAttribute("style")103 }) 104 } 105 obVarian.name = textButtonVarian106 obVarian.isActive = !(status === 'true')107 obVarian.price = (!(status === 'true'))?priceVarian:'0'108 obVarian.image = parseBacgroundImage(image)109 templateDetailProduct.varian.push(obVarian)110 }111 templateDetailProduct.totalVarian = templateDetailProduct.totalVarian + lengChildrenVarian112 }113 const media = []114 const listItemMedia = await page.$x(`//div[contains(@class, '_2riwuv')]/div[1]`)115 116 await listItemMedia[0].click()117 await page.waitForXPath("//div[contains(@class, 'flex _1P7dnP')]")118 await page.waitForXPath("//div[contains(@class, '_1zceAY')]/video")119 await page.waitForXPath("//div[contains(@class, '_1jTFGt')]") 120 const listMediaImage = await page.$x("//div[contains(@class, '_1jTFGt')]")121 const childrenListMediaImage = await listMediaImage[0].getProperty('children')122 const lengListMediaImage = await (await childrenListMediaImage.getProperty("length")).jsonValue()123 for(let o=1;o<=lengListMediaImage;o++){124 const itemMediaImage = await page.$x(`//div[contains(@class, '_1jTFGt')]/div[${o}]/div[1]/div`)125 if(o === 1){126 127 await itemMediaImage[0].click()128 129 await delay(250)130 const videoMedia = await page.$x("//div[contains(@class, '_1zceAY')]/video")131 const tempVideoMediaSrc = await videoMedia[0].evaluate((element)=>{132 return element.getAttribute("src")133 }) ...
homepage-data-views.test.js
Source:homepage-data-views.test.js
...21 await page.waitForSelector('p.lead.text-center');22 await expect(page.$eval('p.lead.text-center', el => el.textContent)).to.eventually.be.equal('Loading...');23 });24 it('shows no orders message after fetch request settles', async () => {25 await page.waitForXPath(`//p[contains(., 'No orders')]`);26 await expect(page.$eval('p.lead.text-center', el => el.textContent)).to.eventually.be.equal('No orders');27 });28 it('starts off with active orders view', async () => {29 await expect(page.$eval('h2', el => el.textContent)).to.eventually.be.equal('Active Orders');30 });31 it('has a button to show historical view that does another request for orders', async () => {32 await expect(page.$eval('button.float-right', el => el.textContent)).to.eventually.be.equal('View History');33 await page.click('button.float-right');34 await expect(page.waitForXPath(`//p[contains(., 'Loading...')]`)).to.eventually.be.fulfilled;35 await expect(page.waitForXPath(`//p[contains(., 'No orders')]`)).to.eventually.be.fulfilled;36 });37 it('does not get any socket updates while on historical view and an order is created/updated', async () => {38 order = await OrderService.createOrder(createFakeParams(OrderModel.attributes, { clientId: 'order1' }));39 await page.waitFor(1000);40 await expect(page.$eval('p.lead.text-center', el => el.textContent)).to.eventually.be.equal('No orders');41 });42 it('will show the newly created order after clicking on button to show active orders view', async () => {43 await expect(page.$eval('button.float-right', el => el.textContent)).to.eventually.be.equal('View Active Orders');44 await page.click('button.float-right');45 await expect(page.waitForXPath(`//p[contains(., 'Loading...')]`)).to.eventually.be.fulfilled;46 await expect(page.waitForXPath(`//div[contains(., '${order.name}')]`)).to.eventually.be.fulfilled;47 });48 it('when another order is created, it will appear on list due socket subscription', async () => {49 order2 = await OrderService.createOrder(createFakeParams(OrderModel.attributes, { clientId: 'order2' }));50 await expect(page.waitForXPath(`//div[contains(., '${order2.name}')]`)).to.eventually.be.fulfilled;51 });52 it('still shows both orders when filter by "cooking"', async () => {53 await page.click('div.dropdown');54 await expect(page.waitForXPath(`//a[contains(., 'Cooking Now')]`)).to.eventually.be.fulfilled;55 const [button] = await page.$x(`//a[contains(., 'Cooking Now')]`);56 await button.click();57 await page.waitFor(200);58 await expect(page.$$eval('form', nodes => nodes.length)).to.eventually.be.equal(2);59 });60 it('does not show edit buttons while on active page', async () => {61 await expect(page.$$eval('button > .fa-pencil', nodes => nodes.length)).to.eventually.be.equal(0);62 });63 it('shows both of these orders with edit buttons when on history page (2nd tab)', async () => {64 // in 2nd tab, go to history section and lets edit65 await page2.click('button.float-right');66 await expect(page2.waitForXPath(`//p[contains(., 'Loading...')]`)).to.eventually.be.fulfilled;67 await page2.waitFor(1000);68 await expect(page2.$$eval('form', nodes => nodes.length)).to.eventually.be.equal(2);69 });70 it('shows edit buttons for both of these orders (2nd tab)', async () => {71 await expect(page2.$$eval('button > .fa-pencil', nodes => nodes.length)).to.eventually.be.equal(2);72 });73 it('can enter edit mode (can edit: status, destination, name)', async () => {74 await page2.click('button > .fa-pencil');75 await expect(page2.waitFor('select[name=status]')).to.eventually.be.fulfilled;76 await expect(page2.waitFor('input[name=name]')).to.eventually.be.fulfilled;77 await expect(page2.waitFor('input[name=destination]')).to.eventually.be.fulfilled;78 });79 it('has save button disabled when no changes', async () => {80 await expect(page2.$('button[disabled] > .fa-check')).to.eventually.not.be.null;81 });82 it('enables save button once a change is made', async () => {83 const selectHandle = await page2.$('select[name=status]');84 await selectHandle.select(OrderStatus.CANCELLED);85 await expect(page2.$('button:not([disabled]) > .fa-check')).to.eventually.not.be.null;86 });87 it('on save, it has new value', async () => {88 await page2.click('button > .fa-check');89 await page2.waitFor(() => !document.querySelector('select[name=status]'));90 await expect(page2.waitForXPath(`//div[contains(., '${OrderStatus.CANCELLED}')]`)).to.eventually.be.fulfilled;91 });92 it('as the order was cancelled it should have disappeared from active orders page (1st tab) (as it is currently showing "Cooking")', async () => {93 await expect(page.$$eval('form', nodes => nodes.length)).to.eventually.be.equal(1);94 });95 it('keeps just cooked for 2s', async function() {96 // select just cooked 1st tab, should have 0 results97 await page.click('div.dropdown');98 const buttonHandle = await page.waitForXPath(`//a[contains(., 'Just Cooked')]`);99 await buttonHandle.click();100 // set the withinCookedSec to 2101 const cookedWithinSecInput = await page.waitFor('#cooked-within-sec');102 cookedWithinSecInput.press('Backspace');103 cookedWithinSecInput.type('2');104 // set order 1 in 2nd tab to COOKED105 await page2.click('button > .fa-pencil');106 const selectHandle = await page2.waitFor('select[name=status]');107 await selectHandle.select(OrderStatus.COOKED);108 await page2.click('button > .fa-check');109 // it should show on 1st tab110 await expect(page.waitForXPath(`//div[contains(., '${OrderStatus.COOKED}')]`)).to.eventually.be.fulfilled;111 // after 2s it should no longer show112 await page.waitFor(2000);113 await expect(page.$x(`//div[contains(., '${OrderStatus.COOKED}')]`)).to.eventually.be.an('array').that.is.empty;114 });...
server.js
Source:server.js
...43 width: 1920,44 height: 108045 })46 // SELECCIONAR MARCA47 await page.waitForXPath('//a[@data-activates="dropdown_brands"]')48 await delay(1000);49 let brand = await page.$x('//a[@data-activates="dropdown_brands"]')50 await delay(1000);51 brand[0].click()52 await page.waitForXPath('//li[@data-content="acura"]//a')53 let selectBrand = await page.$x('//li[@data-content="acura"]//a')54 selectBrand[0].click()55 // SELECCIONAR MODELO56 await page.waitForXPath('//a[@data-activates="dropdown_models"]')57 await delay(1000);58 let model = await page.$x('//a[@data-activates="dropdown_models"]')59 await delay(1000);60 model[0].click()61 await page.waitForXPath('//li[@data-content="ilx"]//a')62 let selectModel = await page.$x('//li[@data-content="ilx"]//a')63 selectModel[0].click()64 //SELECCIONAR SUBTIPO65 await page.waitForXPath('//a[@data-activates="dropdown_subtypes"]')66 await delay(1000);67 let subtype = await page.$x('//a[@data-activates="dropdown_subtypes"]')68 await delay(1000);69 subtype[0].click()70 await page.waitForXPath('//li[@data-content="sedan"]//a')71 let selectSubtype = await page.$x('//li[@data-content="sedan"]//a')72 selectSubtype[0].click()73 // SELECCIONAR AÃO74 await page.waitForXPath('//a[@data-activates="dropdown_years"]')75 await delay(1000);76 let year = await page.$x('//a[@data-activates="dropdown_years"]')77 await delay(1000);78 year[0].click()79 await page.waitForXPath('//li[@data-content="2018"]//a')80 let selectYear = await page.$x('//li[@data-content="2018"]//a')81 selectYear[0].click()82 // SELECCIONAR UBICACION83 await page.waitForXPath('//a[@data-activates="dropdown_provinces"]')84 await delay(1000);85 let ubication = await page.$x('//a[@data-activates="dropdown_provinces"]')86 await delay(1000);87 ubication[0].click()88 await page.waitForXPath('//li[@data-content="nuevo leon"]//a')89 let selectUbication = await page.$x('//li[@data-content="nuevo leon"]//a')90 selectUbication[0].click()91 // SELECCIONAR CIUDAD92 await page.waitForXPath('//a[@data-activates="dropdown_cities"]')93 await delay(1000);94 let city = await page.$x('//a[@data-activates="dropdown_cities"]')95 await delay(1000);96 city[0].click()97 await page.waitForXPath('//li[@data-content="monterrey"]//a')98 let selectCity = await page.$x('//li[@data-content="monterrey"]//a')99 selectCity[0].click()100 101 // SELECCIONAR RECORRIDO102 await page.type("#input_recorrido", "20000")103 await delay(6000);104 // PASARLE EL PRECIO DEL USUARIO105 await page.type("#input_precio", req.body.price)106 await delay(6000);107 108 /*109 ESCRIBIR TELÃFONO110 await page.waitForXPath("//input[starts-with(@id, 'input_tel')]")111 const tel = await page.$x("//input[starts-with(@id, 'input_tel')]")112 console.log(tel)113 tel[0].type("1234567890")114 */115 116 // CONTINUAR A LA SIGUIENTE PÃGINA117 let button = await page.waitForSelector('button[class="next-button"]')118 await delay(2000);119 button.click()120 await delay(5000);121 122 // AGREGAR DESCRIPCION123 await page.waitForSelector('#input_text_area_review');124 await page.type("#input_text_area_review", req.body.description)...
bankid_helper.js
Source:bankid_helper.js
...41 const pwdLabelXPath = "//html/body/div[3]/div/main/div/div[9]/div/form/div[1]/label"; // label with text 'Personlig passord'42 const pwdLabelSelector = "body > div.full_width_height > div > main > div > div.lm_view.padding.block_vertical_center.lm_center > div > form > div.row.label > label"; // label with text 'Personlig passord'43 const pwdAnimDivXPath = "//html/body/div[3]/div/main/div/div[7]"; // div that contains transition animation classes44 // fnr45 await innerFrame.waitForXPath(fnrLabelXPath + '[contains(string(), "Fødselsnummer")]', {visible: true});46 const fnrInputFieldId = await this.getAttributeOf(innerFrame, fnrLabelSelector, 'for');47 await innerFrame.waitForSelector('#' + fnrInputFieldId, {visible: true}); // wait for input field to be visible48 await innerFrame.type('#' + fnrInputFieldId, process.env.SP_WEB_IDPORTEN_USERNAME);49 await Promise.all([ // wait for transition animation to start and end50 innerFrame.waitForXPath(otpAnimDivXPath + "[contains(@class, 'lm_animate')]"), // animation start51 innerFrame.waitForXPath(otpAnimDivXPath + "[not(contains(@class, 'lm_animate'))]"), // animation end52 await page.keyboard.press('Enter') // trigger animation by submitting form53 ]);54 // one time password55 await innerFrame.waitForXPath(otpLabelXPath + '[contains(string(), "Engangskode")]', {visible: true});56 const otpInputFieldId = await this.getAttributeOf(innerFrame, otpLabelSelector, 'for');57 await innerFrame.waitForXPath('//*[@id="' + otpInputFieldId + '"][not(@disabled)]', {visible: true}); // wait for input field to be visible & enabled58 await innerFrame.type('#' + otpInputFieldId, process.env.SP_WEB_IDPORTEN_OTP);59 await Promise.all([ // wait for transition animation to start and end60 innerFrame.waitForXPath(pwdAnimDivXPath + "[contains(@class, 'lm_animate')]"),61 innerFrame.waitForXPath(pwdAnimDivXPath + "[not(contains(@class, 'lm_animate'))]"),62 await page.keyboard.press('Enter')63 ]);64 // password65 await innerFrame.waitForXPath(pwdLabelXPath + '[contains(string(), "Personlig passord")]', {visible: true});66 const pwdInputFieldId = await this.getAttributeOf(innerFrame, pwdLabelSelector, 'for');67 await innerFrame.waitForXPath('//*[@id="' + pwdInputFieldId + '"][not(@disabled)]', {visible: true}); // wait for input field to be visible & enabled68 await innerFrame.type('#' + pwdInputFieldId, process.env.SP_WEB_IDPORTEN_PASSWORD);69 await page.keyboard.press('Enter');70 }71}...
Bot.mjs
Source:Bot.mjs
...35 timeWait = 45000 * index36 setTimeout(async() => {37 // console.log(project.name)38 await page.goto(project.url)39 // const verifyVersion = await page.waitForXPath(`//li[contains(., "Versão")]`)40 const verifyVersion = await page.waitForSelector('ul.list')41 //ExVersão 320220421 (2.13.8) em análise42 const fullTextVersion = await page.evaluate(el => el.textContent, verifyVersion)43 // console.log({ fullTextVersion })44 if (fullTextVersion.includes(tag)) {45 console.log(`${index} - ${project.name} já foi cadastrado essa versão ;)`)46 await page.screenshot({ path: `./screenshots/${project.name}.png` })47 // timeWait = 12000 * index48 return49 }50 //caso ja foi cadastrado - carrega mais rápido51 // timeWait = 45000 * index52 const buttonRelease = await page.waitForXPath(`//button[contains(., 'versão')]`)53 await buttonRelease.click()54 const buttonEnviar = await page.waitForXPath('(//span[text()="Enviar"])[1]')55 const [fileChooser] = await Promise.all([56 page.waitForFileChooser(),57 // page.click("[name='upload']"),58 await buttonEnviar.click()59 ]);60 const appName = `${project.name}-user-${tag}.${project.extension}`61 const pathApk = `${os.homedir()}/automation/marketplace/marketplace-react/releases/${tag}/${project.name}/${appName}`62 await fileChooser.accept([pathApk]);63 await page.waitForXPath(`//div[text()="${appName}"]`, {64 timeout: 065 })66 const buttonSalvar = await page.waitForXPath(`(//div[text()="Salvar"])[1]`)67 await buttonSalvar.click()68 const buttonAvaliar = await page.waitForXPath(`(//div[text()="Avaliar versão"])[1]`)69 await buttonAvaliar.click()70 const buttonLancar = await page.waitForXPath(`//button/div[contains(., "Iniciar lançamento")]`)71 await buttonLancar.click()72 const confirmarLancamento = await page.waitForXPath(`//button[contains(., "Lançar")]`)73 await confirmarLancamento.click()74 await page.screenshot()75 console.log(`${index}${project.name} - Atualizado :)`)76 }, timeWait)77 })78 // await page.close()79 }80 // async 81 async getInfoLastTag() {82 const { data } = await axios.get(process.env.GITLAB_URL_TAG, {83 headers: {84 Authorization: `Bearer ${process.env.GITLAB_KEY}`85 }86 })...
sending_email.js
Source:sending_email.js
...8var subject = ""9When('I try to send an email.', async function () {10 // Click on write email button11 const writeEmailButtonXpath = '//*[@id="app"]/div/div[2]/div[2]/div[1]/div/div/div[1]/div[1]/div[2]/div/div/button'12 const writeEmailButton = await this.page.waitForXPath(writeEmailButtonXpath);13 await writeEmailButton.click();14 // Type in email address of Recipient15 const recipientInputXpath = '//*[@id="ReadingPaneContainerId"]/div/div/div/div[1]/div[1]/div[1]/div/div[1]/div/div[1]/div/div/div[2]/div[2]/input';16 const recipientInput = await this.page.waitForXPath(recipientInputXpath);17 await recipientInput.type(this.targetEmail);18 await this.page.keyboard.press("Enter")19 // Type in subject20 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";21 for (var i = 0; i < 5; i++) {22 subject += possible.charAt(Math.floor(Math.random() * possible.length));23 }24 const subjectInputXpath = '//*[@id="ReadingPaneContainerId"]/div/div/div/div[1]/div[1]/div[3]/div[2]/div/div/div/input';25 const subjectInput = await this.page.waitForXPath(subjectInputXpath);26 await subjectInput.type(subject);27 // Press send email button28 const sendMailButtonXpath = '//*[@id="ReadingPaneContainerId"]/div/div/div/div[1]/div[3]/div[2]/div[1]/div/span/button[1]'29 const sendMailButton = await this.page.waitForXPath(sendMailButtonXpath);30 await sendMailButton.click();31});32Then('It should appear in sent emails.', async function () {33 // Click on Sent messages tab.34 const sentMessagesButtonXpath = '//*[@id="app"]/div/div[2]/div[2]/div[1]/div/div/div[1]/div[2]/div/div[1]/div/div[2]/div[5]/div/span[1]'35 const sentMessagesButton = await this.page.waitForXPath(sentMessagesButtonXpath);36 // Delay of 5000ms should solve the problem of clicking on sent mails before outlook actually sends the mail.37 await sentMessagesButton.click({38 delay: 500039 });40 // Check if there are any email in the list and if so then check if its the last sent one and then delete all.41 const lastSentEmailSubjectXpath = '//*[@id="app"]/div/div[2]/div[2]/div[1]/div/div/div[3]/div[2]/div/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div/div/div[2]/div/div[1]/span'42 const lastSentEmailSubject = await this.page.waitForXPath(lastSentEmailSubjectXpath, {43 timeout: 500044 });45 const potentialSubject = await this.page.evaluate(async span => await span.innerText, lastSentEmailSubject);46 assert.strictEqual(potentialSubject, subject);47 // Click on the dump folder button and confirm it48 const dumpFolderButtonXpath = '//*[@id="app"]/div/div[2]/div[2]/div[1]/div/div/div[3]/div[1]/div/div/div/div/div/div[1]/div[1]/button';49 const dumpFolderButton = await this.page.waitForXPath(dumpFolderButtonXpath)50 await dumpFolderButton.click({51 delay: 100052 });53 const confirmButtonXpath = '/html/body/div[12]/div/div/div/div[2]/div[2]/div/div[2]/div[2]/div/span[1]/button';54 const confirmButton = await this.page.waitForXPath(confirmButtonXpath)55 await confirmButton.click({56 delay: 100057 });58 // Wait for deleting messages59 const noSentMessagesXpath = '//*[@id="app"]/div/div[2]/div[2]/div[1]/div/div/div[3]/div[2]/div/div[1]/div[2]/div/div/img'60 await this.page.waitForXPath(noSentMessagesXpath);...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch();10 const page = await browser.newPage();11 await page.waitForSelector('h1');12 await browser.close();13})();14const puppeteer = require('puppeteer');15(async () => {16 const browser = await puppeteer.launch();17 const page = await browser.newPage();18 await page.waitForTimeout(5000);19 await browser.close();20})();21The `waitForFunction` method waits for the function to return a truthy value. It passes the function a single argument, which is a [JSHandle](
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await browser.close();6})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({ headless: false });4 const page = await browser.newPage();5 await page.type('input[name=q]', 'puppeteer');6 await page.waitForNavigation();7 await page.screenshot({ path: 'screenshot.png' });8 await browser.close();9})();10const puppeteer = require('puppeteer');11(async () => {12 const browser = await puppeteer.launch({ headless: false });13 const page = await browser.newPage();14 await page.type('input[name=q]', 'puppeteer');15 await page.waitForSelector('input[name="btnK"]');16 await page.click('input[name="btnK"]');17 await page.waitForNavigation();18 await page.screenshot({ path: 'screenshot.png' });19 await browser.close();20})();21const puppeteer = require('puppeteer');22(async () => {23 const browser = await puppeteer.launch({ headless: false });24 const page = await browser.newPage();25 await page.type('input[name=q]', 'puppeteer');26 await page.waitFor(2000);27 await page.click('input[name="btnK"]');28 await page.waitForNavigation();29 await page.screenshot({ path: 'screenshot.png' });30 await browser.close();31})();32const puppeteer = require('puppeteer');33(async () => {34 const browser = await puppeteer.launch({ headless: false });35 const page = await browser.newPage();36 await page.type('input[name=q]', 'puppeteer');37 await page.waitFor(2000);38 await page.click('input[name="btnK"]');39 await page.waitForNavigation();40 await page.screenshot({ path: 'screenshot.png' });41 await browser.close();42})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'puppeteer.png'});6 await browser.close();7})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({4 });5 const page = await browser.newPage();6 await page.screenshot({ path: 'puppeteer.png' });7 await browser.close();8})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4async function screenshot(url, selector, filename) {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.goto(url, { waitUntil: 'networkidle2' });8 await page.waitForSelector(selector);9 await page.screenshot({ path: filename });10 await browser.close();11}12async function screenshot(url, selector, filename) {13 const browser = await puppeteer.launch();14 const page = await browser.newPage();15 await page.goto(url, { waitUntil: 'networkidle2' });16 await page.waitForSelector(selector);17 await page.screenshot({ path: filename });18 await browser.close();19}20async function screenshot(url, selector, filename) {21 const browser = await puppeteer.launch();22 const page = await browser.newPage();23 await page.goto(url, { waitUntil: 'networkidle2' });24 await page.waitForSelector(selector);25 await page.screenshot({ path: filename });26 await browser.close();27}28async function screenshot(url, selector, filename) {29 const browser = await puppeteer.launch();30 const page = await browser.newPage();31 await page.goto(url, { waitUntil: 'networkidle2' });32 await page.waitForSelector(selector);33 await page.screenshot({ path
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!!