Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace OpenQA.Selenium.Firefox
public sealed class FirefoxDriverService : DriverService
{
private const string DefaultFirefoxDriverServiceFileName = "geckodriver";
private string logPath = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="FirefoxDriverService"/> class.
Expand Down Expand Up @@ -121,6 +122,15 @@ protected override bool HasShutdown
get => false;
}

/// <summary>
/// Gets or sets the path to which service logging should be written.
/// </summary>
public string LogPath
{
get { return this.logPath; }
set { this.logPath = value; }
}

/// <summary>
/// Gets the command-line arguments for the driver service.
/// </summary>
Expand All @@ -138,7 +148,12 @@ protected override string CommandLineArguments
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " --websocket-port {0}", PortUtilities.FindFreePort()));
}

if (this.BrowserCommunicationPort > 0)
if (!string.IsNullOrEmpty(this.logPath))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " --log \"{0}\"", this.logPath));
}

if (this.browserCommunicationPort > 0)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --marionette-port {0}", this.BrowserCommunicationPort);
}
Expand Down
63 changes: 63 additions & 0 deletions dotnet/test/firefox/FirefoxDriverServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using NUnit.Framework;
using OpenQA.Selenium.Firefox;
using System;
using System.IO;

namespace OpenQA.Selenium.Firefox
{
[TestFixture]
public class FirefoxDriverServiceTests
{
private string tempFileName;

[SetUp]
public void Setup()
{
tempFileName = Path.GetTempFileName();
File.Delete(tempFileName);
}

[TearDown]
public void Teardown()
{
if (File.Exists(tempFileName))
{
File.Delete(tempFileName);
}
}

[Test]
public void CanSetLogPath()
{
var service = FirefoxDriverService.CreateDefaultService();
service.LogPath = tempFileName;

Assert.That(service.LogPath, Is.EqualTo(tempFileName), "LogPath should be set correctly");

string commandLineArgs = service.CommandLineArguments;
Assert.That(commandLineArgs, Contains.Substring($"--log \"{tempFileName}\""),
"Command line arguments should contain the log path");
}

[Test]
public void LogFileIsCreatedWhenDriverStarts()
{
var service = FirefoxDriverService.CreateDefaultService();
service.LogPath = tempFileName;

service.Start();

try
{
Assert.That(File.Exists(tempFileName), Is.True, "Log file should be created when service starts");

string logContent = File.ReadAllText(tempFileName);
Assert.That(logContent, Is.Not.Empty, "Log file should contain content");
}
finally
{
service.Dispose();
}
}
}
}
37 changes: 37 additions & 0 deletions dotnet/test/firefox/FirefoxDriverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,43 @@ public void ShouldInstallAndUninstallUnSignedDirAddon()
Assert.That(driver.FindElements(By.Id("webextensions-selenium-example")).Count, Is.Zero);
}

[Test]
public void ShouldBeAbleToLogToFile()
{
string tempFileName = Path.GetTempFileName();
try
{
File.Delete(tempFileName);
FirefoxOptions options = new FirefoxOptions();
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.LogPath = tempFileName;

IWebDriver firefox = new FirefoxDriver(service, options);
firefox.Url = xhtmlTestPage;
Assert.That(firefox.Title, Is.EqualTo("XHTML Test Page"));

firefox.Quit();

Assert.That(File.Exists(tempFileName), Is.True, "Log file should exist");
string logContent = File.ReadAllText(tempFileName);
Assert.That(logContent, Is.Not.Empty, "Log file should not be empty");
}
finally
{
if (File.Exists(tempFileName))
{
File.Delete(tempFileName);
}
}
}

[Test]
public void LogPathShouldBeNullByDefault()
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
Assert.That(service.LogPath, Is.Empty);
}

private string GetPath(string name)
{
string sCurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
Expand Down