mirror of
https://github.com/appium/appium.git
synced 2026-04-29 23:09:31 -05:00
Update python samples to 1.0
This commit is contained in:
@@ -1,28 +1,53 @@
|
||||
import os
|
||||
from selenium import webdriver
|
||||
import unittest
|
||||
from appium import webdriver
|
||||
from time import sleep
|
||||
|
||||
# Returns abs path relative to this file and not cwd
|
||||
PATH = lambda p: os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), p)
|
||||
)
|
||||
|
||||
desired_caps = {}
|
||||
desired_caps['device'] = 'Android'
|
||||
desired_caps['browserName'] = ''
|
||||
desired_caps['version'] = '4.2'
|
||||
desired_caps['app'] = PATH('../../../sample-code/apps/ContactManager/ContactManager.apk')
|
||||
desired_caps['app-package'] = 'com.example.android.contactmanager'
|
||||
desired_caps['app-activity'] = '.ContactManager'
|
||||
class ContactsAndroidTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
desired_caps = {}
|
||||
desired_caps['platformName'] = 'Android'
|
||||
desired_caps['platformVersion'] = '4.2'
|
||||
desired_caps['deviceName'] = 'Android Emulator'
|
||||
desired_caps['app'] = PATH(
|
||||
'../../../sample-code/apps/ContactManager/ContactManager.apk'
|
||||
)
|
||||
desired_caps['appPackage'] = 'com.example.android.contactmanager'
|
||||
desired_caps['appActivity'] = '.ContactManager'
|
||||
|
||||
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
el = driver.find_element_by_name("Add Contact")
|
||||
el.click()
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
textfields = driver.find_elements_by_tag_name("textfield")
|
||||
textfields[0].send_keys("My Name")
|
||||
textfields[2].send_keys("someone@somewhere.com")
|
||||
def test_add_contacts(self):
|
||||
el = self.driver.find_element_by_name("Add Contact")
|
||||
el.click()
|
||||
|
||||
driver.find_element_by_name("Save").click()
|
||||
textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
|
||||
textfields[0].send_keys("Appium User")
|
||||
textfields[2].send_keys("someone@appium.io")
|
||||
|
||||
driver.quit()
|
||||
self.assertEqual('Appium User', textfields[0].text)
|
||||
self.assertEqual('someone@appium.io', textfields[2].text)
|
||||
|
||||
self.driver.find_element_by_name("Save").click()
|
||||
|
||||
# for some reason "save" breaks things
|
||||
alert = self.driver.switch_to_alert()
|
||||
|
||||
# no way to handle alerts in Android
|
||||
self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click()
|
||||
|
||||
self.driver.keyevent(3)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
Reference in New Issue
Block a user