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
|
||||
1
tests/browsertester.nims
Normal file
1
tests/browsertester.nims
Normal file
|
|
@ -0,0 +1 @@
|
|||
--threads:on
|
||||
29
tests/browsertests/scenario1.nim
Normal file
29
tests/browsertests/scenario1.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import unittest, options, os
|
||||
|
||||
import webdriver
|
||||
|
||||
proc waitForLoad(session: Session) =
|
||||
sleep(2000)
|
||||
|
||||
while true:
|
||||
let loading = session.findElement(".loading")
|
||||
if loading.isNone: return
|
||||
sleep(1000)
|
||||
|
||||
proc test*(session: Session, baseUrl: string) =
|
||||
session.navigate(baseUrl)
|
||||
|
||||
waitForLoad(session)
|
||||
|
||||
# Sanity checks
|
||||
test "shows sign up":
|
||||
let signUp = session.findElement("#signup-btn")
|
||||
check signUp.get().getText() == "Sign up"
|
||||
|
||||
test "shows log in":
|
||||
let signUp = session.findElement("#login-btn")
|
||||
check signUp.get().getText() == "Log in"
|
||||
|
||||
test "is empty":
|
||||
let thread = session.findElement("tr > td.thread-title")
|
||||
check thread.isNone()
|
||||
Loading…
Add table
Add a link
Reference in a new issue