1
0
Fork 0

Fix bug 540

Bug540-XiongJiaming
熊佳明 2024-05-20 20:53:14 +08:00
parent d8e4fbbb2d
commit 175e086a78
2 changed files with 77 additions and 0 deletions

View File

@ -112,6 +112,11 @@
<input type="checkbox" id="highlightCheckbox" onclick="toggleHighlighting()" />生词高亮
<input type="checkbox" id="readCheckbox" onclick="onReadClick()" />大声朗读
<input type="checkbox" id="chooseCheckbox" onclick="onChooseClick()" />划词入库
<button onclick="saveArticle()" class="btn btn-primary">标记文章</button>
<select id="saved_articles_dropdown" style="height: 50px">
<!-- 这里将显示已经保存的文章 -->
<option></option>
</select>
<div class="range">
<div class="field">
<div class="sliderValue">
@ -286,6 +291,31 @@
$('#not_found').hide();
$('#read_all').show();
}
}
function saveArticle() {
const articleTitle = document.getElementById('article_title').innerText; // 获取文章标题
const article = document.getElementById('article').innerText; // 获取文章内容
const savedArticlesDropdown = document.getElementById('saved_articles_dropdown'); // 获取下拉菜单
var option = document.createElement('option'); // 创建一个新的下拉菜单选项
option.text = articleTitle; // 将文章标题作为选项文本
option.value = article; // 将文章内容作为选项值
option.title = article; // 将文章内容作为工具提示内容
savedArticlesDropdown.appendChild(option); // 将选项添加到下拉菜单中
localStorage.setItem(articleTitle, article) //将标记文章存储到localstorage中
alert("文章已标记")
}
window.onload = function() {
const savedArticlesDropdown = document.getElementById('saved_articles_dropdown');
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i); // 获取localStorage中的键
const value = localStorage.getItem(key); // 获取localStorage中的值
// 创建一个新的下拉菜单选项
var option = document.createElement('option');
option.text = key; // 将文章标题作为选项文本
option.value = value; // 将文章内容作为选项值
option.title = value; // 将文章内容作为工具提示内容
savedArticlesDropdown.appendChild(option); // 将选项添加到下拉菜单中
}
}
</script>
</body>

View File

@ -0,0 +1,47 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import logging
from helper import signup
def login(driver, home, uname, password):
driver.get(home)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, '登录'))).click()
driver.find_element(By.ID, 'username').send_keys(uname)
driver.find_element(By.ID, 'password').send_keys(password)
driver.find_element(By.XPATH, '//button[text()="登录"]').click()
WebDriverWait(driver, 10).until(EC.title_is(f"EnglishPal Study Room for {uname}"))
def logout(driver):
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, '退出'))).click()
# 标记文章
def collect_article(driver):
driver.find_element(By.XPATH, '//button[text()="标记文章"]').click()
def test_collect_article(driver, URL):
try:
username, password = signup(URL, driver)
title = driver.find_element(By.ID, 'article_title').text
article = driver.find_element(By.ID, 'article').text
collect_article(driver)
collected_title = driver.execute_script('return localStorage.getItem("articleTitle");')
assert title == collected_title, "Unable to add the article to your collection."
# 退出登录
logout(driver)
# 再次登录并检查收藏状态
login(driver, URL, username, password)
rechecked_title = driver.execute_script('return localStorage.getItem("articleTitle");')
assert title == rechecked_title, "Collected article not found after re-login."
except Exception as e:
# 输出异常信息
logging.error(e)
# 关闭浏览器
driver.quit()
finally:
driver.quit()