Add basic test for creating a thread
This commit is contained in:
parent
122e279256
commit
b650a9f401
4 changed files with 95 additions and 16 deletions
|
|
@ -44,6 +44,7 @@ template withBackend(body: untyped): untyped =
|
||||||
body
|
body
|
||||||
|
|
||||||
import browsertests/scenario1
|
import browsertests/scenario1
|
||||||
|
import browsertests/threads
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
spawn runProcess("geckodriver -p 4444 --log config")
|
spawn runProcess("geckodriver -p 4444 --log config")
|
||||||
|
|
@ -63,8 +64,9 @@ when isMainModule:
|
||||||
|
|
||||||
withBackend:
|
withBackend:
|
||||||
scenario1.test(session, baseUrl)
|
scenario1.test(session, baseUrl)
|
||||||
|
threads.test(session, baseUrl)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
except:
|
except:
|
||||||
sleep(10000) # See if we can grab any more output.
|
sleep(10000) # See if we can grab any more output.
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
42
tests/browsertests/common.nim
Normal file
42
tests/browsertests/common.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import os, options
|
||||||
|
import webdriver
|
||||||
|
|
||||||
|
proc waitForLoad*(session: Session, timeout=20000) =
|
||||||
|
var waitTime = 0
|
||||||
|
sleep(2000)
|
||||||
|
|
||||||
|
while true:
|
||||||
|
let loading = session.findElement(".loading")
|
||||||
|
if loading.isNone: return
|
||||||
|
sleep(1000)
|
||||||
|
waitTime += 1000
|
||||||
|
|
||||||
|
if waitTime > timeout:
|
||||||
|
doAssert false, "Wait for load time exceeded"
|
||||||
|
|
||||||
|
proc logout*(session: Session) =
|
||||||
|
# Check whether we can log out.
|
||||||
|
let logoutLink = session.findElement(
|
||||||
|
"Logout",
|
||||||
|
LinkTextSelector
|
||||||
|
).get()
|
||||||
|
logoutLink.click()
|
||||||
|
|
||||||
|
proc login*(session: Session, user, password: string) =
|
||||||
|
let logIn = session.findElement("#login-btn").get()
|
||||||
|
logIn.click()
|
||||||
|
|
||||||
|
let usernameField = session.findElement(
|
||||||
|
"#login-form input[name='username']"
|
||||||
|
)
|
||||||
|
|
||||||
|
let passwordField = session.findElement(
|
||||||
|
"#login-form input[name='password']"
|
||||||
|
)
|
||||||
|
|
||||||
|
usernameField.get().sendKeys("admin")
|
||||||
|
passwordField.get().sendKeys("admin")
|
||||||
|
passwordField.get().click() # Focus field.
|
||||||
|
session.press(Key.Enter)
|
||||||
|
|
||||||
|
waitForLoad(session, 5000)
|
||||||
|
|
@ -1,20 +1,7 @@
|
||||||
import unittest, options, os
|
import unittest, options, os, common
|
||||||
|
|
||||||
import webdriver
|
import webdriver
|
||||||
|
|
||||||
proc waitForLoad(session: Session, timeout=20000) =
|
|
||||||
var waitTime = 0
|
|
||||||
sleep(2000)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let loading = session.findElement(".loading")
|
|
||||||
if loading.isNone: return
|
|
||||||
sleep(1000)
|
|
||||||
waitTime += 1000
|
|
||||||
|
|
||||||
if waitTime > timeout:
|
|
||||||
doAssert false, "Wait for load time exceeded"
|
|
||||||
|
|
||||||
proc test*(session: Session, baseUrl: string) =
|
proc test*(session: Session, baseUrl: string) =
|
||||||
session.navigate(baseUrl)
|
session.navigate(baseUrl)
|
||||||
|
|
||||||
|
|
@ -112,4 +99,6 @@ proc test*(session: Session, baseUrl: string) =
|
||||||
"#main-navbar .menu-right div.tile-content"
|
"#main-navbar .menu-right div.tile-content"
|
||||||
).get()
|
).get()
|
||||||
|
|
||||||
check profileName.getText() == "test"
|
check profileName.getText() == "test"
|
||||||
|
|
||||||
|
logout(session)
|
||||||
46
tests/browsertests/threads.nim
Normal file
46
tests/browsertests/threads.nim
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import unittest, options, os, common
|
||||||
|
|
||||||
|
import webdriver
|
||||||
|
|
||||||
|
proc test*(session: Session, baseUrl: string) =
|
||||||
|
session.navigate(baseUrl)
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
login(session, "admin", "admin")
|
||||||
|
|
||||||
|
test "can create thread":
|
||||||
|
let newThreadBtn = session.findElement("#new-thread-btn").get()
|
||||||
|
newThreadBtn.click()
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
let newThread = session.findElement("#new-thread")
|
||||||
|
check newThread.isSome()
|
||||||
|
|
||||||
|
let createThreadBtn = session.findElement("#create-thread-btn")
|
||||||
|
check createThreadBtn.isSome()
|
||||||
|
|
||||||
|
|
||||||
|
let threadTitle = session.findElement("#thread-title")
|
||||||
|
check threadTitle.isSome()
|
||||||
|
|
||||||
|
let replyBox = session.findElement("#reply-textarea")
|
||||||
|
check replyBox.isSome()
|
||||||
|
|
||||||
|
threadTitle.get().sendKeys("This is a thread title!")
|
||||||
|
replyBox.get().sendKeys("This is content.")
|
||||||
|
|
||||||
|
createThreadBtn.get().click()
|
||||||
|
|
||||||
|
waitForLoad(session)
|
||||||
|
|
||||||
|
let newThreadTitle = session.findElement("#thread-title")
|
||||||
|
check newThreadTitle.isSome()
|
||||||
|
|
||||||
|
check newThreadTitle.get().getText() == "This is a thread title!"
|
||||||
|
|
||||||
|
let content = session.findElement(".original-post div.post-content")
|
||||||
|
check content.isSome()
|
||||||
|
|
||||||
|
check content.get().getText() == "This is content."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue