Revert "Replace webdriver with halonium"
This commit is contained in:
parent
b2932e9348
commit
7d8417ff97
7 changed files with 87 additions and 25 deletions
|
|
@ -21,7 +21,7 @@ requires "sass#649e0701fa5c"
|
|||
|
||||
requires "karax#5f21dcd"
|
||||
|
||||
requires "halonium#f54c83f"
|
||||
requires "webdriver#429933a"
|
||||
|
||||
# Tasks
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import options, osproc, streams, threadpool, os, strformat, httpclient
|
||||
|
||||
import halonium
|
||||
import webdriver
|
||||
|
||||
proc runProcess(cmd: string) =
|
||||
let p = startProcess(
|
||||
|
|
@ -46,13 +46,22 @@ template withBackend(body: untyped): untyped =
|
|||
import browsertests/[scenario1, threads, issue181, categories]
|
||||
|
||||
proc main() =
|
||||
# Kill any already running instances
|
||||
discard execCmd("killall geckodriver")
|
||||
spawn runProcess("geckodriver -p 4444 --log config")
|
||||
defer:
|
||||
discard execCmd("killall geckodriver")
|
||||
|
||||
# Create a fresh DB for the tester.
|
||||
doAssert(execCmd("nimble testdb") == QuitSuccess)
|
||||
|
||||
doAssert(execCmd("nimble -y frontend") == QuitSuccess)
|
||||
echo("Waiting for geckodriver to startup...")
|
||||
sleep(5000)
|
||||
|
||||
try:
|
||||
let session = createSession(Firefox)
|
||||
let driver = newWebDriver()
|
||||
let session = driver.createSession()
|
||||
|
||||
withBackend:
|
||||
scenario1.test(session, baseUrl)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import unittest, common
|
||||
import halonium
|
||||
import webdriver
|
||||
|
||||
import karaxutils
|
||||
|
||||
|
|
@ -47,12 +47,12 @@ proc categoriesUserTests(session: Session, baseUrl: string) =
|
|||
with session:
|
||||
click "#new-thread-btn"
|
||||
|
||||
checkIsNone "#add-category .plus-btn"
|
||||
checkIsNone "#add-category"
|
||||
|
||||
test "no category add available category page":
|
||||
with session:
|
||||
click "#categories-btn"
|
||||
checkIsNone "#add-category .plus-btn"
|
||||
checkIsNone "#add-category"
|
||||
|
||||
test "can create category thread":
|
||||
with session:
|
||||
|
|
@ -139,17 +139,17 @@ proc categoriesUserTests(session: Session, baseUrl: string) =
|
|||
checkText "#threads-list .thread-title a", "Post 3"
|
||||
for element in session.waitForElements("#threads-list .category-name"):
|
||||
# Have to user "innerText" because elements are hidden on this page
|
||||
assert element.text == "Unsorted"
|
||||
assert element.getProperty("innerText") == "Unsorted"
|
||||
|
||||
selectCategory "announcements"
|
||||
checkText "#threads-list .thread-title a", "Post 2"
|
||||
for element in session.waitForElements("#threads-list .category-name"):
|
||||
assert element.text == "Announcements"
|
||||
assert element.getProperty("innerText") == "Announcements"
|
||||
|
||||
selectCategory "fun"
|
||||
checkText "#threads-list .thread-title a", "Post 1"
|
||||
for element in session.waitForElements("#threads-list .category-name"):
|
||||
assert element.text == "Fun"
|
||||
assert element.getProperty("innerText") == "Fun"
|
||||
|
||||
session.logout()
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ proc categoriesAdminTests(session: Session, baseUrl: string) =
|
|||
with session:
|
||||
click "#new-thread-btn"
|
||||
|
||||
ensureExists "#add-category .plus-btn"
|
||||
ensureExists "#add-category"
|
||||
|
||||
click "#add-category .plus-btn"
|
||||
|
||||
|
|
@ -195,10 +195,10 @@ proc categoriesAdminTests(session: Session, baseUrl: string) =
|
|||
test "category adding disabled on admin logout":
|
||||
with session:
|
||||
navigate(baseUrl & "c/0")
|
||||
ensureExists "#add-category .plus-btn"
|
||||
ensureExists "#add-category"
|
||||
logout()
|
||||
|
||||
checkIsNone "#add-category .plus-btn"
|
||||
checkIsNone "#add-category"
|
||||
navigate baseUrl
|
||||
|
||||
login "admin", "admin"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import os, options, unittest, strutils
|
||||
import halonium
|
||||
import webdriver
|
||||
import macros
|
||||
|
||||
export waitForElement
|
||||
export waitForElements
|
||||
const actionDelayMs {.intdefine.} = 0
|
||||
## Inserts a delay in milliseconds between automated actions. Useful for debugging tests
|
||||
|
||||
macro with*(obj: typed, code: untyped): untyped =
|
||||
## Execute a set of statements with an object
|
||||
|
|
@ -24,6 +24,14 @@ macro with*(obj: typed, code: untyped): untyped =
|
|||
|
||||
result = getAst(checkCompiles(result, code))
|
||||
|
||||
proc elementIsSome(element: Option[Element]): bool =
|
||||
return element.isSome
|
||||
|
||||
proc elementIsNone(element: Option[Element]): bool =
|
||||
return element.isNone
|
||||
|
||||
proc waitForElement*(session: Session, selector: string, strategy=CssSelector, timeout=20000, pollTime=50, waitCondition=elementIsSome): Option[Element]
|
||||
|
||||
proc click*(session: Session, element: string, strategy=CssSelector) =
|
||||
let el = session.waitForElement(element, strategy)
|
||||
el.get().click()
|
||||
|
|
@ -36,33 +44,78 @@ proc clear*(session: Session, element: string) =
|
|||
let el = session.waitForElement(element)
|
||||
el.get().clear()
|
||||
|
||||
proc sendKeys*(session: Session, element: string, keys: varargs[string, convertKeyRuneString]) =
|
||||
proc sendKeys*(session: Session, element: string, keys: varargs[Key]) =
|
||||
let el = session.waitForElement(element)
|
||||
|
||||
el.get().sendKeys(keys)
|
||||
# focus
|
||||
el.get().click()
|
||||
for key in keys:
|
||||
session.press(key)
|
||||
|
||||
proc ensureExists*(session: Session, element: string, strategy=CssSelector) =
|
||||
discard session.waitForElement(element, strategy)
|
||||
|
||||
template check*(session: Session, element: string, function: untyped) =
|
||||
let el = session.waitForElement(element)
|
||||
doAssert function(el)
|
||||
check function(el)
|
||||
|
||||
template check*(session: Session, element: string,
|
||||
strategy: LocationStrategy, function: untyped) =
|
||||
let el = session.waitForElement(element, strategy)
|
||||
doAssert function(el)
|
||||
check function(el)
|
||||
|
||||
proc setColor*(session: Session, element, color: string, strategy=CssSelector) =
|
||||
let el = session.waitForElement(element, strategy)
|
||||
discard session.executeScript("arguments[0].setAttribute('value', '" & color & "')", el.get())
|
||||
discard session.execute("arguments[0].setAttribute('value', '" & color & "')", el.get())
|
||||
|
||||
proc checkIsNone*(session: Session, element: string, strategy=CssSelector) =
|
||||
discard session.waitForElement(element, strategy, waitCondition=elementIsNone)
|
||||
|
||||
proc checkText*(session: Session, element, expectedValue: string) =
|
||||
let el = session.waitForElement(element)
|
||||
doAssert el.get().text.strip() == expectedValue
|
||||
check el.get().getText() == expectedValue
|
||||
|
||||
proc waitForElement*(
|
||||
session: Session, selector: string, strategy=CssSelector,
|
||||
timeout=20000, pollTime=50,
|
||||
waitCondition=elementIsSome
|
||||
): Option[Element] =
|
||||
var waitTime = 0
|
||||
|
||||
when actionDelayMs > 0:
|
||||
sleep(actionDelayMs)
|
||||
|
||||
while true:
|
||||
try:
|
||||
let loading = session.findElement(selector, strategy)
|
||||
if waitCondition(loading):
|
||||
return loading
|
||||
finally:
|
||||
discard
|
||||
sleep(pollTime)
|
||||
waitTime += pollTime
|
||||
|
||||
if waitTime > timeout:
|
||||
doAssert false, "Wait for load time exceeded"
|
||||
|
||||
proc waitForElements*(
|
||||
session: Session, selector: string, strategy=CssSelector,
|
||||
timeout=20000, pollTime=50
|
||||
): seq[Element] =
|
||||
var waitTime = 0
|
||||
|
||||
when actionDelayMs > 0:
|
||||
sleep(actionDelayMs)
|
||||
|
||||
while true:
|
||||
let loading = session.findElements(selector, strategy)
|
||||
if loading.len > 0:
|
||||
return loading
|
||||
sleep(pollTime)
|
||||
waitTime += pollTime
|
||||
|
||||
if waitTime > timeout:
|
||||
doAssert false, "Wait for load time exceeded"
|
||||
|
||||
proc setUserRank*(session: Session, baseUrl, user, rank: string) =
|
||||
with session:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest, common
|
||||
|
||||
import halonium
|
||||
import webdriver
|
||||
|
||||
proc test*(session: Session, baseUrl: string) =
|
||||
session.navigate(baseUrl)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest, common
|
||||
|
||||
import halonium
|
||||
import webdriver
|
||||
|
||||
proc test*(session: Session, baseUrl: string) =
|
||||
session.navigate(baseUrl)
|
||||
|
|
@ -40,4 +40,4 @@ proc test*(session: Session, baseUrl: string) =
|
|||
register "TEst1", "test1", verify = false
|
||||
|
||||
ensureExists "#signup-form .has-error"
|
||||
navigate baseUrl
|
||||
navigate baseUrl
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest, common
|
||||
|
||||
import halonium
|
||||
import webdriver
|
||||
|
||||
let
|
||||
userTitleStr = "This is a user thread!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue