Skip to content

Commit

Permalink
All Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
budcribar committed Feb 23, 2024
1 parent cd7d35d commit af188e7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/RemoteBlazorWebView.Wpf/BlazorWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public override string HostPage
// Set a default Markup if necessary
if (ServerUri != null && Id != Guid.Empty && string.IsNullOrEmpty(markup))
Markup = RemoteWebView.RemoteWebView.GenMarkup(ServerUri, Id);


// Default to the http server
if (GrpcBaseUri == null)
GrpcBaseUri = ServerUri;

SetValue(HostPageProperty, value);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/RemoteWebView/RemoteWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ public static void Restart(IBlazorWebView blazorWebView)
{
if (BlazorWebView.ServerUri == null) return null;

// Default to the http server
if (BlazorWebView.GrpcBaseUri == null)
BlazorWebView.GrpcBaseUri = BlazorWebView.ServerUri;

PingIntervalSeconds = BlazorWebView.PingIntervalSeconds;

if (client == null)
Expand Down
49 changes: 34 additions & 15 deletions testassets/NUnitTestProject/TestBlazorWpfControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
using System.IO;
using System.Linq.Expressions;
using System.Windows.Controls;
using System.Diagnostics;
using PeakSWC.RemoteWebView;
using Grpc.Net.Client;
using System.Threading.Channels;

namespace WebdriverTestProject
{
Expand Down Expand Up @@ -155,7 +159,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => {

webView.Id = Guid.NewGuid();
webView.ServerUri = new System.Uri("https://localhost:5001");
webView.GrpcBaseUri = new System.Uri("https://localhost:5002");
//webView.GrpcBaseUri = new System.Uri("https://localhost:5002");

webView.HostPage = @"wwwroot\index.html";

Expand Down Expand Up @@ -184,16 +188,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => {
webView.Id = Guid.NewGuid();
webView.ServerUri = new System.Uri("https://localhost:5001");
webView.HostPage = @"wwwroot\index.html";
try
{
webView.Group = "group";
}
catch (Exception)
{


}

webView.Group = "group";
});
}

Expand Down Expand Up @@ -329,7 +324,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => {

webView.Id = Guid.NewGuid();
webView.ServerUri = new System.Uri("https://localhost:5001");
webView.GrpcBaseUri = new System.Uri("https://localhost:5002");
//webView.GrpcBaseUri = new System.Uri("https://localhost:5002");
webView.EnableMirrors = true;
webView.HostPage = @"wwwroot\index.html";

Expand All @@ -353,7 +348,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => {

webView.Id = Guid.NewGuid();
webView.ServerUri = new System.Uri("https://localhost:5001");
webView.GrpcBaseUri = new System.Uri("https://localhost:5002");
webView.GrpcBaseUri = new System.Uri("https://localhost:5001");
webView.EnableMirrors = true;
webView.PingIntervalSeconds = 33;
webView.Group = "group";
Expand All @@ -363,11 +358,34 @@ await Application.Current.Dispatcher.InvokeAsync(() => {
});
}

public static Process process;
public TestContext? TestContext { get; set; }

[ClassInitialize]
public static void Initialize(TestContext testContext)
{
public static async Task InitializeAsync(TestContext testContext)
{
string grpcUrl = @"https://localhost:5001/";
GrpcChannel? channel;
string? envVarValue = Environment.GetEnvironmentVariable(variable: "Rust");
if (envVarValue != null)
grpcUrl = @"https://localhost:5002/";

channel = GrpcChannel.ForAddress(grpcUrl);
process = Utilities.StartServer();

for (int i = 0; i < 10; i++)
{
// Wait for server to spin up
try
{
var ids = new WebViewIPC.WebViewIPCClient(channel).GetIds(new Empty());
Assert.AreEqual(0, ids.Responses.Count, "Server has connections at startup");
break;
}
catch (Exception) { }
await Task.Delay(1000);
}

BlazorWebViewFactory.Window = BlazorWebViewFactory.CreateBlazorWindow();

string directoryPath = @"."; // Specify the directory path
Expand Down Expand Up @@ -397,6 +415,7 @@ public static void Initialize(TestContext testContext)
public static void Cleanup()
{
BlazorWebViewFactory.Shutdown();
process?.Kill();
}
}
}
2 changes: 1 addition & 1 deletion testassets/NUnitTestProject/TestLocalBlazorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Setup()

try
{
Log.Handlers.Add(new FileLogHandler(Path.Combine(Path.GetDirectoryName(binary) ?? "", "Selenium.log")));
//Log.Handlers.Add(new FileLogHandler(Path.Combine(Path.GetDirectoryName(binary) ?? "", "Selenium.log")));
Log.SetLevel(LogEventLevel.Trace);

driver = new EdgeDriver(options);
Expand Down
2 changes: 1 addition & 1 deletion testassets/NUnitTestProject/TestServerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override async Task TestClient(int num)
var totalBytesRead = response.ConnectionResponses.Sum(x => x.TotalBytesRead);

Assert.AreEqual(24 * num, totalFilesRead, "Failed on total files read");
Assert.AreEqual(1251746 * num, totalBytesRead, "Failed on total bytes read"); // This will vary depending on the size of the Javascript
Assert.AreEqual(1251832 * num, totalBytesRead, "Failed on total bytes read"); // This will vary depending on the size of the Javascript
Console.WriteLine($"TotalBytesRead {totalBytesRead}");
Console.WriteLine($"TotalReadTime {totalReadTime}");

Expand Down
2 changes: 1 addition & 1 deletion testassets/NUnitTestProject/TestServerWpf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override async Task TestClient(int num)
var totalBytesRead = response.ConnectionResponses.Sum(x => x.TotalBytesRead);

Assert.AreEqual(24 * num, totalFilesRead, "Failed on total files read");
Assert.AreEqual(1251848 * num, totalBytesRead, "Failed on total bytes read");
Assert.AreEqual(1251992 * num, totalBytesRead, "Failed on total bytes read");
Console.WriteLine($"TotalBytesRead {totalBytesRead}");
Console.WriteLine($"TotalReadTime {totalReadTime}");

Expand Down

0 comments on commit af188e7

Please sign in to comment.