How to use waitForNavigation method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Playwright_Wordpress.js

Source:Playwright_Wordpress.js Github

copy

Full Screen

...33 await page.type('#user_pass', req.body.password1);3435 await Promise.all([36 page.click('#wp-submit'),37 page.waitForNavigation({ waitUntil: 'networkidle' }),38 ]);3940 const isLoginfailed = await page.$('#login_error'). then (res =>!! res);41 if (isLoginfailed) {42 throw new Error('Username wordpress and Password wordpress is incorrect.'); 43 }4445 if (options.conten_static_pages == 'on' || options.template_url_and_url == 'on') {46 await Promise.all([47 page.click('#menu-pages'),48 page.waitForNavigation({ waitUntil: 'networkidle' }),49 ]);5051 const tagTr = await page.evaluate(() => {52 const trs = Array.from(document.querySelectorAll('#the-list tr'))53 return trs.map(tr => tr.outerHTML)54 });5556 // 7. Trong các page tĩnh có nội dung html chưa?57 for (const element of tagTr) {58 let myRegex = /^<tr id="(.*?)"/gm;59 let execId = myRegex.exec(element);60 if (execId) {61 await Promise.all([62 page.click(`#${execId[1]} .row-title`),63 page.waitForNavigation({ waitUntil: 'networkidle' }),64 ]);65 66 let contentDetail = await page.$eval('#content', item => {67 return item.textContent;68 });69 70 let title = await page.$eval('#title', item => {71 return item.value || 'not found title';72 });73 74 this.content.push({75 title: title,76 message: contentDetail ? '<span class="badge badge-success">Successfully </span>' : '<span class="badge badge-danger mr-2">error </span>'77 });7879 let img_and_a = contentDetail.match(/<img.*src=".*?">|<a.*?href=".*?">/gm) || [];8081 img_and_a.forEach(element => {82 if (/<img.*src="\[template_url]\/|<a.*href="\[url]\//gm.exec(element)) {83 this.template_url.push({84 item: element,85 message: '<span class="badge badge-success">Successfully </span>'86 });87 } else {88 this.template_url.push({89 item: element,90 message: '<span class="badge badge-danger mr-2">error </span>'91 });92 }93 });94 95 await page.goBack();96 }97 }98 }99 100 // 10. tên công ty trong phần message của contactform và link có khớp với nhau chưa?101 if (options.match_company_contactform == 'on') {102 await Promise.all([103 page.click(`#toplevel_page_wpcf7`),104 page.waitForNavigation({ waitUntil: 'networkidle' }),105 ]);106 107 await Promise.all([108 page.click(`#the-list .row-title`),109 page.waitForNavigation({ waitUntil: 'networkidle' }),110 ]);111 112 await page.click('#mail-panel-tab')113 let from = await page.$eval('#wpcf7-mail-2-sender', item => {114 return item.value || 'not found from';115 });116 117 let regexFrom = /(.*?)</gm;118 let textFrom = regexFrom.exec(from);119 if (textFrom[1]) {120 let mailBody = await page.$eval('#wpcf7-mail-2-body', item => {121 return item.textContent;122 });123 124 if (mailBody.search(textFrom[1].trim()) == -1) {125 this.fromCompany.message = `<span class="badge badge-danger mr-2">error </span>Can"t get seach ${textFrom[1].trim()} in content`;126 fromCompany.item = from;127 } else {128 this.fromCompany.message = `<span class="badge badge-success">Successfully </span>${textFrom[1].trim()}`;129 this.fromCompany.item = from;130 }131 } else {132 this.fromCompany.message = `<span class="badge badge-danger mr-2">error</span>Can't get from mail`;133 this.fromCompany.item = from;134 }135 }136 137 // message của contactform là tiếng Nhật chưa?138 // Thỉnh thoảng vẫn để tiếng Anh nên hãy chú ý."139 if (options.contactform_msg_JP == 'on') {140 await Promise.all([141 page.click(`#toplevel_page_wpcf7`),142 page.waitForNavigation({ waitUntil: 'networkidle' }),143 ]);144 145 await Promise.all([146 page.click(`#the-list .row-title`),147 page.waitForNavigation({ waitUntil: 'networkidle' }),148 ]);149150 await page.click('#messages-panel-tab');151 const messageJapan = await page.evaluate(() => {152 const list = Array.from(document.querySelectorAll('#messages-panel .description input'));153 return list.map(data => data.value);154 });155 156 messageJapan.forEach(element => {157 if (!element.match(/[ぁ-んァ-ン一-龥]/g)) {158 this.message_jp_and_en.push({159 item: element,160 message: '<span class="badge badge-danger mr-2">error </span>'161 });162 } else {163 this.message_jp_and_en.push({164 item: element,165 message: '<span class="badge badge-success">Successfully </span>'166 });167 }168 });169 }170 171 // 12.Tích hợp contactform có "reCAPTCHA" không?172 if (options.contactform_recapchar == 'on') {173 await Promise.all([174 page.click(`#toplevel_page_wpcf7`),175 page.waitForNavigation({ waitUntil: 'networkidle' }),176 ]);177 178 await Promise.all([179 page.click(`#the-list .row-title`),180 page.waitForNavigation({ waitUntil: 'networkidle' }),181 ]);182183 await Promise.all([184 page.click(`#toplevel_page_wpcf7 ul li:nth-child(4)`),185 page.waitForNavigation({ waitUntil: 'networkidle' }),186 ]);187 188 let recaptcha = await page.$eval('#recaptcha', item => {189 return item.textContent || 'not found recapchar';190 });191 192 if (recaptcha.search(/reCAPTCHA/gm)) {193 this.recapchaData.push({194 message: '<span class="badge badge-success">Successfully </span> reCAPTCHA'195 });196 } else {197 this.recapchaData.push({198 message: '<span class="badge badge-danger mr-2">error </span>'199 });200 }201 }202 203 // 9. Không hiển thị các tag chưa đc phân loại trong nội dung bài viết.204 if (options.unclassified_not_displayed == 'on') {205 await Promise.all([206 page.click(`#menu-posts`),207 page.waitForNavigation({ waitUntil: 'networkidle' }),208 ]);209 210 await Promise.all([211 page.click(`#menu-posts ul li:nth-child(4)`),212 page.waitForNavigation({ waitUntil: 'networkidle' }),213 ]);214 215 const tagTrCategories = await page.evaluate(() => {216 const trs = Array.from(document.querySelectorAll('#the-list tr'))217 return trs.map(tr => tr.textContent)218 });219 220 tagTrCategories.forEach(element => {221 if (element.toLowerCase().search('uncategorized') != -1) {222 this.categories_uncategorized.push({223 item: element,224 message: '<span class="badge badge-danger mr-2">error </span>'225 })226 } ...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...12 height:800,13 })14 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});15 await page.click('[data-testid="userTab"]');16 await page.waitForNavigation();17 await page.type('[data-testid="email"]', 'user@iamneo.ai');18 await page.type('[data-testid="password"]', 'neo');19 await page.click('[data-testid="submitButton"]');20 await page.waitForNavigation();21 await page.waitForSelector('[data-testid="userNavbar"]',{timeout:1500});22 await page.click('[data-testid="userLogoutButton"]');23 await page.waitForNavigation();24 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});25 await page.click('[data-testid="adminTab"]');26 await page.type('[data-testid="email', 'admin@iamneo.ai"]');27 await page.type('[data-testid="password"]', 'neo');28 await page.click('[data-testid="submitButton"]');29 await page.waitForNavigation();30 await page.waitForSelector('[data-testid="adminNavbar"]',{timeout:1500});31 await page.click('[data-testid="adminLogoutButton"]');32 await page.waitForNavigation();33 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});34 console.log('TESTCASE:test_case6:success');35 }36 catch(e){37 console.log('TESTCASE:test_case6:failure');38 }finally{39 await page.close();40 await browser.close();41 }42 })();43//user workflow testcase44 (async () => {45 const browser = await puppeteer.launch();46 const page = await browser.newPage();47 try {48 await page.goto('https://8081-adfaaffabfbbeffacfefaffeafcdbeeafffede.examlyiopb.examly.io/login');49 await page.goto('https://8081-eebeafbcddaeffffacfefaffeafcdbeeafffede.examlyiopb.examly.io/login');50 await page.setViewport({51 width:1200,52 height:800,53 })54 55 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});56 await page.click('[data-testid="userTab"]');57 await page.waitForNavigation();58 await page.type('[data-testid="email"]', 'user@iamneo.ai');59 await page.type('[data-testid="password"]', 'neo');60 await page.click('[data-testid="submitButton"]');61 await page.waitForNavigation();62 await page.waitForSelector('[data-testid="userNavbar"]',{timeout:1500});63 await page.click('[data-testid="userDashboardLink"]');64 await page.waitForNavigation();65 await page.waitForSelector('[data-testid="userDashboard"]',{timeout:1500});66 await page.click('[data-testid="userProfileLink"]');67 await page.waitForNavigation();68 await page.waitForSelector('[data-testid="userProfileBody"]',{timeout:1500});69 await page.click('[data-testid="userBookingLink"]');70 await page.waitForSelector('[data-testid="userBookingBody"]');71 await page.click('[data-testid="userLogoutButton"]');72 await page.waitForNavigation();73 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});74 console.log('TESTCASE:test_case7:success');75 } catch(e) {76 console.log('TESTCASE:test_case7:failure');77 }finally{78 await page.close();79 await browser.close();80 }81 })();82//admin workflow testcase83 (async () => {84 const browser = await puppeteer.launch();85 const page = await browser.newPage();86 try {87 await page.goto('https://8081-adfaaffabfbbeffacfefaffeafcdbeeafffede.examlyiopb.examly.io/login');88 await page.goto('https://8081-eebeafbcddaeffffacfefaffeafcdbeeafffede.examlyiopb.examly.io/login');89 await page.setViewport({90 width:1200,91 height:800,92 })93 94 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});95 await page.click('[data-testid="adminTab"]');96 await page.waitForNavigation();97 await page.type('[data-testid="email"]', 'admin@iamneo.ai');98 await page.type('[data-testid="password"]', 'neo');99 await page.click('[data-testid="submitButton"]');100 await page.waitForNavigation();101 await page.waitForSelector('[data-testid="adminNavbar"]',{timeout:1500});102 await page.click('[data-testid="adminDashboardLink"]');103 await page.waitForNavigation();104 await page.waitForSelector('[data-testid="adminDashboard"]',{timeout:1500});105 await page.click('[data-testid="adminProfileLink"]');106 await page.waitForNavigation();107 await page.waitForSelector('[data-testid="adminProfile"]',{timeout:1500});108 await page.click('[data-testid="adminBookingLink"]');109 await page.waitForSelector('[data-testid="adminBookings"]');110 await page.click('[data-testid="adminLogoutButton"]');111 await page.waitForNavigation();112 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});113 console.log('TESTCASE:test_case8:success');114 } catch(e) {115 console.log('TESTCASE:test_case8:failure');116 }finally{117 await page.close();118 await browser.close();119 }120 })();121//super-admin workflow testcase122 (async () => {123 const browser = await puppeteer.launch();124 const page = await browser.newPage();125 try {126 await page.goto('https://8081-adfaaffabfbbeffacfefaffeafcdbeeafffede.examlyiopb.examly.io/superadmin/login');127 await page.goto('https://8081-eebeafbcddaeffffacfefaffeafcdbeeafffede.examlyiopb.examly.io/superadmin/login');128 await page.setViewport({129 width:1200,130 height:800,131 })132 await page.waitForNavigation();133 await page.waitForSelector('[data-testid="superAdminLoginBox"]',{timeout:1500});134 await page.type('[data-testid="email"]', 'superadmin@iamneo.ai');135 await page.type('[data-testid="password"]', 'neo');136 await page.click('[data-testid="submitButton"]');137 await page.waitForNavigation();138 await page.waitForSelector('[data-testid="superAdminNavbar"]',{timeout:1500});139 await page.click('[data-testid="superAdminDashboardLink"]');140 await page.waitForNavigation();141 await page.waitForSelector('[data-testid="allUserDetails"]',{timeout:1500});142 await page.click('[data-testid="superAdminBookingLink"]');143 await page.waitForNavigation();144 await page.waitForSelector('[data-testid="allAdminDetails"]',{timeout:1500});145 await page.click('[data-testid="adminLogoutButton"]');146 await page.waitForNavigation();147 await page.waitForSelector('[data-testid="superAdminLoginBox"]',{timeout:1500});148 console.log('TESTCASE:test_case9:success');149 } catch(e) {150 console.log('TESTCASE:test_case9:failure');151 }finally{152 await page.close();153 await browser.close();154 }155 })();156 157 //checking Authentication158 (async () => {159 const browser = await puppeteer.launch();160 const page = await browser.newPage();161 162 163 try {164 await page.goto('https://8081-adfaaffabfbbeffacfefaffeafcdbeeafffede.examlyiopb.examly.io/user/dashboard');165 await page.goto('https://8081-eebeafbcddaeffffacfefaffeafcdbeeafffede.examlyiopb.examly.io/user/dashboard');166 await page.setViewport({167 width:1200,168 height:800,169 })170 await page.waitForNavigation();171 await page.waitForSelector('[data-testid="loginBox"]',{timeout:1500});172 console.log('TESTCASE:test_case10:success');173 } catch(e) {174 console.log('TESTCASE:test_case10:failure');175 }finally{176 await page.close();177 await browser.close();178 }...

Full Screen

Full Screen

teste_compra_automatica.js

Source:teste_compra_automatica.js Github

copy

Full Screen

...67 await page.goto('https://www.lojadomecanico.com.br');68 69 // Clica no primeiro produto70 console.log('> Selecionando o primeiro produto...');71 let navigationPromise = page.waitForNavigation();72 await page.click('#js-day-offert .latest-deals-product .product-list li:first-child a', {delay: 100});73 await navigationPromise;7475 // Adiciona mais uma unidade e clica em "comprar"76 console.log('> Adicionando mais uma unidade e clicando em comprar...');77 await page.click('#form-comprar-produto button.plus-product', {delay: 100});78 await page.waitForTimeout(100);79 await page.click('#btn-comprar-product', {delay: 100});80 await page.waitForFunction("document.getElementById('cart-popup-count').innerText > 0")81 await page.waitForTimeout(500);8283 // Vai para o carrinho de compras84 console.log('> Direcionando ao carrinho de compras...');85 await page.goto('https://www.lojadomecanico.com.br/carrinho', {waitUntil: 'domcontentloaded'});86 await page.waitForSelector('a.btn-finalizar-pedido');8788 // Clica em "finalizar pedido"89 navigationPromise = page.waitForNavigation();90 await page.click('a.btn-finalizar-pedido', {delay: 100});91 await navigationPromise;92 93 // Clica no botão "criar conta"94 console.log('> Clicando em "criar conta"...');95 navigationPromise = page.waitForNavigation();96 await page.click('#form-flux-login a:last-child');97 await navigationPromise;9899 // Clica em "criar conta pessoal"100 navigationPromise = page.waitForNavigation();101 await page.click('a.standard-select:first-child');102 await navigationPromise;103104 // Preenche o formulário105 console.log('> Preenchendo formulário de cadastro...');106 await page.type('input#nome', cliente.nome, { delay: 100 });107 await page.type('input#telefone', cliente.telefone, { delay: 100 });108 await page.type('input#email', cliente.email, { delay: 100 });109 await page.type('input#password', cliente.senha, { delay: 100 });110 111 // Clica no botão "criar cadastro"112 navigationPromise = page.waitForNavigation();113 await page.click('.btn-create[type=submit]');114 await navigationPromise;115116 // // Preenche os dados do endereço117 console.log('> Preenchendo endereço...');118 await page.type('input#cep', cliente.endereco.cep, { delay: 100 });119 await page.type('input#numero', cliente.endereco.numero, { delay: 100 });120 await page.type('input#complemento', cliente.endereco.complemento, { delay: 100 });121122 // // Clica no botão "continuar" (cadastro de endereço)123 navigationPromise = page.waitForNavigation();124 await page.click('.btn-submit-form[type=submit]');125 await navigationPromise;126127 // Clica no botão "continuar" (confirmação de envio)128 console.log('> Confirmando envio...');129 navigationPromise = page.waitForNavigation();130 await page.click('div.same-day .btn-green[type=submit]');131 await navigationPromise;132133 // Clica no botão "boleto" (confirmação de pagamento)134 console.log('> Clicando em gerar boleto...');135 navigationPromise = page.waitForNavigation();136 await page.click('div.padBoleto input[type=radio]');137 await navigationPromise;138139 // // Preenche CPF para NF e clica em "continuar"140 console.log('> Preenchendo CPF para a nota fiscal...');141 await page.type('input#cpfnota', cliente.cpf, { delay: 100 });142 navigationPromise = page.waitForNavigation();143 await page.click('.btn-submit-form[type=submit]');144 await navigationPromise;145146 // // Clica no botão "finalizar pedido"147 console.log('> Clicando em "finalizar pedido"...');148 navigationPromise = page.waitForNavigation();149 await page.click('#form-save-order .botaoFinalizarBoleto');150 await navigationPromise;151152 // // Fechar popup e-bit153 await page.waitForSelector('span#btFechar');154 await page.click('span#btFechar');155156 // Pega o número do boleto157 console.log('> Extraindo número do boleto...');158 let num_boleto = await page.evaluate(() => {159 return document.getElementById('lindig')160 .innerText161 .trim()162 .replaceAll('.', '') ...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

...25 await page.goto(AMAZON_URL);26 // 検索27 // ----------------------------------28 await Promise.all([29 page.waitForNavigation({ waitUntil: 'load'}),30 await page.type('input[name="field-keywords"]', KEYWORD),31 await page.evaluate(({ }) => {32 document.querySelector("#nav-search-bar-form").submit();33 }, {})34 ]);35 // 検索条件指定36 // ----------------------------------37 // 検索条件指定 > 値段設定38 await Promise.all([39 page.waitForNavigation({ waitUntil: 'load'}),40 await page.evaluate(({ }) => {41 let e = document.querySelector('#priceRefinements > ul');42 let f = e.querySelector('li[aria-label="0-500円"]');43 let aPriceOption = f.querySelector('span > a');44 aPriceOption.click();45 }, {})46 ]);47 // 検索条件指定 > 到着日48 await Promise.all([49 page.waitForNavigation({ waitUntil: 'load'}),50 page.click("li[aria-label=明日までにお届け] > span > a")51 ]);52 // 検索結果取得53 // ----------------------------------54 let url = await page.evaluate(({ }) => {55 let resultList = document.querySelector('.s-main-slot.s-result-list');56 let list = Array.from(resultList.children);57 let items = []58 for ( const elm of list){59 // [note] href属性を持たない要素があるため場合分け60 if ( elm.querySelector('a') && elm.querySelector('a').href ) items.push( elm.querySelector('a').href );61 }62 return items[Math.floor(Math.random() * items.length)];63 }, {});64 return url;65};66const purchase = async ( page, url ) => {67 // 事前処理68 // ----------------------------------69 // ログイン情報を取得70 const loginId = process.env.AMAZON_ID;71 const loginPassword = process.env.AMAZON_PASSWORD;72 // Amazonのサイトを開く73 await page.goto(AMAZON_URL);74 // ログインページへ移動75 await Promise.all([76 page.waitForNavigation({ waitUntil: 'load'}),77 await page.evaluate(() => {78 document.querySelector(".nav-action-button").click();79 })80 ]);81 // ログイン82 // ----------------------------------83 // ID入力84 await Promise.all([85 page.waitForNavigation({ waitUntil: 'load'}),86 await page.type('input[name="email"]', loginId),87 await page.evaluate(({ }) => {88 document.querySelector("form").submit();89 }, {})90 ]);91 // パスワード入力92 await Promise.all([93 page.waitForNavigation({ waitUntil: 'load'}),94 await page.type('input[name="password"]', loginPassword),95 await page.evaluate(({ }) => {96 document.querySelector("form").submit();97 }, {})98 ]);99 // 商品ページへ移動100 // ----------------------------------101 console.log(`[Info] url${url}`);102 await Promise.all([103 page.waitForNavigation({ waitUntil: 'load'}),104 await page.goto(url)105 ]);106 // 購入直前まで107 // ----------------------------------108 // 今すぐ購入109 // await page.waitFor(3000);110 // await page.evaluate(() => {111 // document.querySelector("#buy-now-button").click(); [NOTE] 動作しません112 // });113 // カートに追加114 await page.waitFor(5000); // [note] たまに失敗するので待機する115 await Promise.all([116 page.waitForNavigation({ waitUntil: 'load'}),117 await page.evaluate(({ }) => {118 document.querySelector('#add-to-cart-button').click();119 }, {})120 ]);121 // 続行122 await Promise.all([123 page.waitForNavigation({ waitUntil: 'load'}),124 await page.evaluate(({ }) => {125 document.querySelector('#hlb-ptc-btn-native').click();126 }, {})127 ]);128 // 商品みえなくする129 await Promise.all([130 page.waitForNavigation({ waitUntil: 'load'}),131 await page.evaluate(({ }) => {132 let e = document.querySelector('#revieworder');133 e.style.display='none';134 }, {})135 ]);136 // 注文を確定する 137 // await page.waitFor(5000);138 // await page.evaluate(({ }) => {139 // document.querySelector('#spc-form').submit(); [NOTE] 動作しません140 // }, {}); 141};...

Full Screen

Full Screen

tic.js

Source:tic.js Github

copy

Full Screen

...16 let page = await browser.newPage();17 // Goes to amazon site18 await page.goto("https://www.amazon.in/gp/css/homepage.html?from=hz");19 //sign in 20 await Promise.all([page.click("#nav-link-accountList-nav-line-1"), page.waitForNavigation()]);21 await page.type(".a-input-text.a-span12.auth-autofocus.auth-required-field" , "mahici8394@w3boats.com");22 23 // search click and type password24 await Promise.all([page.click(".a-button-input"), page.waitForNavigation()]);25 await page.waitForSelector(".a-input-text.a-span12.auth-autofocus.auth-required-field");26 await page.type(".a-input-text.a-span12.auth-autofocus.auth-required-field", "mahici8394@w3boats.com");27 await Promise.all([page.click("#signInSubmit"), page.waitForNavigation()]);28 29 //search in search bar 30 await page.type("#twotabsearchtextbox","Tata Salt Lite, Low Sodium, 1kg");31 await Promise.all([page.click("#nav-search-submit-button"), page.waitForNavigation()]);32 // unique selector nhi hai 33 await Promise.all([page.click(".a-size-base-plus.a-color-base.a-text-normal")]);34 // to run in different tab35 let pages = await browser.pages();36 page = await pages[pages.length-1];37 await page.waitForSelector("#freshAddToCartButton .a-button-input",{visible :true});38 await page.evaluate(function(){39 let x = document.querySelector("#freshAddToCartButton .a-button-input");40 x.click();41 })42 43 44 // now clicked on buy again 45 await page.evaluate(function(){46 let a = document.querySelectorAll(".nav-a");47 a[6].click();48 49 })50 /51 await page.waitForNavigation();52 // //type and clicked on Aashirvaad Shudh Atta53 // await page.type("#twotabsearchtextbox","Aashirvaad Shudh Chakki Atta");54 // await Promise.all([page.click("#nav-search-submit-button"), page.waitForNavigation()]);55 // await page.evaluate(function(){56 // let a = document.querySelectorAll(".a-size-base-plus.a-color-base.a-text-normal");57 // a[0].click();58 // })59 // pages = await browser.pages();60 // page = await pages[pages.length-1];61 // await page.waitForSelector("#freshAddToCartButton-announce");62 // await Promise.all([page.click("#freshAddToCartButton-announce"), page.waitForNavigation()]);63 64 65 66 // Type Surf Excel on search bar67 await page.type("#twotabsearchtextbox","Surf Excel");68 await Promise.all([page.click("#nav-search-submit-button"), page.waitForNavigation()]);69 70 await page.waitForSelector(".a-size-base-plus.a-color-base.a-text-normal");71 await page.click(".a-size-base-plus.a-color-base.a-text-normal");72 pages = await browser.pages();73 page = await pages[pages.length-1];74 await page.waitForSelector("#freshAddToCartButton-announce", {visible:true});75 await page.click("#freshAddToCartButton-announce");76 77 78 await page.evaluate(function(){79 let buyagain = document.querySelectorAll(".nav-a");80 buyagain[6].click();81 })82 await page.waitForNavigation();83 await page.type("#twotabsearchtextbox", "Colgate Max Fresh");84 await Promise.all([page.click("#nav-search-submit-button"), page.waitForNavigation()]);85 await page.waitForSelector(".a-size-base-plus.a-color-base.a-text-normal");86 await page.click(".a-size-base-plus.a-color-base.a-text-normal");87 pages = await browser.pages();88 page = await pages[pages.length-1];89 await page.waitForSelector("#a-autoid-0-announce"); 90 91 await page.click("#a-autoid-0-announce"); 92 await page.click("#nav-cart-count");93 94 95 }96 97 catch(err)98 {...

Full Screen

Full Screen

puppeteer.js

Source:puppeteer.js Github

copy

Full Screen

...5 await page.goto('http://12.0.0.2:3000/');6// await page.screenshot({path: './screenshots/accueil.png'});7 await page.type('#searchalbum', 'album_mer');8 await Promise.all([9 page.waitForNavigation(),10 page.click('#btnsearch')11 ]);12// await page.screenshot({path: './screenshots/album_mer.png'});13 await page.click('#img3');14// await page.screenshot({path: './screenshots/img3.png'});15 //l'utilisateur retourne à la page d'accueil16 await page.goto('http://12.0.0.2:3000/');17 //il choisit un autre album18 await page.type('#searchalbum', 'album_montagne');19 await Promise.all([20 page.waitForNavigation(),21 page.click('#btnsearch')22 ]);23// await page.screenshot({path: './screenshots/album_montagne.png'});24 await page.click('#delete');25 await page.type('#searchalbum', 'album_montagne');26 await Promise.all([27 page.waitForNavigation(),28 page.click('#btnsearch')29 ]);30// await page.screenshot({path: './screenshots/album_not_found.png'});31 await page.click('#addalbum');32 await page.type('#id', 'album_montagne');33 await page.type('#titre', 'Montagne Album');34 await page.type('#description', 'The most beautiful mountains on earth');35 await page.type('#photo1', '/images/montagne/montagne1.jpg');36 await page.type('#photo2', '/images/montagne/montagne2.jpg');37 await page.type('#photo3', '/images/montagne/montagne3.jpg');38 await page.type('#photo4', '/images/montagne/montagne4.jpg');39 //await page.screenshot({path: './screenshots/addalbum_desert.png'});40 await Promise.all([41 page.waitForNavigation(),42 page.click('#submit')43 ]);44 await page.type('#searchalbum', 'album_montagne');45 await Promise.all([46 page.waitForNavigation(),47 page.click('#btnsearch')48 ]);49// await page.screenshot({path: './screenshots/album_desert.png'});50/*51 //proba52 function getRandomArbitrary(min, max) { //valeur de max est exclue53 return Math.random() * (max - min) + min;54 }55 // ajoute un album avec une proba 1/1056 if(getRandomArbitrary(1, 11)==1){57 await page.click('#addalbum');58 await page.type('#id', 'album_desert');59 await page.type('#titre', 'Desert Album');60 await page.type('#description', 'The most beautiful deserts on earth');61 await page.type('#photo1', '/images/desert/desert1.jpg');62 await page.type('#photo2', '/images/desert/desert2.jpg');63 await page.type('#photo3', '/images/desert/desert3.jpg');64 await page.type('#photo4', '/images/desert/desert4.jpg');65 await page.screenshot({path: './screenshots/addalbum_desert.png'});66 await Promise.all([67 page.waitForNavigation(),68 page.click('#submit')69 ]);70 await page.type('#searchalbum', 'album_desert');71 await Promise.all([72 page.waitForNavigation(),73 page.click('#btnsearch')74 ]);75 await page.screenshot({path: './screenshots/album_desert.png'});76}77// supprime un album avec une proba 1/1078if(getRandomArbitrary(1, 11)==1){79//l'utilisateur retourne à la page d'accueil80await page.goto('http://12.0.0.2:3000/');81//il choisit un autre album82await page.type('#searchalbum', 'album_montagne');83await Promise.all([84 page.waitForNavigation(),85 page.click('#btnsearch')86]);87await page.screenshot({path: './screenshots/album_montagne.png'});88await page.click('#delete');89await page.type('#searchalbum', 'album_montagne');90await Promise.all([91 page.waitForNavigation(),92 page.click('#btnsearch')93]);94await page.screenshot({path: './screenshots/album_not_found.png'});95}96if(getRandomArbitrary(1, 11)!=1 || getRandomArbitrary(1, 11)!=2){97 await page.goto('http://12.0.0.2:3000/');98 await page.screenshot({path: './screenshots/accueil.png'});99 await page.type('#searchalbum', 'album_mer');100 await Promise.all([101 page.waitForNavigation(),102 page.click('#btnsearch')103 ]);104 await page.screenshot({path: './screenshots/album_mer.png'});105 await page.click('#img3');106 await page.screenshot({path: './screenshots/img3.png'});107}108*/109 await browser.close();...

Full Screen

Full Screen

router_history.test.js

Source:router_history.test.js Github

copy

Full Screen

...15 assert.equal(await page.evaluate(() => document.getElementById('foo').textContent), 'FOO')16 assert.equal(await page.evaluate(() => document.getElementById('bar').textContent), 'BAR')17 await Promise.all([18 page.click('a.about'),19 page.waitForNavigation(),20 ])21 title = await page.evaluate(() => document.title)22 assert.equal(title, 'About | Example App')23 await Promise.all([24 page.click('a.books'),25 page.waitForNavigation(),26 ])27 title = await page.evaluate(() => document.title)28 assert.equal(title, 'BookList | Example App')29 await Promise.all([30 page.click('a.api'),31 page.waitForNavigation(),32 ])33 title = await page.evaluate(() => document.title)34 assert.equal(title, 'API Documents | Example App')35 await Promise.all([36 page.click('a.user'),37 page.waitForNavigation(),38 ])39 title = await page.evaluate(() => document.title)40 assert.equal(title, 'User/someone | Example App')41 await Promise.all([42 page.click('a.book'),43 page.waitForNavigation(),44 ])45 title = await page.evaluate(() => document.title)46 assert.equal(title, 'Book5 | Example App')47 await Promise.all([48 page.click('a.usertimeline'),49 page.waitForNavigation(),50 ])51 title = await page.evaluate(() => document.title)52 assert.equal(title, 'UserTimeline/someone | Example App')53// await sleep(10) // wait redirect54 await Promise.all([55 page.click('a.readers'),56 page.waitForNavigation(),57 ])58 title = await page.evaluate(() => document.title)59 assert.equal(title, 'Book3 | Example App') // books/360 await Promise.all([61 page.click('a.reader'),62 page.waitForNavigation(),63 ])64 title = await page.evaluate(() => document.title)65 assert.equal(title, 'BookReader id:3 reader:tom | Example App')66 await Promise.all([67 page.click('a.docs'),68 page.waitForNavigation(),69 ])70 title = await page.evaluate(() => document.title)71 assert.equal(title, 'Documents | Example App')72 await Promise.all([73 page.click('a.summary'),74 page.waitForNavigation(),75 ])76 title = await page.evaluate(() => document.title)77 assert.equal(title, 'BookSummary 5 | Example App')78 await Promise.all([79 page.click('a.home'),80 page.waitForNavigation(),81 ])82 title = await page.evaluate(() => document.title)83 assert.equal(title, 'Home | Example App')84 assert.equal(await page.evaluate(() => document.getElementById('foo').textContent), 'FOOC')85 assert.equal(await page.evaluate(() => document.getElementById('bar').textContent), 'NULL')86 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...7 await page.goto('https://www.instagram.com',{waitUntil:'networkidle2'});8 await page.type("input[name='username']",data.user,{delay:100});9 await page.type("input[name='password']",data.password,{delay:100});10 await Promise.all([11 page.waitForNavigation({waitUntil:"networkidle2"}),12 page.click("button[type='submit']")13 ]);14 await page.type("input[placeholder='Search']","priyavrat17");15 await page.waitForSelector("._01UL2 .fuqBx a",{visible:true});16 await Promise.all([17 page.waitForNavigation({waitUntil:"networkidle2"}),18 page.click("._01UL2 .fuqBx a")19]);20await page.waitForSelector("._9AhH0",{visible:true});21await Promise.all([22 page.waitForNavigation({waitUntil:"networkidle2"}),23 page.click("._9AhH0"),24]);25let i=0;26do{27 await page.waitForSelector(".fr66n button");28 await page.click(".fr66n button");29 await Promise.all([30 page.waitForNavigation({waitUntil:"networkidle2"}),31 page.click("._65Bje.coreSpriteRightPaginationArrow"),32]);33i++;34}while(i<noOfPost){35}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForNavigation();7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.waitForNavigation();15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch();20 const page = await browser.newPage();21 await page.waitForNavigation();22 await browser.close();23})();24const { Builder, By, Key, until } = require('selenium-webdriver');25(async function example() {26 let driver = await new Builder().forBrowser('chrome').build();27 await driver.wait(until.titleIs('Google'), 1000);28 await driver.quit();29})();30describe('webdriver.io page', () => {31 it('should have the right title', () => {32 browser.getTitle().should.be.equal('Google');33 });34});35test('My first test', async t => {36 .typeText('#developer-name', 'John Smith')37 .click('#submit-button')38 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');39});40describe('My First Test', function() {41 it('Does not do much!', function() {42 })43})44describe('angularjs homepage', function() {45 it('should greet the named user', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.click('text=Click me');6 await page.screenshot({ path: 'screenshot.png' });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const page = await browser.newPage();13 await page.click('text=Click me');14 await page.screenshot({ path: 'screenshot.png' });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const page = await browser.newPage();21 await page.click('text=Click me');22 await page.screenshot({ path: 'screenshot.png' });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const page = await browser.newPage();29 await page.click('text=Click me');30 await page.screenshot({ path: 'screenshot.png' });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { waitForNavigation } = require('playwright/internal');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.fill('input[aria-label="Search"]','Playwright');8 await page.click('input[value="Google Search"]');9 await waitForNavigation(page);10 await browser.close();11})();12const { Page } = require('playwright/lib/server/page');13const { helper } = require('playwright/lib/helper');14Page.prototype.waitForNavigation = async function(options = {}) {15 return await helper.waitForEvent(this, Page.Events.Navigation, options);16};17const { helper } = require('./helper');18class Page {19 static Events = {20 Navigation: Symbol('Navigation')21 };22 async goto(url, options = {}) {23 const { timeout = this._timeoutSettings.navigationTimeout() } = options;24 await this._delegate.goto(url, options);25 await helper.waitForEvent(this, Page.Events.Navigation, { timeout });26 }27}28class Helper {29 static waitForEvent(emitter, eventName, options = {}) {30 const { timeout = 30000 } = options;31 return new Promise((fulfill, reject) => {32 const timeoutId = setTimeout(onTimeout, timeout);33 const listener = (...args) => {34 clearTimeout(timeoutId);35 emitter.removeListener(eventName, listener);36 fulfill(...args);37 };38 emitter.on(eventName, listener);39 function onTimeout() {40 emitter.removeListener(eventName, listener);41 reject(new Error('Timeout while waiting for event'));42 }43 });44 }45}46class Chromium {47 async launch(options = {}) {48 const browser = await this._launcher.launch(options);49 return new ChromiumBrowser(browser, options);50 }51}52class ChromiumBrowser {53 constructor(browser, options = {}) {54 this._browser = browser;55 this._options = options;56 }57 async newContext(options = {}) {58 const context = await this._browser.newContext(options);59 return new ChromiumBrowserContext(context, this._options);60 }61}

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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

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