Bug555-chenshiying #174
|
@ -108,7 +108,7 @@
|
||||||
|
|
||||||
<p><b id="question">{{ today_article['question'] }}</b></p><br/>
|
<p><b id="question">{{ today_article['question'] }}</b></p><br/>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function toggle_visibility(id) { {# https://css-tricks.com/snippets/javascript/showhide-element/#}
|
function toggle_visibility(id) {
|
||||||
const e = document.getElementById(id);
|
const e = document.getElementById(id);
|
||||||
if (e.style.display === 'block')
|
if (e.style.display === 'block')
|
||||||
e.style.display = 'none';
|
e.style.display = 'none';
|
||||||
|
@ -195,55 +195,11 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.onload = function () { // 页面加载时执行
|
|
||||||
const settings = {
|
|
||||||
// initialize settings from localStorage
|
|
||||||
highlightChecked: localStorage.getItem('highlightChecked') !== 'false', // localStorage stores strings, default to true. same below
|
|
||||||
readChecked: localStorage.getItem('readChecked') !== 'false',
|
|
||||||
chooseChecked: localStorage.getItem('chooseChecked') !== 'false',
|
|
||||||
rangeValue: localStorage.getItem('rangeValue') || '1',
|
|
||||||
selectedWords: localStorage.getItem('selectedWords') || ''
|
|
||||||
};
|
|
||||||
|
|
||||||
const elements = {
|
|
||||||
highlightCheckbox: document.querySelector('#highlightCheckbox'),
|
|
||||||
readCheckbox: document.querySelector('#readCheckbox'),
|
|
||||||
chooseCheckbox: document.querySelector('#chooseCheckbox'),
|
|
||||||
rangeComponent: document.querySelector('#rangeComponent'),
|
|
||||||
rangeValueDisplay: document.querySelector('#rangeValue'),
|
|
||||||
selectedWordsInput: document.querySelector('#selected-words')
|
|
||||||
};
|
|
||||||
// 应用设置到页面元素
|
|
||||||
elements.highlightCheckbox.checked = settings.highlightChecked;
|
|
||||||
elements.readCheckbox.checked = settings.readChecked;
|
|
||||||
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')) {
|
|
||||||
$('#load_pre_article').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 事件监听器
|
|
||||||
elements.selectedWordsInput.addEventListener('input', () => {
|
|
||||||
localStorage.setItem('selectedWords', elements.selectedWordsInput.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.rangeComponent.addEventListener('input', () => {
|
|
||||||
const rangeValue = elements.rangeComponent.value;
|
|
||||||
elements.rangeValueDisplay.textContent = `${rangeValue}x`;
|
|
||||||
localStorage.setItem('rangeValue', rangeValue);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function clearSelectedWords() {
|
function clearSelectedWords() {
|
||||||
localStorage.removeItem('selectedWords');
|
localStorage.removeItem('selectedWords');
|
||||||
document.querySelector('#selected-words').value = '';
|
document.querySelector('#selected-words').value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function load_next_article() {
|
function load_next_article() {
|
||||||
$("#load_next_article").prop("disabled", true)
|
$("#load_next_article").prop("disabled", true)
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -295,7 +251,6 @@
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- 检查是否存在上一篇或下一篇,不存在则对应按钮隐藏-->
|
|
||||||
function check_pre(visited_articles) {
|
function check_pre(visited_articles) {
|
||||||
if ((visited_articles == '') || (visited_articles['index'] <= 0)) {
|
if ((visited_articles == '') || (visited_articles['index'] <= 0)) {
|
||||||
$('#load_pre_article').hide();
|
$('#load_pre_article').hide();
|
||||||
|
@ -321,13 +276,74 @@
|
||||||
$('#read_all').show();
|
$('#read_all').show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function longPolling() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/get_next_article/{{username}}', // 这里的URL根据需要更改
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
if (data['today_article']) {
|
||||||
|
update(data['today_article']);
|
||||||
|
check_pre(data['visited_articles']);
|
||||||
|
check_next(data['result_of_generate_article']);
|
||||||
|
toggleHighlighting();
|
||||||
|
}
|
||||||
|
// 发起下一次Long Polling请求
|
||||||
|
longPolling();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
// 处理错误情况
|
||||||
|
// 发起下一次Long Polling请求
|
||||||
|
longPolling();
|
||||||
|
},
|
||||||
|
timeout: 30000 // 设置超时时间,单位为毫秒
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function () { // 页面加载时执行
|
||||||
|
longPolling();
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
// initialize settings from localStorage
|
||||||
|
highlightChecked: localStorage.getItem('highlightChecked') !== 'false', // localStorage stores strings, default to true. same below
|
||||||
|
readChecked: localStorage.getItem('readChecked') !== 'false',
|
||||||
|
chooseChecked: localStorage.getItem('chooseChecked') !== 'false',
|
||||||
|
rangeValue: localStorage.getItem('rangeValue') || '1',
|
||||||
|
selectedWords: localStorage.getItem('selectedWords') || ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const elements = {
|
||||||
|
highlightCheckbox: document.querySelector('#highlightCheckbox'),
|
||||||
|
readCheckbox: document.querySelector('#readCheckbox'),
|
||||||
|
chooseCheckbox: document.querySelector('#chooseCheckbox'),
|
||||||
|
rangeComponent: document.querySelector('#rangeComponent'),
|
||||||
|
rangeValueDisplay: document.querySelector('#rangeValue'),
|
||||||
|
selectedWordsInput: document.querySelector('#selected-words')
|
||||||
|
};
|
||||||
|
// 应用设置到页面元素
|
||||||
|
elements.highlightCheckbox.checked = settings.highlightChecked;
|
||||||
|
elements.readCheckbox.checked = settings.readChecked;
|
||||||
|
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')) {
|
||||||
|
$('#load_pre_article').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 事件监听器
|
||||||
|
elements.selectedWordsInput.addEventListener('input', () => {
|
||||||
|
localStorage.setItem('selectedWords', elements.selectedWordsInput.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.rangeComponent.addEventListener('input', () => {
|
||||||
|
const rangeValue = elements.rangeComponent.value;
|
||||||
|
elements.rangeValueDisplay.textContent = `${rangeValue}x`;
|
||||||
|
localStorage.setItem('rangeValue', rangeValue);
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
<style>
|
</html>
|
||||||
mark {
|
|
||||||
color: #{{ yml['highlight']['color'] }};
|
|
||||||
background-color: rgba(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</html>
|
|
Binary file not shown.
|
@ -9,5 +9,7 @@ def URL():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def driver():
|
def driver():
|
||||||
my_driver = webdriver.Edge() # uncomment this line if you wish to run the test on your laptop
|
my_driver = webdriver.Chrome()
|
||||||
return my_driver
|
return my_driver
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import time
|
||||||
|
import pytest
|
||||||
|
import uuid
|
||||||
|
from selenium import webdriver
|
||||||
|
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
|
||||||
|
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException, NoSuchElementException, \
|
||||||
|
TimeoutException
|
||||||
|
from conftest import URL
|
||||||
|
driver = webdriver.Chrome()
|
||||||
|
def test_bug555():
|
||||||
|
try:
|
||||||
|
driver.maximize_window()
|
||||||
|
base_url = "http://127.0.0.1:5000"
|
||||||
|
driver.get(base_url)
|
||||||
|
article = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'article')))
|
||||||
|
perform_actions_on_article(driver, article)
|
||||||
|
|
||||||
|
next_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_next_article')))
|
||||||
|
next_button.click()
|
||||||
|
print("Clicked next article button.")
|
||||||
|
|
||||||
|
prev_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article')))
|
||||||
|
prev_button.click()
|
||||||
|
print("Clicked previous article button.")
|
||||||
|
|
||||||
|
except (TimeoutException, NoSuchElementException) as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
driver.quit()
|
||||||
|
print("Driver closed.")
|
||||||
|
|
||||||
|
def perform_actions_on_article(driver, article):
|
||||||
|
actions = ActionChains(driver)
|
||||||
|
actions.move_to_element(article)
|
||||||
|
actions.click_and_hold()
|
||||||
|
actions.move_by_offset(450, 200)
|
||||||
|
actions.release()
|
||||||
|
actions.perform()
|
||||||
|
print("Performed actions on article.")
|
Loading…
Reference in New Issue