0
0
Fork 0

Merge branch 'SPM-Spring2021-2597-占健豪201831990539' of https://github.com/lanlab-org/EnglishPal

Lanhui-add-articles
Hui Lan 2021-07-13 11:46:37 +08:00
commit 905e85f201
3 changed files with 75 additions and 1 deletions

5
Readme.md Normal file
View File

@ -0,0 +1,5 @@
Click the Familiar or Unfamiliar button (current word frequency>1), the current word position is displayed at the top of the page;
Click the Familiar or Unfamiliar button (current word frequency is 1), and the page will be displayed as the top of the entire page.
Demo video link: https://b23.tv/QuB77m

View File

@ -274,12 +274,14 @@ def user_mark_word(username):
def unfamiliar(username,word):
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
pickle_idea.unfamiliar(user_freq_record,word)
session['thisWord'] = word # 1. put a word into session
return redirect(url_for('userpage', username=username))
@app.route("/<username>/<word>/familiar", methods=['GET', 'POST'])
def familiar(username,word):
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
pickle_idea.familiar(user_freq_record,word)
session['thisWord'] = word # 1. put a word into session
return redirect(url_for('userpage', username=username))
@app.route("/<username>/<word>/del", methods=['GET', 'POST'])
@ -349,7 +351,13 @@ def userpage(username):
document.getElementById("text-content").addEventListener("touchstart", fillinWord, false);
</script>
'''
if session.get('thisWord'):
page += '''
<script type="text/javascript">
location.href = "#aaa" // 2. define a anchor URL and point to the anchor in the page whose id is aaa
</script>
'''
d = load_freq_history(user_freq_record)
if len(d) > 0:
page += '<p><b>我的生词簿</b></p>'
@ -360,6 +368,8 @@ def userpage(username):
for x in sort_in_descending_order(lst2):
word = x[0]
freq = x[1]
if session.get('thisWord') == x[0]:
page += '<a name="aaa"></a>' # 3. anchor
if isinstance(d[word], list): # d[word] is a list of dates
if freq > 1:
page += '<p class="new-word"> <a href="%s">%s</a>(<a title="%s">%d</a>) <a href="%s/%s/familiar">熟悉</a> <a href="%s/%s/unfamiliar">不熟悉</a> <a href="%s/%s/del">删除</a> </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word, username,word)

View File

@ -0,0 +1,59 @@
"""
Click the Familiar or Unfamiliar button. Specifically, we plan to make the following improvements:
Click the Familiar or Unfamiliar button (current word frequency>1), the current word position is displayed at the top of the page;
Click the Familiar or Unfamiliar button (current word frequency is 1), and the page will be displayed as the top of the entire page.
"""
from random import randint
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME)
driver.implicitly_wait(10)
HOME_PAGE = 'http://121.4.94.30:91/'
def click_by_random(text):
elements = driver.find_elements_by_link_text(text) # 点击单词表中的第一个单词的熟悉按钮
elements[randint(0, len(elements) - 1)].click()
try:
location = driver.find_element_by_xpath('//a[@name="aaa"]').location # 点击后单词次数≥1
roll_height = get_scrollTop() # 获取滚动条的位置
assert int(location['y'] - roll_height) == 0 # 差值小于1
except NoSuchElementException: # 点击后单词消失scrollTop=0页面回到最上面
roll_height = get_scrollTop()
assert roll_height == 0
def get_scrollTop():
js = 'var h = document.body.scrollTop;' + 'return h'
roll_height = driver.execute_script(js)
return roll_height
def test_page_position():
try:
driver.get(HOME_PAGE)
# login
driver.find_element_by_link_text('登录').click()
uname = 'lanhui'
password = 'l0ve1t'
driver.find_element_by_name('username').send_keys(uname)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_xpath('//form[1]/p[3]/input[1]').click() # 找到登录按钮
# 这里随机测试三个单词,点击熟悉
click_by_random('熟悉')
click_by_random('熟悉')
click_by_random('熟悉')
# 这里随机测试三个单词,点击不熟悉
click_by_random('不熟悉')
click_by_random('不熟悉')
click_by_random('不熟悉')
finally:
driver.quit()