【问题标题】:How to create HTML reporting in Python unit test?如何在 Python 单元测试中创建 HTML 报告?
【发布时间】:2019-11-21 00:15:39
【问题描述】:

我正在使用 Appium 和 Python 自动化移动应用程序。我需要获取测试结果的 HTML 报告。 我需要将测试结果保存在 Html 文件中,以便人类可读的结果呈现。我尝试了几种方法,但没有任何效果。

有人知道怎么做吗?提前致谢。

import os, sys
import glob
import unittest
from appium import webdriver
from time import sleep

PLATFORM_VERSION = '5.1.1'


class EntranceTests(unittest.TestCase):

def setUp(self):
    print 'commandline args',sys.argv[1]
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '5.1.1'
    desired_caps['deviceName'] = 'CooTel S32'   
    desired_caps['udid'] = sys.argv[1] 
    desired_caps['appPackage'] = 'com.android.systemui'
    desired_caps['appActivity'] = ' '
    url = "http://localhost:{}/wd/hub".format(sys.argv[2])
    self.driver = webdriver.Remote(url, desired_caps)


def data_connection(self):
    self.driver.orientation = "PORTRAIT"
    self.driver.swipe(340, 1, 340, 800, 2000)

    notification = self.driver.find_element_by_id('com.android.systemui:id/header')
    notification.click()

    try:
            wifi = self.driver.find_element_by_xpath('//*[contains(@class,"android.widget.TextView") and contains(@text, "WLAN")]')
            wifi.is_displayed()
            print 'Wifi is switched off'

            mobiledata = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Mobile data")]')
            mobiledata.click()
            print 'SUCCESS! Switch on Mobile data'
            sleep(5)

    except:
            print 'Wifi is switched on'

            wifi_off = self.driver.find_element_by_xpath('//*[contains(@class,"android.widget.ImageView") and contains(@index, "0")]')
            wifi_off.click()
            print 'SUCCESS! Switch off Wifi'

            mobiledata = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Mobile data")]')
            mobiledata.click()
            print 'SUCCESS! Switch on Mobile data'
            sleep(5)


def testcase_dataAndWifi(self):
    self.data_connection()


def tearDown(self):
    self.driver.quit()


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(EntranceTests)
result = str(unittest.TextTestRunner(verbosity=2).run(suite))

【问题讨论】:

标签: python html appium python-unittest


【解决方案1】:

您可以使用nose-html-reporting 模块(pip install nose-html-reporting) 在使用python unittest 框架时生成HTML 报告。

请参考以下链接了解更多信息: https://pypi.org/project/nose-html-reporting/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    相关资源
    最近更新 更多