From 623b5ab3663277bb16db330a282dc21f2f578c8b Mon Sep 17 00:00:00 2001
From: Hui Lan <lanhui@zjnu.edu.cn>
Date: Tue, 13 Jul 2021 11:56:07 +0800
Subject: =?UTF-8?q?Add=20app/test/test=5Fpage=5Fposition.py=20made=20by=20?=
 =?UTF-8?q?group=20SPM-Spring2021-2597-=E5=8D=A0=E5=81=A5=E8=B1=AA20183199?=
 =?UTF-8?q?0539?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/test/test_page_position.py | 59 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 app/test/test_page_position.py

(limited to 'app/test/test_page_position.py')

diff --git a/app/test/test_page_position.py b/app/test/test_page_position.py
new file mode 100644
index 0000000..21a6722
--- /dev/null
+++ b/app/test/test_page_position.py
@@ -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()
-- 
cgit v1.2.1