Location of the script file in ScriptCS

234 Views Asked by At

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

1

There are 1 best solutions below

0
Sean Kearon On

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"));
}