<commit_before>﻿using System;

namespace CSF.WebDriverFactory.Impl
{
  public abstract class SauceConnectWebDriverFactory : RemoteWebDriverFromEnvironmentFactory
  {
    const string
      TunnelIdCapability = "tunnel-identifier",
      UsernameCapability = "username",
      ApiKeyCapability = "accessKey",
      TestNameCapabilityName = "name",
      BuildNameCapability = "build";

    public static string TestNameCapability => TestNameCapabilityName;

    protected override void ConfigureCapabilities(OpenQA.Selenium.Remote.DesiredCapabilities caps)
    {
      base.ConfigureCapabilities(caps);

      caps.SetCapability(TunnelIdCapability, GetTunnelId());
      caps.SetCapability(UsernameCapability, GetSauceUsername());
      caps.SetCapability(ApiKeyCapability, GetSauceAccessKey());
      caps.SetCapability(BuildNameCapability, GetSauceBuildName());
    }

    protected abstract string GetTunnelId();

    protected abstract string GetSauceUsername();

    protected abstract string GetSauceAccessKey();

    protected abstract string GetSauceBuildName();
  }
}<commit_msg>Improvement to #89 - Ensures that Sauce Labs test names are populated automatically<commit_after>﻿using System;

namespace CSF.WebDriverFactory.Impl
{
  /// <summary>
  /// Web driver factory base type designed for integration with Sauce Connect by Sauce Labs:
  /// https://saucelabs.com/
  /// </summary>
  public abstract class SauceConnectWebDriverFactory : RemoteWebDriverFromEnvironmentFactory
  {
    const string
      TunnelIdCapability = "tunnel-identifier",
      UsernameCapability = "username",
      ApiKeyCapability = "accessKey",
      TestNameCapability = "name",
      BuildNameCapability = "build";

    /// <summary>
    /// Configures the capabilities desired for the current instance.
    /// </summary>
    /// <param name="caps">Caps.</param>
    protected override void ConfigureCapabilities(OpenQA.Selenium.Remote.DesiredCapabilities caps)
    {
      base.ConfigureCapabilities(caps);
      ConfigureSauceConnectCapabilities(caps);
      ConfigureSauceConnectTestName(caps);
    }

    /// <summary>
    /// Configures capabilities specific to Sauce Connect.
    /// </summary>
    /// <param name="caps">Caps.</param>
    protected virtual void ConfigureSauceConnectCapabilities(OpenQA.Selenium.Remote.DesiredCapabilities caps)
    {
      caps.SetCapability(TunnelIdCapability, GetTunnelId());
      caps.SetCapability(UsernameCapability, GetSauceUsername());
      caps.SetCapability(ApiKeyCapability, GetSauceAccessKey());
      caps.SetCapability(BuildNameCapability, GetSauceBuildName());
    }

    /// <summary>
    /// Configures the optional 'test name' Sauce Connect capability.
    /// </summary>
    /// <param name="caps">Caps.</param>
    protected virtual void ConfigureSauceConnectTestName(OpenQA.Selenium.Remote.DesiredCapabilities caps)
    {
      if(SauceTestNameCallback == null)
        return;

      var testName = SauceTestNameCallback();
      if(testName != null)
        caps.SetCapability(TestNameCapability, testName);
    }

    /// <summary>
    /// Gets the tunnel identifier.
    /// </summary>
    /// <returns>The tunnel identifier.</returns>
    protected abstract string GetTunnelId();

    /// <summary>
    /// Gets the Sauce Connect username.
    /// </summary>
    /// <returns>The sauce username.</returns>
    protected abstract string GetSauceUsername();

    /// <summary>
    /// Gets the Sauce Connect access key.
    /// </summary>
    /// <returns>The sauce access key.</returns>
    protected abstract string GetSauceAccessKey();

    /// <summary>
    /// Gets the Sauce Labs 'build name' (a name for the current test run).
    /// </summary>
    /// <returns>The sauce build name.</returns>
    protected abstract string GetSauceBuildName();

    /// <summary>
    /// An optional function/callback which provides the name of the current test scenario (the Sauce Labs 'test name').
    /// </summary>
    /// <returns>The sauce test name callback.</returns>
    public virtual Func<string> SauceTestNameCallback { get; set; }
  }
}
{'fraction_non_alphanumeric': 0.11027079775555014, 'fraction_numerical': 0.00048792388387411563, 'mean_word_length': 3.3386243386243386, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 39, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2400481', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1097, 'n_words': 271}