How to use EnsureDownloadsFolderIsDeleted method of PuppeteerSharp.Tests.LauncherTests.BrowserFetcherTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.LauncherTests.BrowserFetcherTests.EnsureDownloadsFolderIsDeleted

BrowserFetcherTests.cs

Source:BrowserFetcherTests.cs Github

copy

Full Screen

...17 private readonly string _downloadsFolder;18 public BrowserFetcherTests(ITestOutputHelper output) : base(output)19 {20 _downloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), ".test-chromium");21 EnsureDownloadsFolderIsDeleted();22 }23 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should download and extract chrome linux binary")]24 [PuppeteerFact]25 public async Task ShouldDownloadAndExtractLinuxBinary()26 {27 using var browserFetcher = Puppeteer.CreateBrowserFetcher(new BrowserFetcherOptions28 {29 Platform = Platform.Linux,30 Path = _downloadsFolder,31 Host = TestConstants.ServerUrl32 });33 var revisionInfo = browserFetcher.RevisionInfo("123456");34 Server.SetRedirect(revisionInfo.Url.Substring(TestConstants.ServerUrl.Length), "/chromium-linux.zip");35 Assert.False(revisionInfo.Local);36 Assert.Equal(Platform.Linux, revisionInfo.Platform);37 Assert.False(await browserFetcher.CanDownloadAsync("100000"));38 Assert.True(await browserFetcher.CanDownloadAsync("123456"));39 try40 {41 revisionInfo = await browserFetcher.DownloadAsync("123456");42 Assert.True(revisionInfo.Local);43 Assert.Equal("LINUX BINARY\n", File.ReadAllText(revisionInfo.ExecutablePath));44 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))45 {46#if NETCOREAPP //This will not be run on net4x anyway.47 Mono.Unix.FileAccessPermissions permissions = ConvertPermissions(LinuxSysCall.ExecutableFilePermissions);48 Assert.Equal(permissions, UnixFileSystemInfo.GetFileSystemEntry(revisionInfo.ExecutablePath).FileAccessPermissions & permissions);49#endif50 }51 Assert.Equal(new[] { "123456" }, browserFetcher.LocalRevisions());52 browserFetcher.Remove("123456");53 Assert.Empty(browserFetcher.LocalRevisions());54 //Download should return data from a downloaded version55 //This section is not in the Puppeteer test.56 await browserFetcher.DownloadAsync("123456");57 Server.Reset();58 revisionInfo = await browserFetcher.DownloadAsync("123456");59 Assert.True(revisionInfo.Local);60 Assert.Equal("LINUX BINARY\n", File.ReadAllText(revisionInfo.ExecutablePath));61 }62 finally63 {64 EnsureDownloadsFolderIsDeleted();65 }66 }67 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should download and extract firefox linux binary")]68 [PuppeteerFact]69 public async Task ShouldDownloadAndExtractFirefoxLinuxBinary()70 {71 using var browserFetcher = Puppeteer.CreateBrowserFetcher(new BrowserFetcherOptions72 {73 Platform = Platform.Linux,74 Path = _downloadsFolder,75 Host = TestConstants.ServerUrl,76 Product = Product.Firefox77 });78 var expectedVersion = "75.0a1";79 var revisionInfo = browserFetcher.RevisionInfo(expectedVersion);80 Server.SetRedirect(81 revisionInfo.Url.Substring(TestConstants.ServerUrl.Length),82 "/firefox.zip");83 Assert.False(revisionInfo.Local);84 Assert.Equal(Platform.Linux, revisionInfo.Platform);85 Assert.False(await browserFetcher.CanDownloadAsync("100000"));86 Assert.True(await browserFetcher.CanDownloadAsync(expectedVersion));87 try88 {89 revisionInfo = await browserFetcher.DownloadAsync(expectedVersion);90 Assert.True(revisionInfo.Local);91 Assert.Equal("FIREFOX LINUX BINARY\n", File.ReadAllText(revisionInfo.ExecutablePath));92 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))93 {94#if NETCOREAPP //This will not be run on net4x anyway.95 Mono.Unix.FileAccessPermissions permissions = ConvertPermissions(LinuxSysCall.ExecutableFilePermissions);96 Assert.Equal(permissions, UnixFileSystemInfo.GetFileSystemEntry(revisionInfo.ExecutablePath).FileAccessPermissions & permissions);97#endif98 }99 Assert.Equal(new[] { expectedVersion }, browserFetcher.LocalRevisions());100 browserFetcher.Remove(expectedVersion);101 Assert.Empty(browserFetcher.LocalRevisions());102 //Download should return data from a downloaded version103 //This section is not in the Puppeteer test.104 await browserFetcher.DownloadAsync(expectedVersion);105 Server.Reset();106 revisionInfo = await browserFetcher.DownloadAsync(expectedVersion);107 Assert.True(revisionInfo.Local);108 Assert.Equal("FIREFOX LINUX BINARY\n", File.ReadAllText(revisionInfo.ExecutablePath));109 }110 finally111 {112 EnsureDownloadsFolderIsDeleted();113 }114 }115#if NETCOREAPP116 private Mono.Unix.FileAccessPermissions ConvertPermissions(Helpers.Linux.FileAccessPermissions executableFilePermissions)117 {118 Mono.Unix.FileAccessPermissions output = 0;119 var map = new Dictionary<Helpers.Linux.FileAccessPermissions, Mono.Unix.FileAccessPermissions>()120 {121 {Helpers.Linux.FileAccessPermissions.OtherExecute, Mono.Unix.FileAccessPermissions.OtherExecute},122 {Helpers.Linux.FileAccessPermissions.OtherWrite, Mono.Unix.FileAccessPermissions.OtherWrite},123 {Helpers.Linux.FileAccessPermissions.OtherRead, Mono.Unix.FileAccessPermissions.OtherRead},124 {Helpers.Linux.FileAccessPermissions.GroupExecute, Mono.Unix.FileAccessPermissions.GroupExecute},125 {Helpers.Linux.FileAccessPermissions.GroupWrite, Mono.Unix.FileAccessPermissions.GroupWrite},126 {Helpers.Linux.FileAccessPermissions.GroupRead, Mono.Unix.FileAccessPermissions.GroupRead},127 {Helpers.Linux.FileAccessPermissions.UserExecute, Mono.Unix.FileAccessPermissions.UserExecute},128 {Helpers.Linux.FileAccessPermissions.UserWrite, Mono.Unix.FileAccessPermissions.UserWrite},129 {Helpers.Linux.FileAccessPermissions.UserRead, Mono.Unix.FileAccessPermissions.UserRead}130 };131 foreach (var item in map.Keys)132 {133 if ((executableFilePermissions & item) == item)134 {135 output |= map[item];136 }137 }138 return output;139 }140#endif141 private void EnsureDownloadsFolderIsDeleted()142 {143 if (Directory.Exists(_downloadsFolder))144 {145 Directory.Delete(_downloadsFolder, true);146 }147 }148 }149}...

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Threading.Tasks;4using PuppeteerSharp.Tests.Attributes;5using Xunit;6using Xunit.Abstractions;7{8 [Collection(TestConstants.TestFixtureCollectionName)]9 {10 public EnsureDownloadsFolderIsDeletedTests(ITestOutputHelper output) : base(output)11 {12 }13 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should delete downloads folder")]14 public async Task ShouldDeleteDownloadsFolder()15 {16 var downloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "downloadstest");17 var browserFetcher = new BrowserFetcher(downloadsFolder);18 var revisionInfo = browserFetcher.GetRevisionInfo(TestConstants.ChromeRevision);19 await browserFetcher.DownloadAsync(TestConstants.ChromeRevision);20 Assert.True(File.Exists(revisionInfo.ExecutablePath));21 Assert.True(Directory.Exists(downloadsFolder));22 browserFetcher.EnsureDownloadsFolderIsDeleted();23 Assert.False(Directory.Exists(downloadsFolder));24 }25 }26}27using System;28using System.IO;29using System.Threading.Tasks;30using PuppeteerSharp.Tests.Attributes;31using Xunit;32using Xunit.Abstractions;33{34 [Collection(TestConstants.TestFixtureCollectionName)]35 {36 public EnsureDownloadsFolderIsDeletedTests(ITestOutputHelper output) : base(output)37 {38 }39 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should delete downloads folder")]40 public async Task ShouldDeleteDownloadsFolder()41 {42 var downloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "downloadstest");43 var browserFetcher = new BrowserFetcher(downloadsFolder);44 var revisionInfo = browserFetcher.GetRevisionInfo(TestConstants.ChromeRevision);45 await browserFetcher.DownloadAsync(TestConstants.ChromeRevision);46 Assert.True(File.Exists(revisionInfo.ExecutablePath));47 Assert.True(Directory.Exists(downloadsFolder));48 browserFetcher.EnsureDownloadsFolderIsDeleted();49 Assert.False(Directory.Exists(downloadsFolder));50 }51 }52}

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp.Tests.Attributes;4using Xunit;5using Xunit.Abstractions;6{7 [Collection(TestConstants.TestFixtureCollectionName)]8 {9 public BrowserFetcherTests(ITestOutputHelper output) : base(output)10 {11 }12 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should download and extract platform-specific browser")]13 public async Task ShouldDownloadAndExtractPlatformSpecificBrowser()14 {15 var browserFetcher = new BrowserFetcher();16 var revisionInfo = browserFetcher.RevisionInfo(TestConstants.ChromeRevision);17 var revisionPath = revisionInfo.Local;18 var revisionInfo2 = await browserFetcher.DownloadAsync(TestConstants.ChromeRevision);19 Assert.Equal(revisionInfo, revisionInfo2);20 Assert.True(revisionInfo2.Local.EndsWith(".zip"));21 Assert.True(revisionInfo2.ExecutablePath.EndsWith("chrome.exe"));22 Assert.True(revisionInfo2.FolderPath.EndsWith("chrome-win32"));23 Assert.True(revisionInfo2.Revision == TestConstants.ChromeRevision);24 Assert.True(revisionInfo2.Revision == TestConstants.ChromeRevision);25 Assert.True(File.Exists(revisionInfo2.ExecutablePath));26 Assert.True(Directory.Exists(revisionInfo2.FolderPath));27 Assert.True(revisionInfo2.Downloaded);28 }29 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should download and extract platform-specific browser (win32)")]30 public async Task ShouldDownloadAndExtractPlatformSpecificBrowserWin32()31 {32 var browserFetcher = new BrowserFetcher();33 var revisionInfo = browserFetcher.RevisionInfo(TestConstants.ChromeRevision);34 var revisionPath = revisionInfo.Local;35 var revisionInfo2 = await browserFetcher.DownloadAsync(TestConstants.ChromeRevision);36 Assert.Equal(revisionInfo, revisionInfo2);37 Assert.True(revisionInfo2.Local.EndsWith(".zip"));38 Assert.True(revisionInfo2.ExecutablePath.EndsWith("chrome.exe"));39 Assert.True(revisionInfo2.FolderPath.EndsWith("chrome-win32"));40 Assert.True(revisionInfo2.Revision == TestConstants.ChromeRevision);41 Assert.True(revisionInfo2.Revision == Test

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Linq;4using System.Threading.Tasks;5using Xunit;6{7 [Collection("PuppeteerLoaderFixture collection")]8 {9 public async Task ShouldDownloadBrowser()10 {11 var browserFetcher = new BrowserFetcher();12 var revisionInfo = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision);13 var revisionPath = revisionInfo.Local;14 if (Directory.Exists(revisionPath))15 {16 Directory.Delete(revisionPath, true);17 }18 var progress = new Progress<double>();19 var downloadTask = browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision, progress);20 var downloadProgress = new List<double>();21 progress.ProgressChanged += (sender, e) => downloadProgress.Add(e);22 await downloadTask;23 Assert.True(Directory.Exists(revisionPath));24 Assert.True(File.Exists(Path.Combine(revisionPath, "chrome.exe")));25 Assert.True(File.Exists(Path.Combine(revisionPath, "chrome.dll")));26 Assert.True(File.Exists(Path.Combine(revisionPath, "devtools_resources.pak")));27 Assert.True(File.Exists(Path.Combine(revisionPath, "icudtl.dat")));28 Assert.True(File.Exists(Path.Combine(revisionPath, "libEGL.dll")));29 Assert.True(File.Exists(Path.Combine(revisionPath, "libGLESv2.dll")));30 Assert.True(File.Exists(Path.Combine(revisionPath, "natives_blob.bin")));31 Assert.True(File.Exists(Path.Combine(revisionPath, "snapshot_blob.bin")));32 Assert.True(File.Exists(Path.Combine(revisionPath, "v8_context_snapshot.bin")));33 Assert.True(downloadProgress.Count > 0);34 Assert.True(downloadProgress.All(progress => progress >= 0 && progress <= 1));35 }36 public async Task ShouldDownloadBrowserToCustomPath()37 {38 var browserFetcher = new BrowserFetcher();39 var revisionInfo = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision);40 var revisionPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());41 if (Directory.Exists(revisionPath))42 {43 Directory.Delete(revisionPath, true);44 }45 var progress = new Progress<double>();46 var downloadTask = browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision, progress, revisionPath);47 var downloadProgress = new List<double>();48 progress.ProgressChanged += (sender

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Threading.Tasks;4{5 {6 public async Task EnsureDownloadsFolderIsDeleted()7 {8 var downloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "download");9 Directory.CreateDirectory(downloadsFolder);10 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);11 Assert.False(Directory.Exists(downloadsFolder));12 }13 }14}15using System;16using System.IO;17using System.Threading.Tasks;18{19 {20 public async Task CreateNewContextAsync()21 {22 var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions());23 var context = await browser.CreateIncognitoBrowserContextAsync();24 var page = await context.NewPageAsync();25 await page.GoToAsync(TestConstants.EmptyPage);26 await page.EvaluateExpressionAsync("1 + 1");27 await browser.CloseAsync();28 }29 }30}31using System;32using System.IO;33using System.Threading.Tasks;34{35 {36 public async Task CreateNewContextAsync()37 {38 var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions());39 var context = await browser.CreateIncognitoBrowserContextAsync();40 var page = await context.NewPageAsync();41 await page.GoToAsync(TestConstants.EmptyPage);42 await page.EvaluateExpressionAsync("1 + 1");43 await browser.CloseAsync();44 }45 }46}47using System;48using System.IO;49using System.Threading.Tasks;50{

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6{7 {8 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should delete downloaded folder on close")]9 public async Task ShouldDeleteDownloadedFolderOnClose()10 {11 var browserFetcher = new BrowserFetcher();12 var revisionInfo = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision);13 await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);14 Assert.True(File.Exists(revisionInfo.ExecutablePath));15 Assert.True(Directory.Exists(revisionInfo.DownloadFolder));16 await browserFetcher.EnsureDownloadsFolderIsDeleted();17 Assert.False(Directory.Exists(revisionInfo.DownloadFolder));18 }19 }20}21using System;22using System.Collections.Generic;23using System.Linq;24using System.Text;25using System.Threading.Tasks;26{27 {28 [PuppeteerTest("launcher.spec.ts", "BrowserFetcher", "should delete downloaded folder on close")]29 public async Task ShouldDeleteDownloadedFolderOnClose()30 {31 var browserFetcher = new BrowserFetcher();32 var revisionInfo = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision);33 await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);34 Assert.True(File.Exists(revisionInfo.ExecutablePath));35 Assert.True(Directory.Exists(revisionInfo.DownloadFolder));36 await browserFetcher.EnsureDownloadsFolderIsDeleted();37 Assert.False(Directory.Exists(revisionInfo.DownloadFolder));38 }39 }40}41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46{47 {

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using PuppeteerSharp.Tests;7using PuppeteerSharp.Tests.LauncherTests;8{9 {10 static void Main(string[] args)11 {12 var obj = new BrowserFetcherTests();13 obj.EnsureDownloadsFolderIsDeleted();14 }15 }16}17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22using PuppeteerSharp.Tests;23using PuppeteerSharp.Tests.LauncherTests;24{25 {26 static void Main(string[] args)27 {28 var obj = new BrowserFetcherTests();29 obj.EnsureRevisionsAreDownloaded();30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using PuppeteerSharp.Tests;39using PuppeteerSharp.Tests.LauncherTests;40{41 {42 static void Main(string[] args)43 {44 var obj = new BrowserFetcherTests();45 obj.EnsureRevisionsAreNotDownloaded();46 }47 }48}49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54using PuppeteerSharp.Tests;55using PuppeteerSharp.Tests.LauncherTests;56{57 {58 static void Main(string[] args)59 {60 var obj = new BrowserFetcherTests();61 obj.EnsureRevisionIsDownloaded();62 }63 }64}

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4using PuppeteerSharp.Tests.LauncherTests;5{6 {7 static async Task Main(string[] args)8 {9 var fetcher = new BrowserFetcher();10 await fetcher.EnsureDownloadsFolderIsDeleted();11 }12 }13}14using System;15using System.Threading.Tasks;16using PuppeteerSharp;17using PuppeteerSharp.Tests.LauncherTests;18{19 {20 static async Task Main(string[] args)21 {22 var fetcher = new BrowserFetcher();23 await fetcher.EnsureDownloadsFolderIsDeleted();24 }25 }26}27using System;28using System.Threading.Tasks;29using PuppeteerSharp;30using PuppeteerSharp.Tests.LauncherTests;31{32 {33 static async Task Main(string[] args)34 {35 var fetcher = new BrowserFetcher();36 await fetcher.EnsureDownloadsFolderIsDeleted();37 }38 }39}40using System;41using System.Threading.Tasks;42using PuppeteerSharp;43using PuppeteerSharp.Tests.LauncherTests;44{45 {46 static async Task Main(string[] args)47 {48 var fetcher = new BrowserFetcher();49 await fetcher.EnsureDownloadsFolderIsDeleted();50 }51 }52}53using System;54using System.Threading.Tasks;55using PuppeteerSharp;56using PuppeteerSharp.Tests.LauncherTests;57{58 {59 static async Task Main(string[] args)60 {61 var fetcher = new BrowserFetcher();62 await fetcher.EnsureDownloadsFolderIsDeleted();63 }64 }

Full Screen

Full Screen

EnsureDownloadsFolderIsDeleted

Using AI Code Generation

copy

Full Screen

1var launcher = new PuppeteerSharp.Launcher();2await launcher.EnsureDownloadsFolderIsDeleted();3var browserFetcher = new PuppeteerSharp.BrowserFetcher();4var revisionInfo = await browserFetcher.GetRevisionInfo("123");5var browserFetcher = new PuppeteerSharp.BrowserFetcher();6var executablePath = browserFetcher.GetExecutablePath("123");7var browserFetcher = new PuppeteerSharp.BrowserFetcher();8var executablePath = browserFetcher.GetExecutablePath("123");9var browserFetcher = new PuppeteerSharp.BrowserFetcher();10var executablePath = browserFetcher.GetExecutablePath("123");11var browserFetcher = new PuppeteerSharp.BrowserFetcher();12var executablePath = browserFetcher.GetExecutablePath("123");

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer-sharp 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