Commit.
This commit is contained in:
parent
1274b94655
commit
8199a8d5b9
|
@ -0,0 +1,18 @@
|
|||
import logging
|
||||
|
||||
class Logger:
|
||||
"""
|
||||
Testing logger.
|
||||
"""
|
||||
def __init__(self, name: str = 'test'):
|
||||
self._logger = logging.getLogger(name)
|
||||
self._logger.setLevel(logging.DEBUG)
|
||||
self.d = self._logger.debug
|
||||
self.i = self._logger.info
|
||||
self.w = self._logger.warning
|
||||
self.e = self._logger.error
|
||||
self.f = self._logger.fatal
|
||||
self.c = self._logger.critical
|
||||
|
||||
|
||||
log = Logger()
|
|
@ -2,6 +2,7 @@ import tempfile
|
|||
import platform
|
||||
import shutil
|
||||
import glob
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
|
@ -14,6 +15,7 @@ def clear_selenium():
|
|||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def clear_driver_cache():
|
||||
for cache in ['scoped_dir*', 'chrome_BITS*', 'chrome_url_fetcher*']:
|
||||
for i in glob.glob('%s/%s' % (tempfile.gettempdir(), cache)):
|
||||
|
@ -23,7 +25,26 @@ def clear_driver_cache():
|
|||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# e.g. Clear
|
||||
clear_selenium()
|
||||
clear_driver_cache()
|
||||
def file_get_content(file, text=None):
|
||||
if not os.path.exists(file):
|
||||
return text
|
||||
return open(file=file, mode='r', encoding='utf-8').read()
|
||||
|
||||
|
||||
def file_put_content(file, text=None):
|
||||
return open(file=file, mode='w', encoding='utf-8').write(text)
|
||||
|
||||
|
||||
regular_clear = True
|
||||
try:
|
||||
selenium_clear_file = '%s/.selenium_clear_last' % tempfile.gettempdir()
|
||||
selenium_clear_last = file_get_content(selenium_clear_file, '0')
|
||||
try:
|
||||
if int(selenium_clear_last) + 86400 < int(time.time()):
|
||||
clear_selenium()
|
||||
clear_driver_cache()
|
||||
file_put_content(selenium_clear_file, str(int(time.time())))
|
||||
except ValueError:
|
||||
os.remove(selenium_clear_file)
|
||||
except Exception:
|
||||
pass
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from Lib.LoadConf import *
|
||||
from Lib.LoadData import *
|
||||
from Lib.Logger import *
|
||||
import pytest
|
||||
import allure
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from Lib.Driver import *
|
||||
|
||||
from Lib.SeleniumClear import regular_clear
|
||||
|
||||
class PageBase:
|
||||
def __init__(self, d: WebDriver):
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
from Pom.Home import *
|
||||
|
||||
|
||||
class PageSignup(PageHome):
|
||||
def open(self):
|
||||
self.home()
|
||||
self.click_signup()
|
||||
return self
|
|
@ -2,6 +2,7 @@ from Pom.Base import *
|
|||
|
||||
class PageHome(PageBase):
|
||||
btn_signin = [By.LINK_TEXT, '登录']
|
||||
btn_signup = [By.LINK_TEXT, '注册']
|
||||
|
||||
def open(self):
|
||||
self.home()
|
||||
|
@ -9,3 +10,6 @@ class PageHome(PageBase):
|
|||
|
||||
def click_signin(self):
|
||||
return self.driver.click(self.driver.find_element_by(self.btn_signin))
|
||||
|
||||
def click_signup(self):
|
||||
return self.driver.click(self.driver.find_element_by(self.btn_signup))
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
from Lib.TestcaseBasicLibrary import *
|
||||
from Pom.Home.Signin import *
|
||||
|
||||
|
||||
class TestLogger:
|
||||
def test_logger(self):
|
||||
log.i('Logging some information.')
|
|
@ -1,20 +1,24 @@
|
|||
import allure
|
||||
|
||||
from Lib.TestcaseBasicLibrary import *
|
||||
from Pom.Home.Signin import *
|
||||
|
||||
|
||||
@allure.epic('阿凡の博客 · 登录模块')
|
||||
@allure.feature('测试登录站点')
|
||||
class TestSignin:
|
||||
def setup_class(self):
|
||||
self.page = PageSignin(WebDriver()).open()
|
||||
with allure.step('启动页面'):
|
||||
self.page = PageSignin(WebDriver()).open()
|
||||
|
||||
def teardown_class(self):
|
||||
self.page.exit()
|
||||
with allure.step('退出页面'):
|
||||
self.page.exit()
|
||||
|
||||
@allure.severity('SMOKE')
|
||||
@allure.issue('https://demo16.zentao.net/bug-view-571.html', 'BUG #571 我是一个bug - UBTY - 禅道')
|
||||
@allure.testcase('https://demo16.zentao.net/testcase-view-943-1.html', 'CASE #943 把大象装进冰箱 - UBTY - 禅道')
|
||||
@allure.story('异常登录')
|
||||
@allure.title('测试异常登录')
|
||||
@allure.description('......')
|
||||
@allure.description('这是一段用例描述~')
|
||||
@pytest.mark.parametrize(('username', 'password'), [['super', 'super'], ['guest', 'guest'], ['users', 'users']])
|
||||
def test_errors_signin(self, username, password):
|
||||
with allure.step('刷新页面'):
|
||||
|
@ -28,9 +32,10 @@ class TestSignin:
|
|||
self.page.click_submit()
|
||||
allure.attach(self.page.driver.screenshot(), '网页截图', allure.attachment_type.PNG)
|
||||
|
||||
@allure.severity(allure.severity_level.BLOCKER)
|
||||
@allure.story('正常登录')
|
||||
@allure.title('测试正常登录')
|
||||
@allure.description('......')
|
||||
@allure.description('这是一段用例描述~')
|
||||
@pytest.mark.parametrize(('username', 'password'), [['admin', 'admin']])
|
||||
def test_normal_signin(self, username, password):
|
||||
with allure.step('刷新页面'):
|
||||
|
@ -43,3 +48,13 @@ class TestSignin:
|
|||
with allure.step('点击登录'):
|
||||
self.page.click_submit()
|
||||
allure.attach(self.page.driver.screenshot(), '网页截图', allure.attachment_type.PNG)
|
||||
|
||||
@allure.severity('P3')
|
||||
def test_failed(self):
|
||||
with allure.step('开始断言'):
|
||||
assert 1 < 0, 'Assert failed.'
|
||||
|
||||
@allure.severity('p3')
|
||||
def test_errors(self):
|
||||
with allure.step('抛出异常'):
|
||||
raise Exception('This is a exception info.')
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from Lib.TestcaseBasicLibrary import *
|
||||
from Pom.Home.Signup import *
|
||||
|
||||
|
||||
@allure.epic('阿凡の博客 · 注册模块')
|
||||
@allure.feature('测试注册站点')
|
||||
class TestSignin:
|
||||
def setup_class(self):
|
||||
self.page = PageSignup(WebDriver()).open()
|
||||
|
||||
def teardown_class(self):
|
||||
self.page.exit()
|
||||
|
||||
@allure.story('异常注册')
|
||||
@allure.title('测试异常注册')
|
||||
@allure.description('......')
|
||||
@pytest.mark.parametrize(('username', 'password'), [['super', 'super'], ['guest', 'guest'], ['users', 'users']])
|
||||
def test_errors_signin(self, username, password):
|
||||
pass
|
||||
|
||||
@allure.story('正常注册')
|
||||
@allure.title('测试正常注册')
|
||||
@allure.description('......')
|
||||
@pytest.mark.parametrize(('username', 'password'), [['admin', 'admin']])
|
||||
def test_normal_signin(self, username, password):
|
||||
pass
|
|
@ -1,6 +1,6 @@
|
|||
[pytest]
|
||||
testpaths = Testcase
|
||||
addopts = -vs --strict-markers --reruns=1 --reruns-delay=3
|
||||
addopts = -vs --strict-markers --reruns=0 --reruns-delay=3
|
||||
log_cli = 1
|
||||
pythonpath = ./
|
||||
cache_dir = pytest_cache
|
||||
|
@ -10,3 +10,6 @@ markers =
|
|||
p1: P1 level testcase
|
||||
p2: P2 level testcase
|
||||
p3: P3 level testcase
|
||||
log_level = INFO
|
||||
log_format = %(asctime)s %(levelname)s: %(message)s
|
||||
log_date_format = %Y-%m-%d %H:%M:%S
|
||||
|
|
Loading…
Reference in New Issue