Macaca testreporter
借鉴了 网上一些资料
https://www.cnblogs.com/findyou/p/6925733.html
HTMLTestRunner测试报告美化 HTMLTestRunnerCN
https://www.cnblogs.com/8013-cmf/p/6644366.html
以及雷子的一些资料
代码如下:实现了****的搜索功能,截图以及报告生成。
#coding:utf-8
import unittest
import time,os
import HTMLTestRunnerCN
from macaca import WebDriver
desired_caps = {
'platformName': 'desktop',
'browserName': 'electron'
# 'browserName': 'chrome'
}
server_url = {
'hostname': 'localhost',
'port': 3456
}
class MacacaTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = WebDriver(desired_caps, server_url)
cls.driver.init()
@classmethod
def tearDownClass(cls):
cls.driver.quit()
def test_get_url(self):
self.driver \
.set_window_size(1280, 800) \
.get('https://www.****.net/')
img_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + '//screenshots//'
time1 =time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
screen_save_path = img_folder + time1 + '.png'
# self.driver.get_screenshot_as_file(screen_save_path)
self.driver.save_screenshot(screen_save_path)
def test_search_macaca(self):
self.driver \
.element_by_id('toolber-keyword') \
.send_keys('macaca')
time.sleep(3)
#self.driver.element_by_xpath("//div[1]/div/div/ul/li[2]/div/a/svg").click()
self.driver.element_by_xpath("//div[1]/div/div/ul/li[2]/div/a").click()
time.sleep(3)
if __name__ == '__main__':
# unittest.main()
suite = unittest.TestSuite()
timeT =time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
#now = time.strftime('%Y-%m%d', time.localtime(time.time()))
report_dir = r'%s.html'% timeT
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(MacacaTest))
re_open = open(report_dir, 'wb')
runner = HTMLTestRunnerCN.HTMLTestRunner(stream=re_open, title='测试报告', description='测试结果')
https://www.cnblogs.com/findyou/p/6925733.html
HTMLTestRunner测试报告美化 HTMLTestRunnerCN
https://www.cnblogs.com/8013-cmf/p/6644366.html
以及雷子的一些资料
代码如下:实现了****的搜索功能,截图以及报告生成。
#coding:utf-8
import unittest
import time,os
import HTMLTestRunnerCN
from macaca import WebDriver
desired_caps = {
'platformName': 'desktop',
'browserName': 'electron'
# 'browserName': 'chrome'
}
server_url = {
'hostname': 'localhost',
'port': 3456
}
class MacacaTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = WebDriver(desired_caps, server_url)
cls.driver.init()
@classmethod
def tearDownClass(cls):
cls.driver.quit()
def test_get_url(self):
self.driver \
.set_window_size(1280, 800) \
.get('https://www.****.net/')
img_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + '//screenshots//'
time1 =time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
screen_save_path = img_folder + time1 + '.png'
# self.driver.get_screenshot_as_file(screen_save_path)
self.driver.save_screenshot(screen_save_path)
def test_search_macaca(self):
self.driver \
.element_by_id('toolber-keyword') \
.send_keys('macaca')
time.sleep(3)
#self.driver.element_by_xpath("//div[1]/div/div/ul/li[2]/div/a/svg").click()
self.driver.element_by_xpath("//div[1]/div/div/ul/li[2]/div/a").click()
time.sleep(3)
if __name__ == '__main__':
# unittest.main()
suite = unittest.TestSuite()
timeT =time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
#now = time.strftime('%Y-%m%d', time.localtime(time.time()))
report_dir = r'%s.html'% timeT
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(MacacaTest))
re_open = open(report_dir, 'wb')
runner = HTMLTestRunnerCN.HTMLTestRunner(stream=re_open, title='测试报告', description='测试结果')
runner.run(suite)