0

I'm automating mobile app with Appium and Python. I need to get a HTML report for the test results. What I need is to save test results in Html files, for human readable presentation of results. I have tried out a few ways, but nothing worked for me.

Anyone knows how to do it? Thanks in advance.

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))
1

1 Answer 1

1

You can use nose-html-reporting module(pip install nose-html-reporting) for generating HTML reports while using python unittest framework.

Please refer below link for more information: https://pypi.org/project/nose-html-reporting/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.