Skip to content

Commit b1eef5d

Browse files
Meir017kblok
authored andcommitted
Add Puppeteer.executablePath tests (#83)
1 parent 791bc65 commit b1eef5d

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.IO;
2+
using Xunit;
3+
4+
namespace PuppeteerSharp.Tests.Puppeteer
5+
{
6+
[Collection("PuppeteerLoaderFixture collection")]
7+
public class ExecutablePathTests
8+
{
9+
[Fact]
10+
public void ShouldWork()
11+
{
12+
var executablePath = PuppeteerSharp.Puppeteer.GetExecutablePath();
13+
Assert.True(File.Exists(executablePath));
14+
}
15+
}
16+
}

lib/PuppeteerSharp.Tests/TestConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class TestConstants
77
public const int HttpsPort = 8908;
88
public const string ServerUrl = "http://localhost:8907";
99
public const string HttpsPrefix = "https://localhost:8908";
10-
public const int ChromiumRevision = 526987;
10+
public const int ChromiumRevision = Downloader.DefaultRevision;
1111
public static readonly string EmptyPage = $"{ServerUrl}/empty.html";
1212

1313
public static LaunchOptions DefaultBrowserOptions() => new LaunchOptions

lib/PuppeteerSharp/Downloader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class Downloader
2121
};
2222
private string _downloadHost;
2323

24+
public const int DefaultRevision = 526987;
25+
2426
public Downloader(string downloadsFolder)
2527
{
2628
_downloadsFolder = downloadsFolder;

lib/PuppeteerSharp/Launcher.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public async Task<Browser> LaunchAsync(LaunchOptions options, int chromiumRevisi
167167
}
168168

169169
}
170-
170+
171171
public async Task TryDeleteUserDataDir(int times = 10, TimeSpan? delay = null)
172172
{
173173
if (!IsChromeClosed)
@@ -207,6 +207,13 @@ public async Task TryDeleteUserDataDir(int times = 10, TimeSpan? delay = null)
207207
}
208208
}
209209

210+
public static string GetExecutablePath()
211+
{
212+
var downloader = Downloader.CreateDefault();
213+
var revisionInfo = downloader.RevisionInfo(Downloader.CurrentPlatform, Downloader.DefaultRevision);
214+
return revisionInfo.ExecutablePath;
215+
}
216+
210217
public static string GetTemporaryDirectory()
211218
{
212219
string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
@@ -217,7 +224,7 @@ public static string GetTemporaryDirectory()
217224
#endregion
218225

219226
#region Private methods
220-
227+
221228
private Task<string> WaitForEndpoint(Process chromeProcess, int timeout, bool dumpio)
222229
{
223230
var taskWrapper = new TaskCompletionSource<string>();

lib/PuppeteerSharp/Puppeteer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
42

53
namespace PuppeteerSharp
64
{
75
public class Puppeteer
86
{
97
public static string[] DefaultArgs => Launcher.DefaultArgs;
108

9+
public static string GetExecutablePath() => Launcher.GetExecutablePath();
10+
1111
public static async Task<Browser> LaunchAsync(LaunchOptions options, int chromiumRevision)
1212
{
1313
return await new Launcher().LaunchAsync(options, chromiumRevision);

0 commit comments

Comments
 (0)