You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test('example',async({ page })=>{awaitpage.goto('http://example.com')awaitpage.screenshot({path: `before.png`,})awaitpage.evaluate(()=>{consth1Element=document.querySelector('h1')if(h1Element){h1Element.innerHTML='Overwritten BY Playwright!'}})awaitpage.screenshot({path: `after.png`,})})
結果
書き換え前の画像
書き換え後の画像
公式説明
Playwright scripts run in your Playwright environment. Your page scripts run in the browser page environment. Those environments don't intersect, they are running in different virtual machines in different processes and even potentially on different computers.
The page.evaluate() API can run a JavaScript function in the context of the web page and bring results back to the Playwright environment. Browser globals like window and document can be used in evaluate.
Playwrightのテストでどうしても直接DOM操作をする必要がある場合は、出来るようだ
テストファイルの例
結果
書き換え前の画像
書き換え後の画像
公式説明
https://playwright.dev/docs/evaluating
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ
プロフィール・経歴
https://github.com/YumaInaura/YumaInaura
The text was updated successfully, but these errors were encountered: