Appium automated testing and generation of HTML test reports based on Python unittest

Source: Internet
Author: User
Tags appium

This paper completes Appium automated test based on Python unit test framework unittest, and generates a visual test report based on HTML.

code example:

1 #利用unittest并生成测试报告2 classappium_test (unittest. TestCase):3     """Appium Test Class"""4 def setUp (self):5Desired_caps = {6             'PlatformName':'Android',7             'devicename':'Android Emulator', #可有可无, here's my simulator.8             'platformversion':'5.0',9 # APK Package nameTen             'Apppackage':'com.smartisan.notes', One # apk for launcheractivity A             'appactivity':'com.smartisan.notes.NewNotesActivity', - #如果存在activity之间的切换可以用这个 -#'appwaitactivity':'. Mainactivity', the             'Unicodekeyboard': True, - #隐藏手机中的软键盘 -             'Resetkeyboard': True -             } +Self.driver = Webdriver. Remote ('Http://127.0.0.1:4723/wd/hub', Desired_caps) -Time.sleep (5) +Self.verificationerrors ="Today is a good day to study at home! "#设置的断言 A  at def tearDown (self): -Time.sleep (Ten) -Assertt = self.driver.find_element_by_id ("Com.smartisan.notes:id/list_rtf_view"). Text - # Print (ASSERTT) #调试用 -Self.assertequal (assertt,self.verificationerrors,msg="validation failed! ") - #断言: Actual result, expected result, error message in self.driver.quit () -  to def test_creat (self): +         """add a new record in Notepad""" -SELF.DRIVER.FIND_ELEMENT_BY_ID ("Com.smartisan.notes:id/add_button"). Click () theTime.sleep (3) *Self.driver.find_element_by_class_name ("Android.widget.EditText"). Send_keys ("Today is a good day to study at home! ") $SELF.DRIVER.FIND_ELEMENT_BY_ID ("Com.smartisan.notes:id/send_finish_button"). Click ()Panax Notoginseng  -Suite =UnitTest. TestSuite () theSuite.addtest (Appium_test ('test_creat')) +  AReport_file =". \\appium_report.html" thefp = open (Report_file,'WB') +Runner = Htmltestrunner.htmltestrunner (stream=fp,title="appium Test Report", description='Add a note and save') - Runner.run (Suite) $Fp.close ()

To generate a test report:

Appium automated testing and generation of HTML test reports based on Python unittest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.