diff --git a/devtools/selenium_testing/options.py b/devtools/selenium_testing/options.py index 94831696..9d6832b1 100644 --- a/devtools/selenium_testing/options.py +++ b/devtools/selenium_testing/options.py @@ -3,9 +3,7 @@ from urllib.parse import urljoin from urllib.request import urlopen from selenium import webdriver -from selenium.webdriver.chrome.webdriver import WebDriver -from selenium.webdriver.edge.webdriver import WebDriver # skipcq: PYL-W0404 -from selenium.webdriver.firefox.webdriver import WebDriver # skipcq: PYL-W0404 +from selenium.webdriver.remote.webdriver import WebDriver from selenium.webdriver.chrome.options import Options as ChromeOptions from selenium.webdriver.edge.options import Options as EdgeOptions from selenium.webdriver.firefox.options import Options as FirefoxOptions diff --git a/devtools/selenium_testing/tests/test_mgmt.py b/devtools/selenium_testing/tests/test_mgmt.py index efcccac7..001a987a 100644 --- a/devtools/selenium_testing/tests/test_mgmt.py +++ b/devtools/selenium_testing/tests/test_mgmt.py @@ -1,4 +1,4 @@ -import unittest +import urllib.parse from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC @@ -6,7 +6,7 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.select import Select from . import SeleniumTestCase -from ..util.posting import make_post +from ..util.posting import make_post, delete_post import random from ..util.manage import staff_login @@ -16,6 +16,16 @@ class TestManageActions(SeleniumTestCase): staff_login(self.options) return super().setUp() + def get_recent_post_link(self, msg_text: str): + trs = self.driver.find_elements(by=By.CSS_SELECTOR, value="#content table tr") + for tr in trs: + tds = tr.find_elements(by=By.TAG_NAME, value="td") + for c in range(len(tds)): + if tds[c].text == msg_text: + # found the post we made + link = tds[c-2].find_element(by=By.LINK_TEXT, value="Post") + return link + def test_login(self): self.assertEqual( self.driver.find_element(by=By.CSS_SELECTOR, value="header h1").text, @@ -44,12 +54,22 @@ class TestManageActions(SeleniumTestCase): self.options.message = old_msg staff_login(self.options) self.driver.find_element(by=By.LINK_TEXT, value="Recent posts").click() - tds = self.driver.find_elements(by=By.CSS_SELECTOR, value="#content table td") - post_exists = False - for td in tds: - if td.text == new_msg: - post_exists = True - self.assertTrue(post_exists, "Found recent post in recent posts list") + WebDriverWait(self.driver, 10).until( + EC.url_contains("/manage/recentposts")) + + post_link = self.get_recent_post_link(new_msg) + link_href = post_link.get_attribute("href") + self.assertIsNotNone(post_link, "Found recent post in recent posts list") + post_link.click() + WebDriverWait(self.driver, 10).until( + EC.url_contains(link_href)) # link_href should be something like "/seleniumtesting/ref/.html#" + + fragment = urllib.parse.urldefrag(self.driver.current_url).fragment + delete_post(self.options, fragment, self.options.password) + + self.options.goto_page("/manage/recentposts") + post_link = self.get_recent_post_link(new_msg) + self.assertIsNone(post_link, "Confirmed that recent post was deleted") def test_makeBoard(self): if self.options.board_exists("seleniumtesting"): diff --git a/devtools/selenium_testing/tests/test_posting.py b/devtools/selenium_testing/tests/test_posting.py index d849049a..3b57abac 100644 --- a/devtools/selenium_testing/tests/test_posting.py +++ b/devtools/selenium_testing/tests/test_posting.py @@ -1,5 +1,4 @@ from os import path -import unittest from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC diff --git a/devtools/selenium_testing/util/localstorage.py b/devtools/selenium_testing/util/localstorage.py index e3756d8a..d2ed006b 100644 --- a/devtools/selenium_testing/util/localstorage.py +++ b/devtools/selenium_testing/util/localstorage.py @@ -1,6 +1,4 @@ -from selenium.webdriver.chrome.webdriver import WebDriver -from selenium.webdriver.edge.webdriver import WebDriver # skipcq: PYL-W0404 -from selenium.webdriver.firefox.webdriver import WebDriver # skipcq: PYL-W0404 +from selenium.webdriver.remote.webdriver import WebDriver class LocalStorage(): # from https://stackoverflow.com/a/46361900 diff --git a/devtools/selenium_testing/util/qr.py b/devtools/selenium_testing/util/qr.py index 3a39b195..40fa0516 100644 --- a/devtools/selenium_testing/util/qr.py +++ b/devtools/selenium_testing/util/qr.py @@ -1,13 +1,10 @@ -from selenium.webdriver.chrome.webdriver import WebDriver -from selenium.webdriver.edge.webdriver import WebDriver # skipcq: PYL-W0404 -from selenium.webdriver.firefox.webdriver import WebDriver # skipcq: PYL-W0404 +from selenium.webdriver.remote.webdriver import WebDriver from selenium.webdriver.common.by import By - def qrIsVisible(driver: WebDriver): try: return driver.find_element(by=By.CSS_SELECTOR, value="div#qr-box").is_displayed() - except: + except Exception: return False def enableQR(driver: WebDriver):