Skip to content

Commit c96813f

Browse files
committed
[dotnet] Remove JSON serialization from riverOptions.ToString()
1 parent 62aa0e5 commit c96813f

File tree

6 files changed

+90
-2
lines changed

6 files changed

+90
-2
lines changed

dotnet/src/webdriver/DriverOptions.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Globalization;
25-
using System.Text.Json;
25+
using System.Text;
2626

2727
namespace OpenQA.Selenium
2828
{
@@ -396,7 +396,36 @@ public void SetLoggingPreference(string logType, LogLevel logLevel)
396396
/// <returns>A string representation of this <see cref="DriverOptions"/>.</returns>
397397
public override string ToString()
398398
{
399-
return JsonSerializer.Serialize(this.ToDictionary(), new JsonSerializerOptions { WriteIndented = true });
399+
StringBuilder builder = new StringBuilder();
400+
bool needComma = false;
401+
402+
string browserName = this.BrowserName;
403+
if (!string.IsNullOrEmpty(browserName))
404+
{
405+
builder.Append("Browser: ").Append(browserName);
406+
407+
string browserVersion = this.BrowserVersion;
408+
if (!string.IsNullOrEmpty(browserVersion))
409+
{
410+
builder.Append(' ');
411+
builder.Append(browserVersion);
412+
}
413+
414+
needComma = true;
415+
}
416+
417+
string platformName = this.PlatformName;
418+
if (!string.IsNullOrEmpty(platformName))
419+
{
420+
if (needComma)
421+
{
422+
builder.Append(", ");
423+
}
424+
425+
builder.Append("Platform: ").Append(platformName);
426+
}
427+
428+
return builder.ToString();
400429
}
401430

402431
/// <summary>

dotnet/test/chrome/ChromeSpecificTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ public void RunAfterAnyTests()
3131
EnvironmentManager.Instance.CloseCurrentDriver();
3232
EnvironmentManager.Instance.WebServer.Stop();
3333
}
34+
35+
[Test]
36+
public void ChromeOptionsToString()
37+
{
38+
var options = new ChromeOptions();
39+
options.BrowserVersion = "128";
40+
options.PlatformName = "windows";
41+
Assert.That(options.ToString(), Is.EqualTo("Browser: chrome 128, Platform: windows"));
42+
}
3443
}
3544
}

dotnet/test/edge/EdgeSpecificTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,27 @@
1818
// </copyright>
1919

2020
using NUnit.Framework;
21+
using OpenQA.Selenium.Environment;
2122

2223
namespace OpenQA.Selenium.Edge
2324
{
2425
[TestFixture]
2526
public class EdgeSpecificTests : DriverTestFixture
2627
{
28+
[OneTimeTearDown]
29+
public void RunAfterAnyTests()
30+
{
31+
EnvironmentManager.Instance.CloseCurrentDriver();
32+
EnvironmentManager.Instance.WebServer.Stop();
33+
}
34+
35+
[Test]
36+
public void EdgeOptionsToString()
37+
{
38+
var options = new EdgeOptions();
39+
options.BrowserVersion = "128";
40+
options.PlatformName = "windows";
41+
Assert.That(options.ToString(), Is.EqualTo("Browser: MicrosoftEdge 128, Platform: windows"));
42+
}
2743
}
2844
}

dotnet/test/firefox/FirefoxDriverTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ public void ShouldInstallAndUninstallUnSignedDirAddon()
366366
Assert.That(driver.FindElements(By.Id("webextensions-selenium-example")).Count, Is.Zero);
367367
}
368368

369+
[Test]
370+
public void FirefoxOptionsToString()
371+
{
372+
var options = new FirefoxOptions();
373+
options.BrowserVersion = "128";
374+
options.PlatformName = "windows";
375+
Assert.That(options.ToString(), Is.EqualTo("Browser: firefox 128, Platform: windows"));
376+
}
377+
369378
private string GetPath(string name)
370379
{
371380
string sCurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

dotnet/test/ie/IeSpecificTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ public void TestInvisibleZOrder()
360360
element.Click();
361361
}
362362

363+
//[Test]
364+
public void InternetExplorerOptionsToString()
365+
{
366+
var options = new InternetExplorerOptions();
367+
368+
Assert.That(options.ToString(), Is.EqualTo("Browser: internet explorer, Platform: windows"));
369+
}
370+
363371
private long GetScrollTop()
364372
{
365373
return (long)((IJavaScriptExecutor)driver).ExecuteScript("return document.body.scrollTop;");

dotnet/test/safari/SafariSpecificTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,28 @@
1818
// </copyright>
1919

2020
using NUnit.Framework;
21+
using OpenQA.Selenium.Environment;
2122

2223
namespace OpenQA.Selenium.Safari
2324
{
2425
[TestFixture]
2526
public class SafariSpecificTests : DriverTestFixture
2627
{
28+
[OneTimeTearDown]
29+
public void RunAfterAnyTests()
30+
{
31+
EnvironmentManager.Instance.CloseCurrentDriver();
32+
EnvironmentManager.Instance.WebServer.Stop();
33+
}
34+
35+
[Test]
36+
public void SafariOptionsToString()
37+
{
38+
var options = new SafariOptions();
39+
40+
options.BrowserVersion = "5.1.7";
41+
options.PlatformName = "macos";
42+
Assert.That(options.ToString(), Is.EqualTo("Browser: safari 5.1.7, Platform: macos"));
43+
}
2744
}
2845
}

0 commit comments

Comments
 (0)