-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
247 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Check.fs" /> | ||
<Compile Include="ScrutinyStateMachine.fs" /> | ||
<Compile Include="Main.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="FSharp.Core" Version="7.0.0" /> | ||
<PackageReference Include="DEdge.Diffract" Version="0.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="Microsoft.Playwright" Version="1.31.1" /> | ||
<PackageReference Include="Scrutiny" Version="2.0.0" /> | ||
<PackageReference Include="Unquote" Version="6.1.0" /> | ||
<PackageReference Include="xunit.core" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[<Microsoft.FSharp.Core.AutoOpen>] | ||
module App.Test.Check | ||
|
||
open System | ||
open Microsoft.FSharp.Quotations.Patterns | ||
open Swensen.Unquote | ||
|
||
let testWithReason expression reason = | ||
try | ||
Assertions.test expression | ||
with e -> | ||
let diff = | ||
match expression with | ||
| Call(_, methodInfo, [ a; b ]) when methodInfo.Name = "op_Equality" -> | ||
let a = a.Eval() | ||
let b = b.Eval() | ||
|
||
let diffMethod = | ||
typeof<DEdge.Diffract.Differ> | ||
.GetMethod(nameof DEdge.Diffract.Differ.Diff) | ||
.MakeGenericMethod [| a.GetType() |] | ||
|
||
let diff: DEdge.Diffract.Diff option = | ||
downcast diffMethod.Invoke(null, [| b; a; null |]) | ||
|
||
let diffString = DEdge.Diffract.Differ.ToString diff | ||
$"\nDiff =\n{diffString}" | ||
| _ -> String.Empty | ||
|
||
raise ( | ||
Exception( | ||
reason | ||
+ diff | ||
+ "\n----------------------------\nUnquote Message:\n" | ||
+ e.Message | ||
) | ||
) | ||
|
||
let test expression = testWithReason expression String.Empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
module App.Test.Main | ||
|
||
open System | ||
open Microsoft.Playwright | ||
open Scrutiny | ||
open Xunit | ||
open Xunit.Abstractions | ||
|
||
// https://blog.ploeh.dk/2014/03/21/composed-assertions-with-unquote/ | ||
|
||
type PlaywrightTests(outputHelper: ITestOutputHelper) = | ||
do | ||
Microsoft.Playwright.Program.Main([| "install" |]) | ||
|> ignore | ||
|
||
let logger msg = outputHelper.WriteLine(msg) | ||
let playwright = Playwright.CreateAsync().GetAwaiter().GetResult() | ||
|
||
[<Fact>] | ||
member this.``Loads home page``() = task { | ||
let launchOptions = BrowserTypeLaunchOptions() | ||
launchOptions.Headless <- false | ||
|
||
let! browser = playwright.Firefox.LaunchAsync(launchOptions) | ||
let! context = browser.NewContextAsync(BrowserNewContextOptions(IgnoreHTTPSErrors = true)) | ||
|
||
let! page = context.NewPageAsync() | ||
|
||
let! _ = page.GotoAsync("http://localhost:5173/SubtleConduit/") | ||
|
||
let header = page.GetByRole(AriaRole.Heading) | ||
let! text = header.First.InnerTextAsync() | ||
|
||
test <@ text = "conduit" @> | ||
|
||
do! | ||
page | ||
.GetByTestId("feedItems") | ||
.Locator("li") | ||
.Nth(0) | ||
.WaitForAsync() | ||
|
||
let! postCount = | ||
page | ||
.GetByTestId("feedItems") | ||
.Locator("li") | ||
.CountAsync() | ||
|
||
test <@ postCount > 1 @> | ||
|
||
do! | ||
page | ||
.GetByTestId("tags") | ||
.Locator("li") | ||
.Nth(0) | ||
.WaitForAsync() | ||
|
||
let! tagCount = | ||
page | ||
.GetByTestId("tags") | ||
.Locator("li") | ||
.CountAsync() | ||
|
||
test <@ tagCount > 1 @> | ||
} | ||
|
||
[<Fact>] | ||
member this.``Run Scrutiny Test``() = task { | ||
let isHeadless = Environment.GetEnvironmentVariable("CI") = "true" | ||
|
||
let launchOptions = BrowserTypeLaunchOptions() | ||
launchOptions.Headless <- isHeadless | ||
//launchOptions.SlowMo <- 500f | ||
|
||
let! browser = playwright.Firefox.LaunchAsync(launchOptions) | ||
let! context = browser.NewContextAsync(BrowserNewContextOptions(IgnoreHTTPSErrors = true)) | ||
|
||
let! page = context.NewPageAsync() | ||
|
||
let! _ = page.GotoAsync("http://localhost:5173/SubtleConduit/") | ||
|
||
let config = | ||
{ ScrutinyConfig.Default with | ||
Seed = 553931187 | ||
MapOnly = false | ||
ComprehensiveActions = true | ||
ComprehensiveStates = true | ||
} | ||
|
||
let! result = scrutinize config (GlobalState(page, logger)) ScrutinyStateMachine.home | ||
// Assert.True(result.Steps |> Seq.length >= 5) | ||
// Assert.Equal(5, result.Graph.Length) | ||
test <@ 1 = 2 @> | ||
} | ||
|
||
interface IDisposable with | ||
member this.Dispose() = playwright.Dispose() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace App.Test | ||
|
||
open Microsoft.Playwright | ||
open Scrutiny | ||
|
||
type GlobalState(page: IPage, logger: string -> unit) = | ||
member val Logger = logger | ||
member val Page = page | ||
|
||
member x.GetInputValueAsync(selector: string) = task { | ||
let! element = x.Page.QuerySelectorAsync(selector) | ||
let! value = element.EvaluateAsync("e => e.value") | ||
return value.ToString() | ||
} | ||
|
||
|
||
module rec ScrutinyStateMachine = | ||
let home = | ||
fun (gs: GlobalState) -> page { | ||
name "Home" | ||
|
||
onEnter (fun _ -> task { | ||
let header = gs.Page.GetByRole(AriaRole.Heading) | ||
let! text = header.First.InnerTextAsync() | ||
|
||
test <@ text = "conduit" @> | ||
|
||
do! | ||
gs | ||
.Page | ||
.GetByTestId("feedItems") | ||
.Locator("li") | ||
.Nth(0) | ||
.WaitForAsync() | ||
|
||
let! postCount = | ||
gs | ||
.Page | ||
.GetByTestId("feedItems") | ||
.Locator("li") | ||
.CountAsync() | ||
|
||
test <@ postCount > 1 @> | ||
|
||
do! | ||
gs | ||
.Page | ||
.GetByTestId("tags") | ||
.Locator("li") | ||
.Nth(0) | ||
.WaitForAsync() | ||
|
||
let! tagCount = | ||
gs | ||
.Page | ||
.GetByTestId("tags") | ||
.Locator("li") | ||
.CountAsync() | ||
|
||
test <@ tagCount > 1 @> | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters