Skip to content

Instantly share code, notes, and snippets.

@stirno
Last active December 14, 2016 13:36
Show Gist options
  • Save stirno/5138751 to your computer and use it in GitHub Desktop.
Save stirno/5138751 to your computer and use it in GitHub Desktop.
FluentAutomation test running in scriptcs (tested againt dev branch)

Instructions

  • Install nuget somewhere in your path.
  • Install scriptcs somewhere in your path.
  • Download this gist to a folder.
  • From that directory, run 'nuget install FluentAutomation.SeleniumWebDriver -o packages'
  • Then run 'scriptcs TestKnockoutJS.csx'

Comments

This could be really really good from a testing standpoint. One file per test-case, with no extra bits necessary feels awesome.

Also.. Don't forget to call I.Dispose() at the end of the script or the browser will just hang around after the test. I think we'll do some refactoring to make this a bit smarter in this context, as well as eliminate the need for the reflection in Bootstrap() in FluentAutomation.csx

using FluentAutomation;
using FluentAutomation.Interfaces;
using System;
using System.IO;
using System.Reflection;
private static INativeActionSyntaxProvider I = null;
public static void Bootstrap<T>(string browserName)
{
MethodInfo bootstrapMethod = null;
ParameterInfo[] bootstrapParams = null;
MethodInfo[] methods = typeof(T).GetMethods(BindingFlags.Static | BindingFlags.Public);
foreach (var methodInfo in methods)
{
if (methodInfo.Name.Equals("Bootstrap"))
{
bootstrapMethod = methodInfo;
bootstrapParams = methodInfo.GetParameters();
if (bootstrapParams.Length == 1) break;
}
}
var browserEnumValue = Enum.Parse(bootstrapParams[0].ParameterType, browserName);
bootstrapMethod.Invoke(null, new object[] { browserEnumValue });
I = new FluentTest().I;
// hack to move drivers into bin so they can be located by Selenium (only prob on scriptcs atm)
foreach (var driver in Directory.GetFiles(Environment.CurrentDirectory, "*.exe"))
{
var newFileName = Path.Combine(Environment.CurrentDirectory, "bin", Path.GetFileName(driver));
if (!File.Exists(newFileName)) File.Move(driver, newFileName);
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAutomation.Core" version="2.0.0.2" targetFramework="net45" />
<package id="FluentAutomation.SeleniumWebDriver" version="2.0.0.2" targetFramework="net45" />
<package id="Selenium.Support" version="2.31.2" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.31.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
</packages>
#load "FluentAutomation.csx"
Bootstrap<FluentAutomation.SeleniumWebDriver>("Chrome");
I.Open("http://knockoutjs.com/examples/cartEditor.html");
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"));
I.Dispose();
@stirno
Copy link
Author

stirno commented Mar 11, 2013

Updated to no longer suck. All dependencies load and added a hack to make the driver exe's available to the engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment