Skip to content

Instantly share code, notes, and snippets.

@baronfel
Last active December 9, 2018 19:26
Show Gist options
  • Save baronfel/5667a97c0d62fbf98a7787156ab677b1 to your computer and use it in GitHub Desktop.
Save baronfel/5667a97c0d62fbf98a7787156ab677b1 to your computer and use it in GitHub Desktop.
Snippets for my F# Advent 2018 blogpost
# install the latest version of the template
dotnet new -i "MiniScaffold::*"
# create a new project with the template
dotnet new mini-scaffold -n Figurine --githubUsername baronfel -lang F#
testCase "Go to google" <| fun () ->
# create a browser
use ctx = Browser.createFromExe chromePath
# go to the url
url googleHomePage ctx
# check we went there
Expect.equal ctx.CurrentUrl googleHomePage "should have gone to google"
module Types =
type BrowserCtx =
{ /// the actual unit of work
page : Page
dispose : unit -> unit
compareTimeout : System.TimeSpan
navigateTimeout : System.TimeSpan }
member x.CurrentUrl = x.page.Url
interface IDisposable with
member x.Dispose() = x.dispose()
module Browser =
open Types
type LaunchMethod =
| Launch of LaunchOptions
| Connect of ConnectOptions
let create (method : LaunchMethod) =
let factory =
match method with
| Launch opts -> Puppeteer.LaunchAsync opts
| Connect opts -> Puppeteer.ConnectAsync opts
let b = Task.force factory
let p = b.NewPageAsync() |> Task.force
{ page = p
dispose = b.Dispose
compareTimeout = TimeSpan.FromSeconds 10.
navigateTimeout = TimeSpan.FromSeconds 30. }
let createFromExe (path : string) =
create (Launch(LaunchOptions(ExecutablePath = path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment