From b0cfe31597f82b7ffe7f229c98ba833ede3f3d02 Mon Sep 17 00:00:00 2001 From: Ennio Visconti Date: Mon, 17 Jun 2024 12:49:31 +0200 Subject: [PATCH] feat: enhanced DSL --- test.main.kts | 39 --------------------------------- webmonitor.main.kts | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 39 deletions(-) delete mode 100644 test.main.kts create mode 100644 webmonitor.main.kts diff --git a/test.main.kts b/test.main.kts deleted file mode 100644 index e1e7081..0000000 --- a/test.main.kts +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env kotlin - -@file:DependsOn("com.enniovisco:webmonitor:v1.2.0-beta.7") - -import com.enniovisco.dsl.* - -monitor { - webSource { - screenWidth = 393 // px - screenHeight = 851 // px - // To date Google Chrome is the browser with the most stable APIs - browser = Browser.CHROME_HEADLESS - wait = 0 - maxSessionDuration = 5_000 // ms - targetUrl = "https://enniovisco.github.io/webmonitor/sample.html" - } - - spec { - atoms( - select { "#css" } - ) - - record( - after { "click" } - ) - - formula = screen and atoms[0] - } -} - -//println(WebSource.screenWidth) - -//print( -// createHTML().html { -// body { -// h1 { +"Hello, $addressee!" } -// } -// } -//) \ No newline at end of file diff --git a/webmonitor.main.kts b/webmonitor.main.kts new file mode 100644 index 0000000..6fcc20a --- /dev/null +++ b/webmonitor.main.kts @@ -0,0 +1,53 @@ +#!/usr/bin/env kotlin + +@file:DependsOn("com.enniovisco:webmonitor:1.2.0") + +import com.enniovisco.dsl.* + +monitor { + webSource { + screenWidth = 393 // px + screenHeight = 851 // px + // To date Google Chrome is the browser with the most stable APIs + browser = Browser.CHROME_HEADLESS // Alternatively Browser.FIREFOX, Browser.EDGE or Browser.CHROME + wait = 0 + maxSessionDuration = 5_000 // ms + targetUrl = "https://enniovisco.github.io/webmonitor/sample.html" + } + + spec { + atoms( + select { ".cookieInfo" } // [0] + read "visibility" + equalTo "visible", + select { ".subtitle" }, // [1] + select { "button#close" }, // [2] + select { ".cookieInfo" } read "position" bind "pos", + select { ".cookieInfo" } read "font-size" bind "fs", + select { ".info" } read "position" bind "pos", + select { ".subtitle" } read "font-size" bind "fs" + applying { value, bound -> + parsePixels(value) == parsePixels(bound) * 1.5 + }, + select { "h2.subtitle" }, + select { "p" } + ) + + record( + after { "click" }, + after { "touch" } + ) + + + // helper formulae + val screen = Spec.screen + val popupIsVisible = Spec.atoms[0] + val subtitle = Spec.atoms[1] + val closeButton = Spec.atoms[2] + val er1 = closeButton implies screen + val er2 = not(popupIsVisible and subtitle) + + // Final formula + formula = atoms[6] and not(atoms[8]) // and everywhere(er1) + } +} \ No newline at end of file