About the automated test framework PO, see the blog I wrote earlier: http://www.cnblogs.com/hanxiaobei/p/6755329.html
This article is mainly about Appium automated test how to have PO design ideas to achieve.
The directory structure of the PO model:
Where main.py is the main portal of the framework, test_creat.py calls creat_page.py,creat_page.py call base_page.py.
PO code example:
main.py
1 Import UnitTest2 Import Htmltestrunner3 4 #相对路径5Testcase_path =". \\testcase"6Report_path =". \\report\\appium_report.html"7 def creat_suite ():8Uit =UnitTest. TestSuite ()9Discover = Unittest.defaultTestLoader.discover (testcase_path,pattern="test_*.py")Ten forTest_suiteinchDiscover: One # Print (test_suite) A forTest_caseinchTest_suite: - uit.addtest (test_case) - returnuit the -Suite =Creat_suite () -fp = open (Report_path,"WB") -Runner = Htmltestrunner.htmltestrunner (stream=fp,title="Test Results", description="appium New Note test results") + Runner.run (Suite) -Fp.close ()
test_creat.py
1 fromappium Import Webdriver2 Import UnitTest3 fromAppiumframework. Po.creat_page Import Creatpage4 Import Time5 6 classTest (unittest. TestCase):7 """Automation"""8 def setUp (self):9Desired_caps = {Ten 'PlatformName':'Android', One 'devicename':'Android Emulator', #可有可无 A 'platformversion':'5.0', - # APK Package name - 'Apppackage':'com.smartisan.notes', the # apk for launcheractivity - 'appactivity':'com.smartisan.notes.NewNotesActivity', - #如果存在activity之间的切换可以用这个 -#'appwaitactivity':'. Mainactivity', + 'Unicodekeyboard': True, - #隐藏手机中的软键盘 + 'Resetkeyboard': True A } atSelf.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! " - - def tearDown (self): -Time.sleep (Ten) in self.driver.quit () - to def test_saveedittext (self): + """Save the edited text""" -SP =creatpage (self.driver) the Sp.add_button_link () *Sp.run_case ("Today is a good day to study at home! ") $ #断言: Actual result, expected result, error messagePanax NotoginsengSelf.assertequal (Sp.get_finish_button_text (), self.verificationerrors,msg="validation failed! ")
creat_page.py
1 fromAppiumframework. PO Import Base_page2 Import Time3 4 classCreatpage (base_page. Action):5Add_button_loc = ("Com.smartisan.notes:id/add_button")6Edittext_loc = ("Com.smartisan.notes:id/list_rtf_view")7Finish_button_loc = ("Com.smartisan.notes:id/send_finish_button")8 9 def add_button_link (self):Ten self.find_element (Self.add_button_loc). Click () OneTime.sleep (3) #等待3秒, waiting for the login pop-up window to finish loading A - def run_case (self,value): - self.find_element (Self.edittext_loc). Send_keys (value) theTime.sleep (5) - self.find_element (Self.finish_button_loc). Click () -Time.sleep (2) - + def get_finish_button_text (self): - returnSelf.find_element (self.edittext_loc). Text
base_page.py
1 classAction (Object):2 #初始化3 def __init__ (self,se_driver):4Self.driver =Se_driver5 6 #重写元素定位的方法7 def find_element (self,loc):8 Try:9 returnself.driver.find_element_by_id (Loc)TenExcept Exception ase: OnePrint"%s not found"% (Self,loc))
Test report:
Appium-based Python app automation testing framework-PO