新手学Appium-Python unittest框架

发表于:2015-5-28 10:19

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Mr.Dantes    来源:51Testing软件测试网采编

  #废话不多说了,直接上代码~
importos
importunittest
fromappiumimportwebdriver
fromtimeimportsleep
#Returnsabspathrelativetothisfileandnotcwd
PATH=lambdap:os.path.abspath(
os.path.join(os.path.dirname(__file__),p)
)
classContactsAndroidTests(unittest.TestCase):
defsetUp(self):
desired_caps={}
desired_caps['platformName']='Android'
desired_caps['platformVersion']='4.3'
desired_caps['deviceName']='192.168.56.101:5555'
'''desired_caps['app']=PATH(
'../../../sample-code/apps/ContactManager/ContactManager.apk'
)'''
desired_caps['appPackage']='com.android.calculator2'
desired_caps['appActivity']='.Calculator'
self.driver=webdriver.Remote('http://192.168.10.95:4723/wd/hub',desired_caps)
deftearDown(self):
self.driver.close_app()
self.driver.quit()
deftest_add_contacts(self):
'''el=self.driver.find_element_by_name("AddContact")
el.click()
textfields=self.driver.find_elements_by_class_name("android.widget.EditText")
textfields[0].send_keys("AppiumUser")
textfields[2].send_keys("someone@appium.io")
self.assertEqual('AppiumUser',textfields[0].text)
self.assertEqual('someone@appium.io',textfields[2].text)
self.driver.find_element_by_name("Save").click()
#forsomereason"save"breaksthings
alert=self.driver.switch_to_alert()
#nowaytohandlealertsinAndroid
self.driver.find_element_by_android_uiautomator('newUiSelector().clickable(true)').click()
self.driver.keyevent(3)'''
self.driver.find_element_by_id('com.android.calculator2:id/digit9').click()
if__name__=='__main__':
suite=unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
  成功后的结果截图~,参照下图:
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号