Skip to content

Commit

Permalink
Switch Gradle tasks to utilise Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
scroix committed Apr 7, 2024
1 parent c8cb6e9 commit 7315692
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions nodel-jyhost/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodelhost-temp
39 changes: 32 additions & 7 deletions nodel-jyhost/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,37 @@ tasks.named('distZip') {

def process

tasks.register('cleanNodelhostTemp') {
doLast {
def nodelhostTempDir = new File("$projectDir/nodelhost-temp")
if (nodelhostTempDir.exists()) {
nodelhostTempDir.deleteDir()
println "Cleaned nodelhost-temp directory"
}
}
}

clean {
dependsOn 'cleanNodelhostTemp'
}

tasks.register('startApplication') {
dependsOn 'cleanNodelhostTemp'
doLast {
def nodelhostTempDir = new File("$projectDir/nodelhost-temp")
if (!nodelhostTempDir.exists()) {
nodelhostTempDir.mkdirs()
}

def processBuilder = new ProcessBuilder(
'java',
'-cp', sourceSets.main.runtimeClasspath.asPath,
'-ea',
'org.nodel.jyhost.Launch'
)
processBuilder.redirectOutput(new File("$buildDir/output.log"))
processBuilder.redirectError(new File("$buildDir/error.log"))
processBuilder.directory(nodelhostTempDir)
processBuilder.redirectOutput(new File("$nodelhostTempDir/output.log"))
processBuilder.redirectError(new File("$nodelhostTempDir/error.log"))
process = processBuilder.start()
}
}
Expand All @@ -84,14 +105,18 @@ tasks.register('stopApplication') {
}
}

// ./gradlew playwright --args="help"
task playwright(type: JavaExec) {
classpath sourceSets.test.runtimeClasspath
mainClass = 'com.microsoft.playwright.CLI'
}

test {
dependsOn startApplication
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
maxParallelForks = 1 // Ensure tests run sequentially
systemProperty 'webdriver.chrome.driver', '/opt/homebrew/bin/chromedriver'
finalizedBy stopApplication
}

Expand Down Expand Up @@ -122,9 +147,9 @@ dependencies {
// Add joda-time dependency
implementation 'joda-time:joda-time:2.10.14'

// Selenium dependencies
testImplementation 'org.seleniumhq.selenium:selenium-java:4.0.0'
testImplementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.0.0'
// add Playwright and test dependencies
testImplementation 'com.microsoft.playwright:playwright:1.42.0'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

0 comments on commit 7315692

Please sign in to comment.