ImportUnitTestImportWebdriverImport TimeclassTest (unittest. TestCase): @classmethoddefSetupClass (self): Cap={} cap['PlatformName'] ='Android'cap['platformversion'] ='4.4.2'cap['devicename'] ='7n2sse158p001892'cap['NoReset'] ='NoReset'cap['Apppackage'] ='Com.gomo.calculator'cap['appactivity'] ='. Ui.activity.MainActivity'Self.driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', CAP) @classmethoddefTeardownclass (self): Self.driver.quit ()defTest_add (self): Time.sleep (2) self.driver.find_element_by_id ('com.gomo.calculator:id/input_num_1'). Click () self.driver.find_element_by_id ('Com.gomo.calculator:id/display_op_add'). Click () self.driver.find_element_by_id ('com.gomo.calculator:id/input_num_2'). Click () self.driver.find_element_by_id ('com.gomo.calculator:id/display_eq'). Click ()Print("test_add Success!!!") defTest_mul (self): Time.sleep (2) self.driver.find_element_by_id ('Com.gomo.calculator:id/input_num_3'). Click () self.driver.find_element_by_id ('Com.gomo.calculator:id/op_mul'). Click () self.driver.find_element_by_id ('Com.gomo.calculator:id/input_num_4'). Click () self.driver.find_element_by_id ('com.gomo.calculator:id/display_eq'). Click ()Print("Test_mul Success!!!") if __name__=="__main__": #Import sys;sys.argv = [' ', ' test.testname ']Unittest.main ()
Java Edition: Write app Automation test cases in Java and JUnit
Writing app automation test cases with Python and unittest