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