#r"canopy.dll"opencanopyopenrunneropenSystem//overwrite default pathcanopy.configuration.phantomJSDir<-@".\"//start an instance of the browserstartphantomJS"taking canopy for a spin"&&&fun_->//go to urlurl"http://localhost:81/canopy/testpages/"//assert that the element with an id of 'welcome' has the text 'Welcome'"#welcome"=="Welcome"//run all testsrun()quit()

Although Selenium (which is the framework behind canopy) supports all browsers you might want to run your tests with the headless browser PhantomJS. To grab the latest version just install the NuGet package:

1:

install-packagePhantomJS

Normally canopy loads PhantomJS.exe from C:\ but in our case we want to use the installed one so we have to override the path in our test script and set the current path as location of PhantomJS.exe.

The target in FAKE basically hosts the website in IIS Express and starts the canopy tests. IIS Express requires a configuration template ("iisexpress-template.config") which can be copied from %ProgramFiles%\IIS Express\AppServer\applicationhost.config.

This sample target will require the FAKE.IIS package to be installed and referenced in your script, though the package isn't required to run Canopy tests.

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:

Target"CanopyTests"(fun_->lethostName="localhost"letport=81letconfig=createConfigFile(project,1,"iisexpress-template.config",websiteDir+"/"+project,hostName,port)letwebSiteProcess=HostWebsiteidconfig1letresult=ExecProcess(funinfo->info.FileName<-(buildDir@@"CanopyTests.exe")info.WorkingDirectory<-buildDir)(System.TimeSpan.FromMinutes5.)ProcessHelper.killProcessByIdwebSiteProcess.Idifresult<>0thenfailwith"Failed result from canopy tests")

Please note that HostWebsite starts the IIS Express process asynchronous and does NOT wait until the IIS Express successfully started. Issue #403