提交 c5d57100 编写于 作者: yuan.luo's avatar yuan.luo

add case

上级 23c8b96b
...@@ -2,7 +2,7 @@ import time ...@@ -2,7 +2,7 @@ import time
from unittest import TestCase from unittest import TestCase
from appium import webdriver from appium import webdriver
from util import config from util import config
from util.tools import set_file_path from util import tools
class Login(TestCase): class Login(TestCase):
...@@ -13,7 +13,41 @@ class Login(TestCase): ...@@ -13,7 +13,41 @@ class Login(TestCase):
def tearDown(self): def tearDown(self):
pass pass
def test_login(self): def test_login_code(self):
time.sleep(1)
try:
self.driver.find_element_by_id("tv_exist_account").click()
time.sleep(2)
self.driver.find_element_by_id("ll_login_bycode").click()
time.sleep(1)
self.driver.find_element_by_id("ed_phone").send_keys("15606680071")
self.driver.find_element_by_id("ed_code").send_keys("089898")
self.driver.find_element_by_id("btn_user_login").click()
except Exception as e:
filename = tools.get_screenshot_dir("test_login_code")
self.driver.save_screenshot(filename)
print(e)
tools.save_log(e)
def test_login_pwd(self):
time.sleep(1)
try:
self.driver.find_element_by_id("tv_exist_account").click()
time.sleep(2)
self.driver.find_element_by_id("ll_login_bypwd").click()
time.sleep(1)
self.driver.find_element_by_id("ed_phone").send_keys("15606680071")
self.driver.find_element_by_id("ed_pwd").send_keys("15606680072")
self.driver.find_element_by_id("btn_user_login").click()
except Exception as e:
filename = tools.get_screenshot_dir("test_login_pwd")
self.driver.save_screenshot(filename)
print(e)
tools.save_log(e)
def test_login_wechat(self):
time.sleep(2) time.sleep(2)
try: try:
...@@ -26,7 +60,7 @@ class Login(TestCase): ...@@ -26,7 +60,7 @@ class Login(TestCase):
time.sleep(1) time.sleep(1)
self.driver.find_element_by_id("btn_user_login").click() self.driver.find_element_by_id("btn_user_login").click()
filename = set_file_path('images/') + 'Login.png' filename = tools.set_file_path('images/') + 'Login.png'
self.driver.save_screenshot(filename) self.driver.save_screenshot(filename)
except Exception as e: except Exception as e:
print(e) print(e)
\ No newline at end of file
import time
from unittest import TestCase
from appium import webdriver
from util import config
from util import tools
class Register(TestCase):
def setUp(self):
self.driver = webdriver.Remote(config.host, config.get_caps())
def tearDown(self):
pass
def test_register(self):
time.sleep(2)
try:
self.driver.find_element_by_id("bt_next").click()
time.sleep(2)
self.driver.find_element_by_id("ed_phone").send_keys("15606680071")
# Tools.get_validate_code(self)
self.driver.find_element_by_id("ed_code").send_keys("245456")
self.driver.find_element_by_id("ed_pwd").send_keys("123456a")
time.sleep(1)
self.driver.find_element_by_id("btn_user_login").click()
except Exception as e:
filename = tools.get_screenshot_dir("test_login_code")
self.driver.save_screenshot(filename)
print(e)
tools.save_log(e)
...@@ -2,12 +2,16 @@ import unittest ...@@ -2,12 +2,16 @@ import unittest
import time import time
import HTMLTestRunner import HTMLTestRunner
from functions.login import Login from functions.login import Login
from util.tools import set_file_path from functions.register import Register
from util import tools
if __name__ == '__main__': if __name__ == '__main__':
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(Login("test_login")) suite.addTest(Login("test_login_code"))
filename = set_file_path('reports/') + time.strftime("%Y_%m_%d_%H_%M_%S", time.gmtime()) + '_result.html' suite.addTest(Login("test_login_pwd"))
suite.addTest(Register("test_register"))
filename = tools.get_report_dir() + time.strftime("%Y_%m_%d_%H_%M_%S", time.gmtime()) + '_result.html'
fp = open(filename, 'wb') fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='测试报告', description='用例执行情况:') runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='测试报告', description='用例执行情况:')
runner.run(suite) runner.run(suite)
......
CONFIG = { CONFIG = {
'PHONE_VERSION': '6.0.1', 'PHONE_VERSION': '6.0.1',
'HSOT': "http://localhost:4723/wd/hub" 'HOST': "http://localhost:4723/wd/hub"
} }
host = "http://localhost:4723/wd/hub"
def get_caps(version="8.0.0"): def get_caps(version="8.0.0"):
......
...@@ -18,6 +18,22 @@ def get_validate_code(self): ...@@ -18,6 +18,22 @@ def get_validate_code(self):
raise ValueError raise ValueError
return code return code
def save_log(log):
pass
# 保存截图地址
def get_screenshot_dir(name):
return set_file_path('images/') + name + '.png'
# 保存日志地址
def get_log_dir(name):
return set_file_path('logs/')
# 保存报告地址
def get_report_dir():
return set_file_path('reports/')
def get_project_path(): def get_project_path():
return os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir)) return os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir))
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册