diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index e5c8d95..aabc080 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -198,7 +198,8 @@ elements.chooseCheckbox.checked = settings.chooseChecked; elements.rangeComponent.value = settings.rangeValue; elements.rangeValueDisplay.textContent = `${settings.rangeValue}x`; - elements.selectedWordsInput.value = settings.selectedWords; + + // 刷新页面或进入页面时判断,若不是首篇文章,则上一篇按钮可见 if (sessionStorage.getItem('pre_page_button') !== 'display' && sessionStorage.getItem('pre_page_button')) { diff --git a/app/test/test_next_article.py b/app/test/test_next_article.py new file mode 100644 index 0000000..3e470de --- /dev/null +++ b/app/test/test_next_article.py @@ -0,0 +1,85 @@ +''' Contributed by Lin Junhong et al. 2023-06.''' + +from selenium import webdriver +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException +import random, time +import string + +# 初始化webdriver +# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME) +# driver.implicitly_wait(10) +driver = webdriver.Chrome("C:\\Users\\12993\AppData\Local\Programs\Python\Python38\\chromedriver.exe") + + +def test_next_article(): + try: + driver.get("http://118.25.96.118:90") + assert 'English Pal -' in driver.page_source + # login + elem = driver.find_element_by_link_text('登录') + elem.click() + + uname = 'abcdefg' + password = 'abcdefg' + elem = driver.find_element_by_id('username') + elem.send_keys(uname) + + elem = driver.find_element_by_id('password') + elem.send_keys(password) + elem = driver.find_element_by_xpath('/html/body/div/button') # 找到登录按钮 + elem.click() + + time.sleep(0.5) + assert 'EnglishPal Study Room for ' + uname in driver.title + for i in range(50): + time.sleep(0.1) + # 找到固定按钮 + elem = driver.find_element_by_xpath('//*[@id="load_next_article"]') + elem.click() + except Exception as e: + print(e) + + +def test_local_next_article(): + try: + driver.get("http://127.0.0.1:5000") + assert 'English Pal -' in driver.page_source + # login + elem = driver.find_element_by_link_text('注册') + elem.click() + + uname = 'abcdefg' + password = 'abcdefg' + elem = driver.find_element_by_id('username') + elem.send_keys(uname) + + elem = driver.find_element_by_id('password') + elem.send_keys(password) + + elem = driver.find_element_by_id('password2') + elem.send_keys(password) + + time.sleep(0.5) + + elem = driver.find_element_by_class_name('btn') # 找到提交按钮 + elem.click() + time.sleep(0.5) + try: + WebDriverWait(driver, 1).until(EC.alert_is_present()) + driver.switch_to.alert.accept() + except (UnexpectedAlertPresentException, NoAlertPresentException): + pass + + time.sleep(0.5) + assert 'EnglishPal Study Room for ' + uname in driver.title + for i in range(50): + time.sleep(0.1) + # 找到固定按钮 + elem = driver.find_element_by_xpath('//*[@id="load_next_article"]') + elem.click() + except Exception as e: + print(e)