Recently has been busy, finally have the time to tidy up, pass a simple use case, after running can see the use case report, hope to everyone helpful.
Htmltestrunner This package has a lot of online, you can download it yourself.
1 ImportUnitTest2 fromAppiumImportWebdriver3 fromTimeImportSleep4 ImportOS5 ImportTempfile6 fromPILImportImage7 ImportHtmltestrunner8 Import Time9 Ten classlittertestscase (unittest. TestCase): One defsetUp (self): Adesired_cups={} -desired_cups['PlatformName']='Android' -desired_cups['platformversion']='4.4.2' thedesired_cups['devicename']='du2sse15a9032675' -desired_cups['Apppackage']='COM.CLEANMASTER.MGUARD_CN' -desired_cups['appactivity']='com.keniu.security.main.MainActivity' -Self.dr=webdriver. Remote ('Http://localhost:4725/wd/hub', desired_cups) +Sleep (20) - #self.dr.find_element_by_id (' Com.cleanmaster.mguard_cn:id/im '). Click () + #Sleep (5) A defTearDown (self): at self.dr.quit () - #Garbage Cleanup - defClean_litter (self): -CL=SELF.DR.FIND_ELEMENT_BY_ID ('COM.CLEANMASTER.MGUARD_CN:ID/BIW') - Self.assertisnotnone (CL) - Cl.click () inSleep (15) - #If you need to clean up the direct cleanup, do not need to click back---garbage cleanup to Try: +SELF.DR.FIND_ELEMENT_BY_ID ('Com.cleanmaster.mguard_cn:id/af6'). Click () - exceptException as E: the Print(Exception,":"E'Trash Cleanup button') *Self.dr.find_element_name ('Master's Purse'). Click () $ Else:Panax NotoginsengSleep (15) -Self.dr.find_element_by_name ('Master's Purse'). Click () the if __name__=='__main__': +Suite =UnitTest. TestSuite () ASuite.addtest (Littertestscase ('Clean_litter')) the #UnitTest. Texttestrunner (verbosity=2). Run (Suite) -
Filename='c:\\test-zq\\report\\report.html' $Fp=open (filename,'WB') $Runner=Htmltestrunner.htmltestrunner ( -stream=FP, -Title=u'result', theDescription=u' Report' - )Wuyi Runner.run (Suite) theFp.close ()
A simple and complete use case for Appium+python