From f8a5cc2a40a51492e8fcb78d572037cec759f582 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Fri, 3 Dec 2021 09:16:18 +0800 Subject: [PATCH] test: use localhost to test --- app/test/test_add_word.py | 15 +++++++-------- .../test_add_word_and_essay_does_not_change.py | 15 +++++++-------- app/test/test_delete_word.py | 14 +++++--------- app/test/test_login.py | 16 +++++++--------- app/test/test_login_security_fix.py | 11 +++++------ app/test/test_next_essay.py | 13 +++++-------- app/test/test_page_position.py | 13 ++++--------- app/test/test_signup.py | 14 +++++++------- 8 files changed, 47 insertions(+), 64 deletions(-) diff --git a/app/test/test_add_word.py b/app/test/test_add_word.py index a08c376..ffac643 100644 --- a/app/test/test_add_word.py +++ b/app/test/test_add_word.py @@ -6,19 +6,18 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import random, time import string +import pytest -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) - -HOME_PAGE = 'http://121.4.94.30:91/' - +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) def has_punctuation(s): return [c for c in s if c in string.punctuation] != [] - -def test_add_word(): + +@pytest.mark.usefixtures +def test_add_word(URL, driver): try: - driver.get(HOME_PAGE) + driver.get(URL) assert 'English Pal -' in driver.page_source # login diff --git a/app/test/test_add_word_and_essay_does_not_change.py b/app/test/test_add_word_and_essay_does_not_change.py index 2746657..8ee81d0 100644 --- a/app/test/test_add_word_and_essay_does_not_change.py +++ b/app/test/test_add_word_and_essay_does_not_change.py @@ -3,22 +3,21 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, time import string -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) - -HOME_PAGE = 'http://121.4.94.30:91/' +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) def has_punctuation(s): return [c for c in s if c in string.punctuation] != [] - -def test_add_word_and_essay_does_not_change(): + +@pytest.mark.usefixtures +def test_add_word_and_essay_does_not_change(URL, driver): try: - driver.get(HOME_PAGE) + driver.get(URL) assert 'English Pal -' in driver.page_source # login diff --git a/app/test/test_delete_word.py b/app/test/test_delete_word.py index 9dcad81..59128a7 100644 --- a/app/test/test_delete_word.py +++ b/app/test/test_delete_word.py @@ -3,25 +3,22 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, time import string # 调用本地chromedriver # driver = webdriver.Chrome(executable_path="D:\ChromeDriver\chromedriver.exe") # driver.get("http://127.0.0.1:5000/") -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) # driver.maximize_window() # HOME_PAGE = "http://127.0.0.1:5000/" - -HOME_PAGE = 'http://121.4.94.30:91/' - - +@pytest.mark.usefixtures def test_delete_word(): try: - driver.get(HOME_PAGE) + driver.get(URL) assert 'English Pal -' in driver.page_source # login elem = driver.find_element_by_link_text('登录') @@ -58,4 +55,3 @@ def test_delete_word(): finally: driver.quit() -# test_delete_word() diff --git a/app/test/test_login.py b/app/test/test_login.py index bb4df51..d711cb0 100644 --- a/app/test/test_login.py +++ b/app/test/test_login.py @@ -3,19 +3,17 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, string -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) - -HOME_PAGE = 'http://121.4.94.30:91/' +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) - -def test_login(): +@pytest.mark.usefixtures +def test_login(URL, driver): try: - driver.get(HOME_PAGE) + driver.get(URL) driver.save_screenshot('./app/test/test_login_pic0.png') assert 'English Pal -' in driver.page_source @@ -41,7 +39,7 @@ def test_login(): assert uname in driver.page_source # logout - driver.get(HOME_PAGE + 'logout') + driver.get(URL + 'logout') driver.save_screenshot('./app/test/test_login_pic3.png') # login diff --git a/app/test/test_login_security_fix.py b/app/test/test_login_security_fix.py index 461aaba..f17122a 100644 --- a/app/test/test_login_security_fix.py +++ b/app/test/test_login_security_fix.py @@ -3,17 +3,16 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, string -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) - -HOME_PAGE = 'http://121.4.94.30:91/' +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) +@pytest.mark.usefixtures def test_login_security_fix(): try: - driver.get(HOME_PAGE) + driver.get(URL) elem = driver.find_element_by_link_text('登录') elem.click() diff --git a/app/test/test_next_essay.py b/app/test/test_next_essay.py index 9814e58..3d16577 100644 --- a/app/test/test_next_essay.py +++ b/app/test/test_next_essay.py @@ -3,17 +3,14 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, string, time -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) -HOME_PAGE = 'http://121.4.94.30:91/' - - - -def test_next(): +@pytest.mark.usefixtures +def test_next(URL, driver): try: driver.get(HOME_PAGE) assert 'English Pal -' in driver.page_source diff --git a/app/test/test_page_position.py b/app/test/test_page_position.py index be6ece3..4eb8ef9 100644 --- a/app/test/test_page_position.py +++ b/app/test/test_page_position.py @@ -6,15 +6,10 @@ Click the Familiar or Unfamiliar button (current word frequency is 1), and the p from random import randint from selenium import webdriver +import pytest from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.desired_capabilities import DesiredCapabilities -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -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() @@ -33,10 +28,10 @@ def get_scrollTop(): roll_height = driver.execute_script(js) return roll_height - -def test_page_position(): +@pytest.mark.usefixtures +def test_page_position(URL, driver): try: - driver.get(HOME_PAGE) + driver.get(URL) # login driver.find_element_by_link_text('登录').click() diff --git a/app/test/test_signup.py b/app/test/test_signup.py index a2664c5..d034107 100644 --- a/app/test/test_signup.py +++ b/app/test/test_signup.py @@ -3,19 +3,19 @@ # docker run -d -p 4444:4444 selenium/standalone-chrome from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities - +import pytest import random, string -driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) -driver.implicitly_wait(10) - -HOME_PAGE = 'http://121.4.94.30:91/' +#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX) +#driver.implicitly_wait(10) -def test_signup(): + +@pytest.mark.usefixtures +def test_signup(URL, driver): try: - driver.get(HOME_PAGE) + driver.get(URL) driver.save_screenshot('test_signup_pic0.png') assert 'English Pal -' in driver.page_source