Brandon Stirnaman

FluentAutomation Creator
Simple, fluent automated testing for web applications.

F14N Founder
Fast, easy automation test creation, execution and management.

FluentAutomation + scriptcs

I first noticed scriptcs back in March '13 -- It was immediately obvious that this could be a game changer in many ways. It wasn't the first attempt at C# scripting but it had a solid group working on it and gained momentum quickly.

To test it out, I created a sample FluentAutomation test using scriptcs. I was sold. Not long after the sample made it into the scriptcs repo, Glenn Block suggested I check out the new Script Pack functionality they had added. I've been delayed on this because of a new business I have been working on with the creator of the FluentAutomation Recorder, @pzumbrun -- F14N.com -- a complete solution for automated testing. I knew that I wanted to integrate scriptcs into our business plan because it just felt like a perfect fit for tests.

Months later, the first OSS contribution from the F14N product is ready and released. We now have a proper Script Pack: ScriptCs.FluentAutomation. Combine the script pack with the F14N IDE and we have a complete scriptcs testing solution!

To get started (after installing scriptcs), create a new scriptcs directory, then:

scriptcs -install ScriptCs.FluentAutomation  
scriptcs -install FluentAutomation.SeleniumWebDriver  
del packages.config  

Then we create a new script, say test.csx, and require the Script Pack:

var Test = Require<F14N>()  
    .Config(settings => {
        // Easy access to FluentAutomation.Settings values
        settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(1);

Now we are ready to add tests:

Test.Run("KnockoutJS Cart Editor", I => {  
    I.Select("Motorcycles").From(".liveExample tr select:eq(0)"); // Select by value/text
    I.Select(2).From(".liveExample tr select:eq(1)"); // Select by index
    I.Enter(6).In(".liveExample td.quantity input:eq(0)");
    I.Expect.Text("$197.70").In(".liveExample tr span:eq(1)");

    // add second product
    I.Click(".liveExample button:eq(0)");
    I.Select(1).From(".liveExample tr select:eq(2)");
    I.Select(4).From(".liveExample tr select:eq(3)");
    I.Enter(8).In(".liveExample td.quantity input:eq(1)");
    I.Expect.Text("$788.64").In(".liveExample tr span:eq(3)");

    // validate totals
    I.Expect.Text("$986.34").In("p.grandTotal span");

    // remove first product
    I.Click(".liveExample a:eq(0)");

    // validate new total
    I.WaitUntil(() => I.Expect.Text("$788.64").In("p.grandTotal span"));

This can easily be executed from any command prompt:

scriptcs test.csx  

scriptcs test.csx

Chrome/ChromeDriver will throw some debugging information into the console but its nothing to worry about. Once the tests are all complete, you'll see:

scriptcs test.csx - Complete

or if a test fails:

scriptcs test.csx - Error

We will continue to add more features to the script pack as we use it. Next features are proper logging and better Exception print outs (reading InnerExceptions). Expect the NuGet package to be updated often and as always, feedback is welcome/desired.