mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 19:16:23 -07:00
Make all testing options available to command line
This commit is contained in:
parent
46c1899732
commit
760f1cb75e
6 changed files with 74 additions and 32 deletions
2
build.py
2
build.py
|
@ -529,7 +529,7 @@ if __name__ == "__main__":
|
|||
from tools.selenium_testing.runtests import setup_selenium_args, start_tests, close_tests
|
||||
args = setup_selenium_args(parser)
|
||||
try:
|
||||
start_tests(args.browser, args.headless, args.keepopen, args.site, args.board, "html/static/notbanned.png", args.singletest)
|
||||
start_tests(args.__dict__)
|
||||
except KeyboardInterrupt:
|
||||
print("Tests interrupted by KeyboardInterrupt, exiting")
|
||||
except Exception:
|
||||
|
|
|
@ -13,8 +13,8 @@ default_name = "Selenium"
|
|||
default_email = "selenium@gochan.org#noko"
|
||||
default_message = "Hello, from Selenium!\n(driver is %s)"
|
||||
default_subject = "Selenium post creation"
|
||||
default_upload = "./html/static/notbanned.png"
|
||||
default_password = "12345"
|
||||
default_upload = "html/static/notbanned.png"
|
||||
default_post_password = "12345"
|
||||
default_board1 = "test"
|
||||
default_board2 = "selenium2"
|
||||
default_staff_username = "admin"
|
||||
|
@ -24,7 +24,7 @@ class TestingOptions:
|
|||
browser: str
|
||||
driver: WebDriver
|
||||
headless: bool
|
||||
keep_open: bool
|
||||
__keep_open: bool
|
||||
site: str
|
||||
board1: str
|
||||
board2: str
|
||||
|
@ -33,9 +33,37 @@ class TestingOptions:
|
|||
subject: str
|
||||
message: str
|
||||
upload_path: str
|
||||
password: str
|
||||
post_password: str
|
||||
staff_username: str
|
||||
staff_password: str
|
||||
|
||||
@property
|
||||
def keep_open(self):
|
||||
return self.__keep_open
|
||||
|
||||
|
||||
@keep_open.setter
|
||||
def keep_open(self, ko:bool):
|
||||
self.__keep_open = ko and not self.headless
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_dict(src_dict:dict[str,object]):
|
||||
options = TestingOptions(src_dict.get("browser", ""), src_dict.get("headless", False), src_dict.get("keepopen"))
|
||||
options.site = src_dict.get("site", default_site)
|
||||
options.board1 = src_dict.get("board1", default_board1)
|
||||
options.board2 = src_dict.get("board2", default_board2)
|
||||
options.name = src_dict.get("name", default_name)
|
||||
options.email = src_dict.get("email", default_email)
|
||||
options.subject = src_dict.get("subject", default_subject)
|
||||
options.message = src_dict.get("message", default_message)
|
||||
options.upload_path = src_dict.get("upload", default_upload)
|
||||
options.post_password = src_dict.get("post_password", default_post_password)
|
||||
options.staff_username = src_dict.get("staff_username", default_staff_username)
|
||||
options.staff_password = src_dict.get("staff_password", default_staff_password)
|
||||
return options
|
||||
|
||||
|
||||
def __init__(self, browser: str, headless=False, keep_open=False):
|
||||
self.browser = browser
|
||||
self.headless = headless
|
||||
|
@ -48,7 +76,7 @@ class TestingOptions:
|
|||
self.subject = default_subject
|
||||
self.message = default_message
|
||||
self.upload_path = default_upload
|
||||
self.password = default_password
|
||||
self.post_password = default_post_password
|
||||
self.staff_username = default_staff_username
|
||||
self.staff_password = default_staff_password
|
||||
|
||||
|
@ -78,7 +106,8 @@ class TestingOptions:
|
|||
if keep_open:
|
||||
options.add_experimental_option("detach", True)
|
||||
self.driver = webdriver.Edge(options=options)
|
||||
|
||||
case ""|None:
|
||||
raise ValueError("browser argument is required")
|
||||
case _:
|
||||
raise ValueError("Unrecognized browser argument %s" % browser)
|
||||
|
||||
|
|
|
@ -7,27 +7,19 @@
|
|||
from argparse import ArgumentParser
|
||||
import unittest
|
||||
|
||||
from .options import TestingOptions, default_site, default_board1
|
||||
from .options import (TestingOptions, default_site, default_name, default_email, default_message, default_subject,
|
||||
default_upload, default_post_password, default_board1, default_board2, default_staff_username, default_staff_password)
|
||||
from .tests import SeleniumTestCase
|
||||
from .tests.test_mgmt import TestManageActions
|
||||
from .tests.test_posting import TestPosting
|
||||
|
||||
options:TestingOptions = None
|
||||
|
||||
def start_tests(browser:str, headless=False, keep_open=False, site="", board="", upload="", single_test=""):
|
||||
def start_tests(dict_options:dict[str,object]=None):
|
||||
global options
|
||||
options = TestingOptions(browser, headless, keep_open)
|
||||
|
||||
if headless:
|
||||
options.keep_open = False
|
||||
if site != "":
|
||||
options.site = site
|
||||
if board != "":
|
||||
options.board1 = board
|
||||
if upload != "":
|
||||
options.upload_path = upload
|
||||
|
||||
print("Using browser %s (headless: %s) on site %s" % (browser, options.headless, options.site))
|
||||
options = TestingOptions.from_dict(dict_options)
|
||||
single_test = dict_options.get("single_test", "")
|
||||
print("Using browser %s (headless: %s) on site %s" % (options.browser, options.headless, options.site))
|
||||
if single_test == "":
|
||||
suite = unittest.suite.TestSuite()
|
||||
SeleniumTestCase.add(suite, options, TestPosting)
|
||||
|
@ -67,25 +59,46 @@ def close_tests():
|
|||
def setup_selenium_args(parser:ArgumentParser):
|
||||
testable_browsers = ("firefox","chrome","chromium", "edge")
|
||||
|
||||
|
||||
parser.add_argument("--browser", choices=testable_browsers, required=True)
|
||||
parser.add_argument("--headless", action="store_true",
|
||||
help="If set, the driver will run without opening windows (overrides --keep-open if it is set)")
|
||||
parser.add_argument("--keep-open", action="store_true",
|
||||
help="If set, the browser windows will not automatically close after the tests are complete")
|
||||
parser.add_argument("--site", default=default_site,
|
||||
help=("Sets the site to be used for testing, defaults to %s" % default_site))
|
||||
parser.add_argument("--board", default=default_board1,
|
||||
parser.add_argument("--board1", default=default_board1,
|
||||
help="Sets the board to be used for testing")
|
||||
parser.add_argument("--headless", action="store_true",
|
||||
help="If set, the driver will run without opening windows (overrides --keepopen if it is set)")
|
||||
parser.add_argument("--keepopen", action="store_true",
|
||||
help="If set, the browser windows will not automatically close after the tests are complete")
|
||||
parser.add_argument("--singletest", default="",
|
||||
parser.add_argument("--board2", default=default_board2,
|
||||
help="Sets the board to be used for testing")
|
||||
parser.add_argument("--name", default=default_name,
|
||||
help="Sets the name to be used when posting")
|
||||
parser.add_argument("--email", default=default_email,
|
||||
help="Sets the email to be used when posting")
|
||||
parser.add_argument("--subject", default=default_subject,
|
||||
help="Sets the subject to be used when posting")
|
||||
parser.add_argument("--message", default=default_message,
|
||||
help="Sets the message to be used when posting")
|
||||
parser.add_argument("--upload_path", default=default_upload,
|
||||
help="Sets the file to be used when posting")
|
||||
parser.add_argument("--post_password", default=default_post_password,
|
||||
help="Sets the post password")
|
||||
parser.add_argument("--staff_username", default=default_staff_username,
|
||||
help="Sets the staff username to be used when logging in")
|
||||
parser.add_argument("--staff_password", default=default_staff_password,
|
||||
help="Sets the staff password to be used when logging in")
|
||||
parser.add_argument("--single-test", default="",
|
||||
help="If specified, only the test method with this name will be run")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser(description="Browser testing via Selenium")
|
||||
args = setup_selenium_args(parser)
|
||||
|
||||
try:
|
||||
start_tests(args.browser, args.headless, args.keepopen, args.site, args.board, "", args.singletest)
|
||||
start_tests(args.__dict__)
|
||||
except KeyboardInterrupt:
|
||||
print("Tests interrupted by KeyboardInterrupt, exiting")
|
||||
close_tests()
|
||||
|
|
|
@ -74,7 +74,7 @@ class TestManageActions(SeleniumTestCase):
|
|||
EC.url_contains(link_href)) # link_href should be something like "/seleniumtesting/ref/<threadOP>.html#<postID>"
|
||||
|
||||
fragment = urllib.parse.urldefrag(self.driver.current_url).fragment
|
||||
delete_post(self.options, fragment, self.options.password)
|
||||
delete_post(self.options, fragment, self.options.post_password)
|
||||
|
||||
self.options.goto_page("/manage/recentposts")
|
||||
post_link = self.get_recent_post_link(new_msg)
|
||||
|
|
|
@ -62,7 +62,7 @@ class TestPosting(SeleniumTestCase):
|
|||
self.options.subject,
|
||||
self.options.message % self.driver.name,
|
||||
path.abspath(self.options.upload_path),
|
||||
self.options.password)
|
||||
self.options.post_password)
|
||||
WebDriverWait(self.driver, 10).until(
|
||||
EC.url_matches(threadRE))
|
||||
|
||||
|
@ -100,7 +100,7 @@ class TestPosting(SeleniumTestCase):
|
|||
"",
|
||||
"Reply to thread after it was moved",
|
||||
path.abspath(self.options.upload_path),
|
||||
self.options.password)
|
||||
self.options.post_password)
|
||||
|
||||
delete_post(self.options, int(threadID), "")
|
||||
WebDriverWait(self.driver, 10).until(
|
||||
|
|
|
@ -44,7 +44,7 @@ def make_post(options: TestingOptions, url: str, runner: unittest.TestCase):
|
|||
options.message if options.message.find("%s") == -1
|
||||
else (options.message % options.name),
|
||||
path.abspath(options.upload_path),
|
||||
options.password)
|
||||
options.post_password)
|
||||
WebDriverWait(options.driver, 10).until(
|
||||
EC.url_matches(threadRE))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue