简体   繁体   中英

How to run a Canopy test suite with xUnit?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM