<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          微軟開源的Web測(cè)試和自動(dòng)化神器 Playwright

          共 1471字,需瀏覽 3分鐘

           ·

          2022-01-10 20:20


          Playwright 是微軟開源的一個(gè)用于 Web 測(cè)試和自動(dòng)化的框架, 提供了可靠的端到端測(cè)試, 功能非常強(qiáng)大, 可以在測(cè)試, 爬蟲,自動(dòng)化場(chǎng)景中使用。


          跨瀏覽器


          Playwright 支持所有現(xiàn)代的渲染引擎,包括 Chromium、WebKit 和 Firefox。



          跨平臺(tái)


          在 Windows, Linux 和 macOS 提供相同的使用體驗(yàn)。



          跨語言


          多語言支持, TypeScript, JavaScript, Python, .NET, Java.


          錄制、自動(dòng)代碼生成 、重放

          ?


          Playwright for .NET


          https://playwright.dev/dotnet/


          創(chuàng)建一個(gè)控制臺(tái)項(xiàng)目并添加 Playwright 依賴項(xiàng)


          dotnet new console -n PlaywrightDemocd PlaywrightDemodotnet add package Microsoft.Playwright dotnet build


          修改 Program.cs


          using Microsoft.Playwright;using System.Threading.Tasks;class Program{    public static async Task Main()    {        using var playwright = await Playwright.CreateAsync();        await using var browser = await playwright.Chromium.LaunchAsync();        var page = await browser.NewPageAsync();        await page.GotoAsync("https://github.com");        await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });    }}


          然后直接運(yùn)行, 程序會(huì)后臺(tái)打開 Chrome 瀏覽器, 訪問 github 并截圖保存


          dotnet run


          默認(rèn)情況下,Playwright 以無頭模式運(yùn)行瀏覽器, 要查看瀏覽器界面, 設(shè)置?Headless = false, 另外還可以設(shè)置slowMo來減慢執(zhí)行速度。


          await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions {     Headless = false,     SlowMo = 50, });


          支持運(yùn)行過程中進(jìn)行截圖


          var bytes = await page.ScreenshotAsync();


          錄制視頻


          var context = await browser.NewContextAsync(new BrowserNewContextOptions{    RecordVideoDir = "videos/"}); await context.CloseAsync();


          官網(wǎng)的文檔也很齊全,感興趣的可以關(guān)注 playwright.dev,希望對(duì)您有用!



          瀏覽 34
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  婷婷五月天丁香网 | 骚逼被操 | 色情免费观看 | 午夜黄色电影 | 人人摸操 |