mirror of
https://github.com/appium/appium.git
synced 2026-05-05 01:39:51 -05:00
Merge pull request #2802 from imurchie/isaac-pythonsamples
Update Python samples
This commit is contained in:
@@ -37,7 +37,7 @@ class ComplexAndroidTests(unittest.TestCase):
|
||||
el = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Animat")]')
|
||||
self.assertEqual('Animation', el.text)
|
||||
|
||||
el = self.driver.find_element_by_name("App")
|
||||
el = self.driver.find_element_by_accessibility_id("App")
|
||||
el.click()
|
||||
|
||||
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
|
||||
@@ -55,25 +55,25 @@ class ComplexAndroidTests(unittest.TestCase):
|
||||
els = self.driver.find_elements_by_xpath('//android.widget.TextView')
|
||||
self.driver.scroll(els[7], els[3])
|
||||
|
||||
el = self.driver.find_element_by_name('Views')
|
||||
el = self.driver.find_element_by_accessibility_id('Views')
|
||||
|
||||
def test_smiley_face(self):
|
||||
# just for the fun of it.
|
||||
# this doesn't really assert anything.
|
||||
self.driver.find_element_by_name('Graphics').click()
|
||||
self.driver.find_element_by_accessibility_id('Graphics').click()
|
||||
|
||||
els = self.driver.find_elements_by_class_name('android.widget.TextView')
|
||||
self.driver.scroll(els[len(els)-1], els[0])
|
||||
|
||||
el = None
|
||||
try:
|
||||
el = self.driver.find_element_by_name('Touch Paint')
|
||||
el = self.driver.find_element_by_accessibility_id('Touch Paint')
|
||||
except Exception as e:
|
||||
els = self.driver.find_elements_by_class_name('android.widget.TextView')
|
||||
self.driver.scroll(els[len(els)-1], els[0])
|
||||
|
||||
if el is None:
|
||||
el = self.driver.find_element_by_name('Touch Paint')
|
||||
el = self.driver.find_element_by_accessibility_id('Touch Paint')
|
||||
|
||||
el.click()
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class ContactsAndroidTests(unittest.TestCase):
|
||||
self.driver.quit()
|
||||
|
||||
def test_add_contacts(self):
|
||||
el = self.driver.find_element_by_name("Add Contact")
|
||||
el = self.driver.find_element_by_accessibility_id("Add Contact")
|
||||
el.click()
|
||||
|
||||
textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
|
||||
@@ -36,7 +36,7 @@ class ContactsAndroidTests(unittest.TestCase):
|
||||
self.assertEqual('Appium User', textfields[0].text)
|
||||
self.assertEqual('someone@appium.io', textfields[2].text)
|
||||
|
||||
self.driver.find_element_by_name("Save").click()
|
||||
self.driver.find_element_by_accessibility_id("Save").click()
|
||||
|
||||
# for some reason "save" breaks things
|
||||
alert = self.driver.switch_to_alert()
|
||||
|
||||
@@ -47,13 +47,13 @@ class SimpleAndroidSauceTests(unittest.TestCase):
|
||||
return result.status == 200
|
||||
|
||||
def test_create_note(self):
|
||||
el = self.driver.find_element_by_name("New note")
|
||||
el = self.driver.find_element_by_accessibility_id("New note")
|
||||
el.click()
|
||||
|
||||
el = self.driver.find_element_by_class_name("android.widget.EditText")
|
||||
el.send_keys("This is a new note!")
|
||||
|
||||
el = self.driver.find_element_by_name("Save")
|
||||
el = self.driver.find_element_by_accessibility_id("Save")
|
||||
el.click()
|
||||
|
||||
els = self.driver.find_elements_by_class_name("android.widget.TextView")
|
||||
|
||||
@@ -34,15 +34,13 @@ class SimpleAndroidTests(unittest.TestCase):
|
||||
|
||||
self.driver.back()
|
||||
|
||||
el = self.driver.find_element_by_name("App")
|
||||
el = self.driver.find_element_by_accessibility_id("App")
|
||||
self.assertIsNotNone(el)
|
||||
|
||||
els = self.driver.find_elements_by_android_uiautomator("new UiSelector().clickable(true)")
|
||||
self.assertEqual(12, len(els))
|
||||
self.assertGreaterEqual(12, len(els))
|
||||
|
||||
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().enabled(true)')
|
||||
self.assertEqual(20, len(els))
|
||||
self.assertEqual("API Demos", els[7].text)
|
||||
self.driver.find_element_by_android_uiautomator('text("API Demos")')
|
||||
|
||||
|
||||
def test_simple_actions(self):
|
||||
@@ -52,8 +50,7 @@ class SimpleAndroidTests(unittest.TestCase):
|
||||
el = self.driver.find_element_by_accessibility_id('Arcs')
|
||||
el.click()
|
||||
|
||||
main = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(false)')[7]
|
||||
self.assertEqual("Graphics/Arcs", main.text)
|
||||
self.driver.find_element_by_android_uiautomator('new UiSelector().text("Graphics/Arcs")')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -5,8 +5,10 @@ from time import sleep
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
PLATFORM_VERSION = '4.4'
|
||||
|
||||
class TestAndroidWebView(unittest.TestCase):
|
||||
|
||||
class AndroidWebViewTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
app = os.path.abspath(
|
||||
@@ -17,18 +19,24 @@ class TestAndroidWebView(unittest.TestCase):
|
||||
'appPackage': 'io.selendroid.testapp',
|
||||
'appActivity': '.HomeScreenActivity',
|
||||
'platformName': 'Android',
|
||||
'platformVersion': '4.4',
|
||||
'platformVersion': PLATFORM_VERSION,
|
||||
'deviceName': 'Android Emulator'
|
||||
}
|
||||
|
||||
if (PLATFORM_VERSION != '4.4'):
|
||||
desired_caps['automationName'] = 'selendroid'
|
||||
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
|
||||
desired_caps)
|
||||
|
||||
def test(self):
|
||||
button = self.driver.find_element_by_name('buttonStartWebviewCD')
|
||||
def test_webview(self):
|
||||
if (PLATFORM_VERSION == '4.4'):
|
||||
button = self.driver.find_element_by_accessibility_id('buttonStartWebviewCD')
|
||||
else:
|
||||
button = self.driver.find_element_by_name('buttonStartWebviewCD')
|
||||
button.click()
|
||||
|
||||
self.driver.switch_to.context('WEBVIEW')
|
||||
self.driver.switch_to.context('WEBVIEW_0')
|
||||
|
||||
input_field = self.driver.find_element_by_id('name_input')
|
||||
sleep(1)
|
||||
@@ -46,4 +54,5 @@ class TestAndroidWebView(unittest.TestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(AndroidWebViewTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
@@ -31,7 +31,7 @@ class ComplexIOSTests(unittest.TestCase):
|
||||
desired_capabilities={
|
||||
'app': app,
|
||||
'platformName': 'iOS',
|
||||
'platformVersion': '7.0',
|
||||
'platformVersion': '7.1',
|
||||
'deviceName': 'iPhone Simulator'
|
||||
})
|
||||
self._values = []
|
||||
@@ -122,7 +122,7 @@ class ComplexIOSTests(unittest.TestCase):
|
||||
def test_alert_interaction(self):
|
||||
# go to the alerts section
|
||||
self.driver.find_element_by_name('Alert Views, AAPLAlertViewController').click()
|
||||
triggerOk = self.driver.find_element_by_name("Simple")
|
||||
triggerOk = self.driver.find_element_by_accessibility_id("Simple")
|
||||
|
||||
# TOFIX: Looks like alert object is not proper state
|
||||
# something to do with UIActionSheet vs. UIAlertView?
|
||||
@@ -134,7 +134,7 @@ class ComplexIOSTests(unittest.TestCase):
|
||||
alert.accept()
|
||||
|
||||
# trigger modal alert with cancel & ok buttons
|
||||
triggerOkCancel = self.driver.find_element_by_name("Okay / Cancel")
|
||||
triggerOkCancel = self.driver.find_element_by_accessibility_id("Okay / Cancel")
|
||||
triggerOkCancel.click()
|
||||
alert = self.driver.switch_to_alert()
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class WebViewIOSSauceTests(unittest.TestCase):
|
||||
url_el = self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATextField[1]')
|
||||
url_el.send_keys('http://www.google.com')
|
||||
|
||||
go_el = self.driver.find_element_by_name('Go')
|
||||
go_el = self.driver.find_element_by_accessibility_id('Go')
|
||||
go_el.click()
|
||||
|
||||
self.driver.switch_to.context('WEBVIEW')
|
||||
|
||||
@@ -20,7 +20,7 @@ class SimpleIOSTests(unittest.TestCase):
|
||||
desired_capabilities={
|
||||
'app': app,
|
||||
'platformName': 'iOS',
|
||||
'platformVersion': '7.0',
|
||||
'platformVersion': '7.1',
|
||||
'deviceName': 'iPhone Simulator'
|
||||
})
|
||||
|
||||
@@ -54,7 +54,7 @@ class SimpleIOSTests(unittest.TestCase):
|
||||
els[5].click()
|
||||
|
||||
sleep(1)
|
||||
el = self.driver.find_element_by_name('OK')
|
||||
el = self.driver.find_element_by_accessibility_id('OK')
|
||||
el.click()
|
||||
|
||||
sleep(1)
|
||||
|
||||
@@ -23,7 +23,7 @@ class WebViewIOSTests(unittest.TestCase):
|
||||
'app': app,
|
||||
'deviceName': 'iPhone Simulator',
|
||||
'platformName': 'iOS',
|
||||
'platformVersion': '7.0'
|
||||
'platformVersion': '7.1'
|
||||
})
|
||||
|
||||
def tearDown(self):
|
||||
@@ -33,8 +33,9 @@ class WebViewIOSTests(unittest.TestCase):
|
||||
url_el = self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATextField[1]')
|
||||
url_el.send_keys('http://www.google.com')
|
||||
|
||||
go_el = self.driver.find_element_by_name('Go')
|
||||
go_el = self.driver.find_element_by_accessibility_id('Go')
|
||||
go_el.click()
|
||||
sleep(1)
|
||||
|
||||
self.driver.switch_to.context('WEBVIEW')
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SimpleSalendroidTests(unittest.TestCase):
|
||||
|
||||
el = self.driver.find_element_by_class_name("android.widget.TextView")
|
||||
# assert el.text == "Accessibility"
|
||||
self.assertEqual('API Demos', el.text)
|
||||
self.assertEqual('Accessibility', el.text)
|
||||
|
||||
el = self.driver.find_element_by_name("App")
|
||||
el.click()
|
||||
@@ -44,8 +44,9 @@ class SimpleSalendroidTests(unittest.TestCase):
|
||||
|
||||
els = self.driver.find_elements_by_class_name("android.widget.TextView")
|
||||
# Selendroid gets all the elements, not just the visible ones
|
||||
self.assertEqual(34, len(els))
|
||||
self.assertEqual('Action Bar', els[2].text)
|
||||
self.assertLessEqual(30, len(els))
|
||||
|
||||
self.driver.find_element_by_name('Action Bar')
|
||||
|
||||
self.driver.back()
|
||||
sleep(THINK_TIME)
|
||||
|
||||
Reference in New Issue
Block a user