How to run a Canopy test suite with xUnit?

118 Views Asked by At

I decided to use canopy framework to test my UI.

Most of the examples include either built-in assertion framework or Expecto. Which are both good choices yet I use xUnit everywhere else in the project and want to be uniform for now.

For xUnit I have found only this example but it contains just two very basic tests whereas I need to things like common code to run prior to all the tests. What would be an idiomatic way for canopy + xUnit?

1

There are 1 best solutions below

0
psfinaki On BEST ANSWER

xUnit has class fixtures and here is an example how to bring it to F# code.

Combining that with canopy scenarios, here is an example of what it can look like:

open canopy.classic
open canopy.types
open System
open Xunit

let private openApp() =
    ...

type Fixture() =
    do
        start ChromeHeadless

    interface IDisposable with 
        member _.Dispose() =
            quit()

type Tests() = 
    interface IClassFixture<Fixture>

    [<Fact>]
    member _.``Soundcheck - Server is online``() =
        openApp()
        
    [<Fact>]
    member _.``Button1 is enabled``() =
        openApp()

        let button = element "#button1"

        Assert.True button.Enabled

    [<Fact>]
    member _.``Button2 is disabled``() =
        openApp()

        let button = element "#button2"

        Assert.False button.Enabled

Related Questions in F#