Skip to content

Commit

Permalink
Disable log methods for .NET in the case of a spec-compliant driver
Browse files Browse the repository at this point in the history
When calling driver.Manage().Logs.AvailableLogTypes for a driver that
implements the W3C WebDriver Specification (where there is no
corresponding end point), the bindings would throw a
NullReferenceException, because the command does not exist in the
command repository for spec-compliant remote ends. With this commit,
the .NET bindings will not even attempt the remote call for spec-
compliant sessions, returning empty lists instead. Fixes issue #5842.
  • Loading branch information
jimevans committed Dec 12, 2018
1 parent 06047fc commit 1156fbc
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions dotnet/src/webdriver/Remote/RemoteLogs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="RemoteLogs.cs" company="WebDriver Committers">
// <copyright file="RemoteLogs.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand Down Expand Up @@ -45,13 +45,16 @@ public ReadOnlyCollection<string> AvailableLogTypes
get
{
List<string> availableLogTypes = new List<string>();
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null);
object[] responseValue = commandResponse.Value as object[];
if (responseValue != null)
if (!driver.IsSpecificationCompliant)
{
foreach (object logKind in responseValue)
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null);
object[] responseValue = commandResponse.Value as object[];
if (responseValue != null)
{
availableLogTypes.Add(logKind.ToString());
foreach (object logKind in responseValue)
{
availableLogTypes.Add(logKind.ToString());
}
}
}

Expand All @@ -68,19 +71,22 @@ public ReadOnlyCollection<string> AvailableLogTypes
public ReadOnlyCollection<LogEntry> GetLog(string logKind)
{
List<LogEntry> entries = new List<LogEntry>();
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("type", logKind);
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetLog, parameters);

object[] responseValue = commandResponse.Value as object[];
if (responseValue != null)
if (!driver.IsSpecificationCompliant)
{
foreach (object rawEntry in responseValue)
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("type", logKind);
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetLog, parameters);

object[] responseValue = commandResponse.Value as object[];
if (responseValue != null)
{
Dictionary<string, object> entryDictionary = rawEntry as Dictionary<string, object>;
if (entryDictionary != null)
foreach (object rawEntry in responseValue)
{
entries.Add(LogEntry.FromDictionary(entryDictionary));
Dictionary<string, object> entryDictionary = rawEntry as Dictionary<string, object>;
if (entryDictionary != null)
{
entries.Add(LogEntry.FromDictionary(entryDictionary));
}
}
}
}
Expand Down

0 comments on commit 1156fbc

Please sign in to comment.