0

When running a ScriptCS .CSX script, is there a way to get the location of the current script file?

Sean Kearon
  • 10,987
  • 13
  • 77
  • 93

1 Answers1

1

Okay, so you can access that using Env.ScriptPath from inside your CSX script.

The test below shows that in action, and can be found here.

[Scenario]
public static void ScriptPathIsSet(ScenarioDirectory directory, string output)
{
    var scenario = MethodBase.GetCurrentMethod().GetFullName();

    "Given a script which accesses Env.ScriptPath"
        .f(() => directory = ScenarioDirectory.Create(scenario)
            .WriteLine("foo.csx", "Console.WriteLine(Env.ScriptPath)"));

    "When I execute the script"
        .f(() => output = ScriptCsExe.Run("foo.csx", directory));

    "Then the ScriptPath is displayed"
        .f(() => output.ShouldContain("foo.csx"));
}
Sean Kearon
  • 10,987
  • 13
  • 77
  • 93