Macaca testreporter

借鉴了 网上一些资料
https://www.cnblogs.com/findyou/p/6925733.html

HTMLTestRunner测试报告美化  HTMLTestRunnerCN

https://www.cnblogs.com/8013-cmf/p/6644366.html
以及雷子的一些资料

代码如下:实现了csdn的搜索功能,截图以及报告生成。

#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.csdn.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)





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值