From 8575a0dc33672c53fccf3fc383950c92f22ef0b0 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 20 May 2024 15:25:34 +0800 Subject: [PATCH 01/15] fix --- app/static/js/fillword.js | 6 +++++- app/static/js/highlight.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/static/js/fillword.js b/app/static/js/fillword.js index b967633..d851123 100644 --- a/app/static/js/fillword.js +++ b/app/static/js/fillword.js @@ -10,7 +10,11 @@ function fillInWord() { if (isRead) Reader.read(word, inputSlider.value); if (!isChoose) return; const element = document.getElementById("selected-words"); - element.value = element.value + " " + word; + let index = (String)(element.value).indexOf(word); + localStorage.setItem("nowWord",element.value); + if(index === -1){ + element.value = element.value + " " + word; + } } document.getElementById("text-content").addEventListener("click", fillInWord, false); diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 0cea31a..ccd6c95 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -33,6 +33,21 @@ function highLight() { allWords = pickedWords.value + " "; } const list = allWords.split(" ");//将所有的生词放入一个list中,用于后续处理 + if(word !== null && word !== "" && word !== " "){ + let articleContent_fb2 = articleContent; + if(localStorage.getItem("nowWord").indexOf(word) !== -1){ + while(articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()) !== -1){ + // 找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。 + const index = articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()); + word = articleContent_fb2.substring(index, index + word.length); + articleContent_fb2 = articleContent_fb2.substring(index + word.length); // 使用副本中list[i]之后的子串替换掉副本 + articleContent = articleContent.replace(new RegExp(""+word+"", "g"), word) + } + pickedWords.value = localStorage.getItem("nowWord").replace(word,""); + document.getElementById("article").innerHTML = articleContent; + return; + } + } for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符 list[i] = list[i].replace('|', ""); From 9b3551bbc841538a9d37aed0409d3baa5ed6288d Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 20 May 2024 15:30:38 +0800 Subject: [PATCH 02/15] fix --- app/static/js/highlight.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index e8a3cf8..e776bb3 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -27,6 +27,21 @@ function highLight() { let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value; const list = allWords.split(" "); // 将所有的生词放入一个list中 + if(word !== null && word !== "" && word !== " "){ + let articleContent_fb2 = articleContent; + if(localStorage.getItem("nowWord").indexOf(word) !== -1){ + while(articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()) !== -1){ + // 找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。 + const index = articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()); + word = articleContent_fb2.substring(index, index + word.length); + articleContent_fb2 = articleContent_fb2.substring(index + word.length); // 使用副本中list[i]之后的子串替换掉副本 + articleContent = articleContent.replace(new RegExp(""+word+"", "g"), word) + } + pickedWords.value = localStorage.getItem("nowWord").replace(word,""); + document.getElementById("article").innerHTML = articleContent; + return; + } + } let totalSet = new Set(); for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符 From 101506a5119bd28e3df2d994d5abe3e47b721d6a Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Tue, 21 May 2024 20:00:32 +0800 Subject: [PATCH 03/15] test and fix --- app/static/js/highlight.js | 13 ++++- app/templates/userpage_get.html | 2 +- app/test/test_bug545_HuangHuiLing.py | 74 ++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 app/test/test_bug545_HuangHuiLing.py diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index e776bb3..d75dace 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -22,6 +22,7 @@ function getWord() { function highLight() { if (!isHighlight) return; + let word = (getWord() + "").trim(); let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器 let pickedWords = document.getElementById("selected-words"); // words picked to the text area let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list @@ -45,13 +46,23 @@ function highLight() { let totalSet = new Set(); for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符 - if (list[i] != "" && !totalSet.has(list[i])) { + list[i] = list[i].replace('|', ""); + list[i] = list[i].replace('?', ""); + if (list[i] != "" && !totalSet.has(list[i]) && "".indexOf(list[i]) === -1 && "".indexOf(list[i]) === -1) { // 返回所有匹配单词的集合, 正则表达式RegExp()中, "\b"匹配一个单词的边界, g 表示全局匹配, i 表示对大小写不敏感。 let matches = new Set(articleContent.match(new RegExp("\\b" + list[i] + "\\b", "gi"))); + let articleContent_fb = articleContent; //文章副本 if (matches.has("mark")) { // 优先处理单词为 "mark" 的情况 totalSet = new Set(["mark", ...totalSet]); } + while(articleContent_fb.toLowerCase().indexOf(list[i].toLowerCase()) !== -1 && list[i]!=""){ + //找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。 + const index = articleContent_fb.toLowerCase().indexOf(list[i].toLowerCase()); + list[i] = articleContent_fb.substring(index, index + list[i].length); + articleContent_fb = articleContent_fb.substring(index + list[i].length); // 使用副本中list[i]之后的子串替换掉副本 + articleContent = articleContent.replace(new RegExp("\\b"+list[i]+"\\b","g"),"" + list[i] + ""); + } totalSet = new Set([...totalSet, ...matches]); } } diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index edb8bf2..57461c1 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -291,7 +291,7 @@ diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py new file mode 100644 index 0000000..bff8c13 --- /dev/null +++ b/app/test/test_bug545_HuangHuiLing.py @@ -0,0 +1,74 @@ +import random +import string +import time +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.action_chains import ActionChains + +from helper import signup + + +def has_punctuation(s): + return any(c in string.punctuation for c in s) + + +def select(driver): + text_element = driver.find_element(By.ID, 'article') + + # 创建ActionChains对象 + actions = ActionChains(driver) + + # 模拟鼠标移动到文本元素上 + actions.move_to_element(text_element) + + # 模拟鼠标按下并拖动以选择文本 + # 假设我们想要选择从第10个字符开始的5个字符 + actions.click() + actions.perform() + time.sleep(5) + # 找到包含要选择文字的元素 + text_element = driver.find_element(By.ID, 'article_title') + + # 创建ActionChains对象 + actions = ActionChains(driver) + + # 模拟鼠标移动到文本元素上 + actions.move_to_element(text_element) + + # 模拟鼠标按下并拖动以选择文本 + # 假设我们想要选择从第10个字符开始的5个字符 + actions.double_click() + actions.perform() + #actions.move_by_offset(100, 0) + #actions.move_by_offset(10, 0) + actions.release() # 释放鼠标按钮 + +def test_selected_second_word(driver, URL): + try: + username, password = signup(URL, driver) + # 找到包含要选择文字的元素 + text_element = driver.find_element(By.ID, 'article_title') + + # 创建ActionChains对象 + actions = ActionChains(driver) + + # 模拟鼠标移动到文本元素上 + actions.move_to_element(text_element) + + # 模拟鼠标按下并拖动以选择文本 + # 假设我们想要选择从第10个字符开始的5个字符 + actions.double_click() + actions.perform() + #actions.move_by_offset(10, 0) + + # 获取选中的文本 + selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') + assert selected_words != "","选中单词被放置框中" + #再次选取 + select(driver) + time.sleep(6) + selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') + assert selected_second_words.strip() == "", "选中的单词被删除" + finally: + driver.quit() From 630cb6befa2f050e25e93fa626163b7e6baa67c0 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Tue, 21 May 2024 20:34:28 +0800 Subject: [PATCH 04/15] delete --- app/test/test_bug545_HuangHuiLing.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index bff8c13..04897af 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -37,11 +37,8 @@ def select(driver): actions.move_to_element(text_element) # 模拟鼠标按下并拖动以选择文本 - # 假设我们想要选择从第10个字符开始的5个字符 actions.double_click() actions.perform() - #actions.move_by_offset(100, 0) - #actions.move_by_offset(10, 0) actions.release() # 释放鼠标按钮 def test_selected_second_word(driver, URL): @@ -57,10 +54,8 @@ def test_selected_second_word(driver, URL): actions.move_to_element(text_element) # 模拟鼠标按下并拖动以选择文本 - # 假设我们想要选择从第10个字符开始的5个字符 actions.double_click() actions.perform() - #actions.move_by_offset(10, 0) # 获取选中的文本 selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') From 29a673cd92efc8981ec4375fb9901b838a9de92d Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sat, 25 May 2024 11:59:38 +0800 Subject: [PATCH 05/15] change --- app/static/js/fillword.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/static/js/fillword.js b/app/static/js/fillword.js index d851123..04f2d7e 100644 --- a/app/static/js/fillword.js +++ b/app/static/js/fillword.js @@ -1,5 +1,5 @@ let isRead = true; -let isChoose = true; +let isChoose = localStorage.getItem('chooseChecked') !== 'false'; function getWord() { return window.getSelection ? window.getSelection() : document.selection.createRange().text; @@ -12,6 +12,7 @@ function fillInWord() { const element = document.getElementById("selected-words"); let index = (String)(element.value).indexOf(word); localStorage.setItem("nowWord",element.value); + localStorage.setItem('selectedWords', element.value); if(index === -1){ element.value = element.value + " " + word; } @@ -28,8 +29,16 @@ inputSlider.oninput = () => { function onReadClick() { isRead = !isRead; + localStorage.setItem('readChecked', isRead); } function onChooseClick() { isChoose = !isChoose; + localStorage.setItem('chooseChecked', isChoose); } + +// 如果网页刷新,停止播放声音 +if (performance.getEntriesByType("navigation")[0].type == "reload") { + Reader.stopRead(); +} + From fcd2c83904dc0f33a47bfd7da4646b5ff8baf863 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sat, 25 May 2024 12:03:37 +0800 Subject: [PATCH 06/15] change --- app/static/js/fillword.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/static/js/fillword.js b/app/static/js/fillword.js index 04f2d7e..2751a6a 100644 --- a/app/static/js/fillword.js +++ b/app/static/js/fillword.js @@ -1,4 +1,4 @@ -let isRead = true; +let isRead = localStorage.getItem('readChecked') !== 'false'; // default to true let isChoose = localStorage.getItem('chooseChecked') !== 'false'; function getWord() { From d1589f60628da0cfd1f4e121dd964f0270e3be4e Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sat, 25 May 2024 15:14:31 +0800 Subject: [PATCH 07/15] time.sleep(1) --- app/test/test_bug545_HuangHuiLing.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 04897af..97860d0 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -9,10 +9,6 @@ from selenium.webdriver.common.action_chains import ActionChains from helper import signup -def has_punctuation(s): - return any(c in string.punctuation for c in s) - - def select(driver): text_element = driver.find_element(By.ID, 'article') @@ -26,7 +22,7 @@ def select(driver): # 假设我们想要选择从第10个字符开始的5个字符 actions.click() actions.perform() - time.sleep(5) + time.sleep(1) # 找到包含要选择文字的元素 text_element = driver.find_element(By.ID, 'article_title') @@ -62,7 +58,7 @@ def test_selected_second_word(driver, URL): assert selected_words != "","选中单词被放置框中" #再次选取 select(driver) - time.sleep(6) + time.sleep(1) selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') assert selected_second_words.strip() == "", "选中的单词被删除" finally: From 624426b6cf5dda2d599e3fafcad104ae51345f10 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sat, 25 May 2024 15:20:31 +0800 Subject: [PATCH 08/15] change --- app/test/test_bug545_HuangHuiLing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 97860d0..42b1112 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -19,7 +19,6 @@ def select(driver): actions.move_to_element(text_element) # 模拟鼠标按下并拖动以选择文本 - # 假设我们想要选择从第10个字符开始的5个字符 actions.click() actions.perform() time.sleep(1) From f3b9fd879062e35674127baafa7aa6dde1e4f84e Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sat, 25 May 2024 15:24:49 +0800 Subject: [PATCH 09/15] change --- app/test/test_bug545_HuangHuiLing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 42b1112..4b80afa 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -54,7 +54,7 @@ def test_selected_second_word(driver, URL): # 获取选中的文本 selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') - assert selected_words != "","选中单词被放置框中" + #再次选取 select(driver) time.sleep(1) From 85a3a9ce6a2469ab710e0a3db5c400da5a578f58 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sun, 26 May 2024 11:19:28 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E8=BF=99=E9=87=8C=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=86=99=E5=A4=9A=E4=BD=99=E4=BA=86=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BA=86=E4=B8=80=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/fillword.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/static/js/fillword.js b/app/static/js/fillword.js index 2751a6a..421d972 100644 --- a/app/static/js/fillword.js +++ b/app/static/js/fillword.js @@ -10,12 +10,9 @@ function fillInWord() { if (isRead) Reader.read(word, inputSlider.value); if (!isChoose) return; const element = document.getElementById("selected-words"); - let index = (String)(element.value).indexOf(word); - localStorage.setItem("nowWord",element.value); + localStorage.setItem('nowWords', element.value); + element.value = element.value + " " + word; localStorage.setItem('selectedWords', element.value); - if(index === -1){ - element.value = element.value + " " + word; - } } document.getElementById("text-content").addEventListener("click", fillInWord, false); From 95370243396eaf5d64cc18e06cc2b4aacf928280 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sun, 26 May 2024 11:22:20 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E5=8D=95=E8=AF=8D=EF=BC=8C=E7=94=B1=E4=BA=8E?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E9=AB=98=E4=BA=AE=E5=8D=95=E8=AF=8D=E7=9A=84?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=94=B1=E6=94=B9=E4=B8=BA=E4=BA=86=EF=BC=8C=E6=89=80=E4=BB=A5=E5=9C=A8=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=8D=95=E8=AF=8D=E9=AB=98=E4=BA=AE=E7=8A=B6=E6=80=81=E6=97=B6?= =?UTF-8?q?=E5=B0=86=E6=A0=87=E7=AD=BE=E5=9D=87=E6=94=B9=E4=B8=BA=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E6=9B=BF=E6=8D=A2=E6=97=B6=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B9=9F=E5=86=97=E4=BD=99=E4=BA=86=EF=BC=8C=E6=89=80?= =?UTF-8?q?=E4=BB=A5=E4=B9=9F=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=88=A0=E9=99=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/highlight.js | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 245931e..939d691 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -30,15 +30,9 @@ function highLight() { const list = allWords.split(" "); // 将所有的生词放入一个list中 if(word !== null && word !== "" && word !== " "){ let articleContent_fb2 = articleContent; - if(localStorage.getItem("nowWord").indexOf(word) !== -1){ - while(articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()) !== -1){ - // 找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。 - const index = articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()); - word = articleContent_fb2.substring(index, index + word.length); - articleContent_fb2 = articleContent_fb2.substring(index + word.length); // 使用副本中list[i]之后的子串替换掉副本 - articleContent = articleContent.replace(new RegExp(""+word+"", "g"), word) - } - pickedWords.value = localStorage.getItem("nowWord").replace(word,""); + if(localStorage.getItem("nowWords").indexOf(word) !== -1 || localStorage.getItem("nowWords").indexOf(word.toLowerCase()) !== -1){ + articleContent = articleContent.replace(new RegExp('' + word + '', "gi"), word); + pickedWords.value = localStorage.getItem("nowWords").replace(word,""); document.getElementById("article").innerHTML = articleContent; return; } @@ -48,39 +42,26 @@ function highLight() { list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符 list[i] = list[i].replace('|', ""); list[i] = list[i].replace('?', ""); - if (list[i] != "" && !totalSet.has(list[i]) && "".indexOf(list[i]) === -1 && "".indexOf(list[i]) === -1) { + if (list[i] != "" && !totalSet.has(list[i])) { // 返回所有匹配单词的集合, 正则表达式RegExp()中, "\b"匹配一个单词的边界, g 表示全局匹配, i 表示对大小写不敏感。 let matches = new Set(articleContent.match(new RegExp("\\b" + list[i] + "\\b", "gi"))); - let articleContent_fb = articleContent; //文章副本 - if (matches.has("mark")) { - // 优先处理单词为 "mark" 的情况 - totalSet = new Set(["mark", ...totalSet]); - } - while(articleContent_fb.toLowerCase().indexOf(list[i].toLowerCase()) !== -1 && list[i]!=""){ - //找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。 - const index = articleContent_fb.toLowerCase().indexOf(list[i].toLowerCase()); - list[i] = articleContent_fb.substring(index, index + list[i].length); - articleContent_fb = articleContent_fb.substring(index + list[i].length); // 使用副本中list[i]之后的子串替换掉副本 - articleContent = articleContent.replace(new RegExp("\\b"+list[i]+"\\b","g"),"" + list[i] + ""); - } totalSet = new Set([...totalSet, ...matches]); } } - // 删除所有的mark标签,防止标签发生嵌套 - articleContent = articleContent.replace(/<(mark)[^>]*>/gi, ""); - articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, ""); + // 删除所有的""标签,防止标签发生嵌套 + articleContent = articleContent.replace(new RegExp('',"gi"), "") + articleContent = articleContent.replace(new RegExp("","gi"), ""); // 将文章中所有出现该单词word的地方改为:"" + word + ""。 for (let word of totalSet) { articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "" + word + ""); } document.getElementById("article").innerHTML = articleContent; - } function cancelHighlighting() { let articleContent = document.getElementById("article").innerHTML; - articleContent = articleContent.replace(/<(mark)[^>]*>/gi, ""); - articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, ""); + articleContent = articleContent.replace(new RegExp('',"gi"), "") + articleContent = articleContent.replace(new RegExp("","gi"), ""); document.getElementById("article").innerHTML = articleContent; } From 64a82bee228e2c6bacbea300f595760556a4afa8 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sun, 26 May 2024 11:27:15 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B9=9F=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E4=B8=BA=E4=BA=86=E9=81=BF=E5=85=8D=E9=80=89=E6=8B=A9=E7=9A=84?= =?UTF-8?q?=E5=8D=95=E8=AF=8D=E5=87=BA=E7=8E=B0=E7=A9=BA=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=88=A4=E6=96=AD=EF=BC=8C=E8=8B=A5=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=EF=BC=8C=E5=88=99=E6=9B=B4=E6=8D=A2=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E5=86=8D=E6=AC=A1=E9=80=89=E6=8B=A9=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E6=80=BB=E4=BC=9A=E9=80=89=E6=8B=A9=E5=88=B0=E9=9D=9E?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E7=9A=84=E5=8D=95=E8=AF=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug545_HuangHuiLing.py | 71 +++++++++++++--------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 4b80afa..4ebc504 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -9,55 +9,50 @@ from selenium.webdriver.common.action_chains import ActionChains from helper import signup -def select(driver): - text_element = driver.find_element(By.ID, 'article') - +def select_one(driver): + question = driver.find_element(By.ID, 'question') # 创建ActionChains对象 actions = ActionChains(driver) # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) - - # 模拟鼠标按下并拖动以选择文本 - actions.click() - actions.perform() - time.sleep(1) - # 找到包含要选择文字的元素 - text_element = driver.find_element(By.ID, 'article_title') - - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) + actions.move_to_element(question) # 模拟鼠标按下并拖动以选择文本 actions.double_click() actions.perform() - actions.release() # 释放鼠标按钮 + + # 获取选中的文本 + return driver.find_element(By.ID, 'selected-words').get_attribute('value') + +def select_two(driver): + question = driver.find_element(By.ID, 'question') + article = driver.find_element(By.ID, 'article_title') + +# 创建ActionChains对象 + actions = ActionChains(driver) + actions.move_to_element(article) + actions.click() + time.sleep(1) +# 模拟鼠标移动到文本元素上 + actions.move_to_element(question) + + # 模拟鼠标按下并拖动以选择文本 + actions.double_click() + actions.perform() + def test_selected_second_word(driver, URL): try: - username, password = signup(URL, driver) - # 找到包含要选择文字的元素 - text_element = driver.find_element(By.ID, 'article_title') - - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) - - # 模拟鼠标按下并拖动以选择文本 - actions.double_click() - actions.perform() - - # 获取选中的文本 - selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') - - #再次选取 - select(driver) - time.sleep(1) + signup(URL, driver) + selected_words = select_one(driver); + while selected_words.strip() == "": + load_next_article = driver.find_element(By.ID, "load_next_article") + action_chains = ActionChains(driver) + action_chains.click(load_next_article).perform() + time.sleep(1) + selected_words = select_one(driver) + assert selected_words.strip() != "", "选中的单词被放置框中" + select_two(driver) selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') assert selected_second_words.strip() == "", "选中的单词被删除" finally: From 101c359596c75d60a700f52deb2d200a8452b27a Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sun, 26 May 2024 11:32:39 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E6=88=91=E5=B0=86tangxinyuan=E5=B0=8F?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=8B=EF=BC=8C=E5=8F=AA=E6=98=AF=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=8B=E7=82=B9=E5=87=BB=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E5=B0=86=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E9=80=80=E5=87=BA=E6=8C=89=E9=92=AE=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?ActionChains=E5=8E=BB=E7=82=B9=E5=87=BB=EF=BC=8C=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E6=88=91=E6=B5=8B=E8=AF=95=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E7=94=A8driver=E5=8E=BB=E7=82=B9=E5=87=BB=E5=A4=A7?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BC=9A=E6=8A=A5=E5=87=BA'=E9=80=80?= =?UTF-8?q?=E5=87=BA'=E7=9A=84=E6=8C=89=E9=92=AE=E8=A2=AB=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E6=8B=A6=E6=88=AA=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug544_tangxinyuan.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/test/test_bug544_tangxinyuan.py b/app/test/test_bug544_tangxinyuan.py index 43bfa8c..729c857 100644 --- a/app/test/test_bug544_tangxinyuan.py +++ b/app/test/test_bug544_tangxinyuan.py @@ -1,5 +1,8 @@ import random import string +import time + +from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC @@ -36,7 +39,8 @@ def test_save_selected_word(driver, URL): stored_words = driver.execute_script('return localStorage.getItem("selectedWords");') assert word == stored_words, "Selected word not saved to localStorage correctly" # 退出并重新登录以检查存储的单词 - driver.find_element(By.LINK_TEXT, '退出').click() + action_chains = ActionChains(driver) + action_chains.click(driver.find_element(By.LINK_TEXT, '退出')).perform() driver.execute_script("window.open('');window.close();") # 等待一会儿,让浏览器有足够的时间关闭标签页 From 4a42c5c22c97b9307267a4dcb3601ad680d15cf9 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 27 May 2024 14:26:54 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E6=88=91=E5=8F=88=E5=B0=86tangxinyuan?= =?UTF-8?q?=E5=B0=8F=E7=BB=84=E7=9A=84=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=94=B9=E5=9B=9E=E5=8E=BB=E4=BA=86=EF=BC=8C=E6=88=91=E6=94=B9?= =?UTF-8?q?=E5=AE=8C=E6=88=91=E7=9A=84=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=EF=BC=8C=E5=8F=AA=E6=9C=89=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9C=AA=E7=BB=8F=E6=88=91=E4=BF=AE=E6=94=B9=E7=9A=84tangxinyu?= =?UTF-8?q?an=E5=B0=8F=E7=BB=84=E7=9A=84=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=89=8D=E8=83=BD=E9=80=9A=E8=BF=87=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug544_tangxinyuan.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/test/test_bug544_tangxinyuan.py b/app/test/test_bug544_tangxinyuan.py index 729c857..2cffdd4 100644 --- a/app/test/test_bug544_tangxinyuan.py +++ b/app/test/test_bug544_tangxinyuan.py @@ -2,7 +2,6 @@ import random import string import time -from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC @@ -39,8 +38,7 @@ def test_save_selected_word(driver, URL): stored_words = driver.execute_script('return localStorage.getItem("selectedWords");') assert word == stored_words, "Selected word not saved to localStorage correctly" # 退出并重新登录以检查存储的单词 - action_chains = ActionChains(driver) - action_chains.click(driver.find_element(By.LINK_TEXT, '退出')).perform() + driver.find_element(By.LINK_TEXT, '退出').click() driver.execute_script("window.open('');window.close();") # 等待一会儿,让浏览器有足够的时间关闭标签页 From a0c9b82ee7aaed8c10cd268f03e45e0ec0d7033d Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 27 May 2024 14:35:56 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E5=8F=82=E8=80=83=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8Btangxinyuan=E5=B0=8F=E7=BB=84=E7=9A=84=E5=86=99?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=B0=86=E9=80=89=E5=8F=96=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E7=94=B1=E6=A8=A1=E6=8B=9F=E9=BC=A0?= =?UTF-8?q?=E6=A0=87=E9=80=89=E5=8F=96=E5=8D=95=E8=AF=8D=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEid=E8=8E=B7=E5=8F=96=E6=96=87=E7=AB=A0?= =?UTF-8?q?=EF=BC=8C=E9=9A=8F=E6=9C=BA=E4=BB=8E=E6=96=87=E7=AB=A0=E4=B8=AD?= =?UTF-8?q?=E6=8C=91=E9=80=89=E4=B8=80=E4=B8=AA=E5=8D=95=E8=AF=8D=E6=94=BE?= =?UTF-8?q?=E5=85=A5=E7=94=9F=E8=AF=8D=E6=A1=86=E4=B8=AD=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E6=98=AF=E4=B8=80=E5=AE=9A=E5=8F=AF=E4=BB=A5=E9=80=89?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E6=96=87=E7=AB=A0=E4=B8=AD=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E8=AF=8D=E3=80=82=20=E7=84=B6=E5=90=8E=E6=A0=B9=E6=8D=AEspan?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=AE=9A=E4=BD=8D=E5=88=B0=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E8=AF=8D=EF=BC=8C=E5=8F=8C=E5=87=BB=E5=86=8D?= =?UTF-8?q?=E6=AC=A1=E9=80=89=E6=8B=A9=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=9C=A8?= =?UTF-8?q?=E7=94=9F=E8=AF=8D=E6=A1=86=E4=B8=AD=E5=88=A0=E9=99=A4=E8=AF=A5?= =?UTF-8?q?=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug545_HuangHuiLing.py | 39 +++++++++------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 4ebc504..21ddeea 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -8,33 +8,24 @@ from selenium.webdriver.common.action_chains import ActionChains from helper import signup +def has_punctuation(s): + return any(c in string.punctuation for c in s) def select_one(driver): - question = driver.find_element(By.ID, 'question') - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(question) - - # 模拟鼠标按下并拖动以选择文本 - actions.double_click() - actions.perform() - - # 获取选中的文本 - return driver.find_element(By.ID, 'selected-words').get_attribute('value') + elem = driver.find_element(By.ID, 'article') + essay_content = elem.text + valid_word = random.choice([word for word in essay_content.split() if len(word) >= 6 and not has_punctuation( + word) and 'font>' not in word and 'br>' not in word and 'p>' not in word]) + driver.find_element(By.ID, 'selected-words').send_keys(valid_word) + driver.find_element(By.ID, 'article').click() + return valid_word def select_two(driver): - question = driver.find_element(By.ID, 'question') - article = driver.find_element(By.ID, 'article_title') + word = driver.find_element(By.CLASS_NAME, 'highlighted') -# 创建ActionChains对象 + # 创建ActionChains对象 actions = ActionChains(driver) - actions.move_to_element(article) - actions.click() - time.sleep(1) -# 模拟鼠标移动到文本元素上 - actions.move_to_element(question) + actions.move_to_element(word) # 模拟鼠标按下并拖动以选择文本 actions.double_click() @@ -45,12 +36,6 @@ def test_selected_second_word(driver, URL): try: signup(URL, driver) selected_words = select_one(driver); - while selected_words.strip() == "": - load_next_article = driver.find_element(By.ID, "load_next_article") - action_chains = ActionChains(driver) - action_chains.click(load_next_article).perform() - time.sleep(1) - selected_words = select_one(driver) assert selected_words.strip() != "", "选中的单词被放置框中" select_two(driver) selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')