Browse Source

init from phab

xielq 4 years ago
parent
commit
3629f744e0

+ 15 - 0
ReadMe.md

@@ -0,0 +1,15 @@
+轻量级自动化测试框架目录结构设计
+
+1.config层,放配置文件,把所有的项目相关的配置均放到这里,用Python支持较好的配置文件格式如ini或yaml等进行配置。实现配置与代码分离。
+
+2.data层,放数据文件,可以把所有的testcase的参数化相关的文件放到这里,一般可采用xlsx、csv、xml等格式。实现数据与代码分离。
+
+3.drivers层,放所需的驱动,如Chromedriver、IEDriverServer等。
+
+4.log层,所有生成的日志均存放在这里,可将日志分类,如运行时日志test log,错误日志error log等。
+
+5.report层,放程序运行生成的报告,一般可有html报告、excel报告等。
+
+6.src源码层,放所有程序代码。其中还需要进行更进一步的分层: 
+  test层,放所有测试相关的文件,如case——测试用例、common——项目相关的抽象通用代码、page——页面类(Page-Object思想)、suite——组织的测试套件。
+  utils层,所有的支撑代码都在这里,包括读取config的类、写log的类、读取excel、xml的类、生成报告的类(如HTMLTestRunner)、数据库连接、发送邮件等类和方法,都在这里。

+ 0 - 0
README.md → config/__init__.py


+ 0 - 0
data/__init__.py


+ 0 - 0
log/__init__.py


+ 0 - 0
report/__init__.py


+ 0 - 0
src/case/__init__.py


+ 0 - 0
src/common/__init__.py


+ 0 - 0
src/page/__init__.py


+ 0 - 0
src/suite/__init__.py


+ 2 - 0
src/testscript/HelloWorld.py

@@ -0,0 +1,2 @@
+if __name__ == '__main__':
+    print('Hello worldsss')

+ 43 - 0
src/testscript/Test_Login.py

@@ -0,0 +1,43 @@
+import time
+import unittest
+from time import sleep
+
+import selenium.webdriver
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.support.wait import WebDriverWait
+
+
+class testLogin(unittest.TestCase):
+    @classmethod
+    def setUpClass(cls):
+        cls.driver = selenium.webdriver.Chrome()
+        cls.driver.implicitly_wait(10)
+        cls.url = 'http://192.168.253.6:23400/'
+
+    @classmethod
+    def testLogin(self):
+
+        driver = self.driver
+        driver.get(self.url)
+        sleep(3)
+        driver.find_element_by_link_text(u'登录').click()
+        sleep(3)
+        driver.find_element_by_css_selector('[placeholder="手机号/邮箱"]').send_keys('18948739305')
+        driver.find_element_by_xpath('//input[@placeholder="密码"]').send_keys('qq123123')
+        driver.find_element_by_xpath('//*[@id="form-wrap"]/div[1]/form/div[6]/div/a').click()
+        sleep(3)
+        driver.find_element_by_xpath(
+            '//*[@id="__nuxt"]/div/div/div/div[1]/div[3]/div/div/div[2]/div/div[2]/ul/li[1]').click()
+        sleep(3)
+        login_name = driver.find_element_by_xpath('//*[@id="main"]/header/nav/div/div[2]/div/div[1]/span').text
+        self.assertEqual(login_name, '月牙科技有限公司2')
+
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.driver.quit()
+
+
+if __name__ == '__main__':
+    unittest.main

+ 0 - 0
src/testscript/__init__.py


+ 76 - 0
src/utils/Generate.py

@@ -0,0 +1,76 @@
+"""
+@auth: huyy
+@time: 2018/8/20 9:42
+"""
+import os
+import smtplib
+import time
+import unittest
+
+from HTMLTestRunner import HTMLTestRunner
+from email.header import Header
+from email.mime.text import MIMEText
+
+
+def send_emall(new_report):
+    f = open(new_report, 'rb')
+    mail_content = f.read()
+    f.close()
+
+    smtpserver = 'smtp.163.com'
+
+    user = 'hu_yy199426767@163.com'
+    password = 'qq123123'
+
+    sender = 'hu_yy199426767@163.com'
+    receiver = 'huyy@usoftchina.com'
+
+    subject = '测试'
+
+    msg = MIMEText(mail_content, 'html', 'utf-8')
+    msg['Subject'] = Header(subject, 'utf-8')
+    #对应的标题
+    msg['From'] = sender
+    msg['To'] = receiver
+
+    smtp = smtplib.SMTP_SSL(smtpserver, 465)
+    #使用smtplib连接邮件服务器
+    smtp.helo(smtpserver)
+    smtp.ehlo(smtpserver)
+    # 认证邮箱
+    smtp.login(user, password)
+    #登录
+    print("发送邮件中。。")
+
+    smtp.sendmail(sender, receiver, msg.as_string())
+    smtp.quit()
+    print("发送成功!")
+
+def new_report(report_dir):
+    lists = os.listdir(report_dir)
+
+    lists.sort(key=lambda fn: os.path.getatime(report_dir + '\\' + fn))
+    print(lists[-1])
+
+    file = os.path.join(report_dir, lists[-1])
+    print(file)
+    return file
+
+
+try:
+    test_dir = '../testscript'
+    case = unittest.defaultTestLoader.discover(test_dir, pattern='Test_*.py')
+except Exception as e:
+    print(e)
+
+if __name__ == '__main__':
+    report_dir = '../../report'
+    _time = time.strftime('%Y-%m-%d %H`%M`%S ')
+    report_name = report_dir + '/' + _time + '.html'
+    with open(report_name, 'wb')as rp:
+        runner = HTMLTestRunner(stream=rp, title='Mall Test', description='desc')
+        runner.run(case)
+    rp.close()
+
+    a = new_report(report_dir)
+    send_emall(a)

+ 0 - 0
src/utils/__init__.py