Implements web driver test suite and simple test.
This commit is contained in:
parent
770b5cddab
commit
c6ed9e80c9
8 changed files with 183 additions and 29 deletions
68
tests/browsertester.nim
Normal file
68
tests/browsertester.nim
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import options, osproc, streams, threadpool, os, strformat, httpclient
|
||||
|
||||
import webdriver
|
||||
|
||||
proc runProcess(cmd: string) =
|
||||
let p = startProcess(
|
||||
cmd,
|
||||
options={
|
||||
poStdErrToStdOut,
|
||||
poEvalCommand
|
||||
}
|
||||
)
|
||||
|
||||
let o = p.outputStream
|
||||
while p.running and (not o.atEnd):
|
||||
echo cmd.substr(0, 10), ": ", o.readLine()
|
||||
|
||||
p.close()
|
||||
|
||||
const backend = "forum"
|
||||
const port = 5000
|
||||
const baseUrl = "http://localhost:" & $port & "/"
|
||||
template withBackend(body: untyped): untyped =
|
||||
## Starts a new backend instance with a fresh DB.
|
||||
doAssert(execCmd("nimble testdb") == QuitSuccess)
|
||||
|
||||
spawn runProcess("nimble runbackend")
|
||||
defer:
|
||||
discard execCmd("killall " & backend)
|
||||
|
||||
echo("Waiting for server...")
|
||||
var success = false
|
||||
for i in 0..5:
|
||||
sleep(5000)
|
||||
try:
|
||||
let client = newHttpClient()
|
||||
doAssert client.getContent(baseUrl).len > 0
|
||||
success = true
|
||||
break
|
||||
except:
|
||||
echo("Failed to getContent")
|
||||
|
||||
doAssert success
|
||||
|
||||
body
|
||||
|
||||
import browsertests/scenario1
|
||||
|
||||
when isMainModule:
|
||||
spawn runProcess("geckodriver -p 4444 --log config")
|
||||
defer:
|
||||
discard execCmd("killall geckodriver")
|
||||
|
||||
doAssert(execCmd("nimble frontend") == QuitSuccess)
|
||||
echo("Waiting for geckodriver to startup...")
|
||||
sleep(5000)
|
||||
|
||||
try:
|
||||
let driver = newWebDriver()
|
||||
let session = driver.createSession()
|
||||
|
||||
withBackend:
|
||||
scenario1.test(session, baseUrl)
|
||||
|
||||
session.close()
|
||||
except:
|
||||
sleep(10000) # See if we can grab any more output.
|
||||
raise
|
||||
Loading…
Add table
Add a link
Reference in a new issue