mirror of
https://github.com/appium/appium.git
synced 2026-04-24 20:38:43 -05:00
Update python samples to 1.0
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
from socketIO_client import SocketIO
|
||||
|
||||
"""
|
||||
Please note that you will need to install the socketIO-client python module.
|
||||
|
||||
This app will block on the wait() method until messages are recieved. It's
|
||||
advised to read the documentation for socketIO-client and listen for alerts
|
||||
in a seperate thread.
|
||||
|
||||
This should not be considered production quality.
|
||||
"""
|
||||
|
||||
|
||||
class Alerts(object):
|
||||
def __init__(self):
|
||||
self.socket = SocketIO('localhost', 4723)
|
||||
self.connect_events()
|
||||
self.socket.wait()
|
||||
|
||||
def connect_events(self):
|
||||
self.socket.on('connect', self.on_connect)
|
||||
self.socket.on('disconnect', self.on_disconnect)
|
||||
self.socket.on('alert', self.on_alert)
|
||||
self.socket.on('error', self.on_error)
|
||||
|
||||
def on_connect(self):
|
||||
print "[connected]"
|
||||
|
||||
def on_alert(self, *args):
|
||||
message = args[0]['message']
|
||||
print 'on_alert', str(message)
|
||||
|
||||
def on_disconnect(self):
|
||||
print "[disconnected]"
|
||||
|
||||
def on_error(self, name, message):
|
||||
print('Error: %s: %s' % (name, message))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
alerts = Alerts()
|
||||
@@ -1,28 +0,0 @@
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
from selenium import webdriver
|
||||
|
||||
# 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/ApiDemos/bin/ApiDemos-debug.apk'
|
||||
)
|
||||
desired_caps['app-package'] = 'com.example.android.apis'
|
||||
desired_caps['app-activity'] = '.ApiDemos'
|
||||
|
||||
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
print driver.get_window_size()
|
||||
elem = driver.find_element_by_name('Graphics')
|
||||
elem.click()
|
||||
elem = driver.find_element_by_name('Arcs')
|
||||
elem.click()
|
||||
driver.quit()
|
||||
@@ -1,37 +0,0 @@
|
||||
import os
|
||||
from selenium import webdriver
|
||||
|
||||
# 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.3'
|
||||
desired_caps['app'] = PATH('../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk')
|
||||
desired_caps['app-package'] = 'com.example.android.apis'
|
||||
desired_caps['app-activity'] = '.ApiDemos'
|
||||
|
||||
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
el = driver.find_element_by_xpath('//text[contains(@value, "Animat")]')
|
||||
assert el.text == "Animation"
|
||||
|
||||
el = driver.find_element_by_tag_name("text")
|
||||
assert el.text == "API Demos"
|
||||
|
||||
el = driver.find_element_by_name("App")
|
||||
el.click()
|
||||
|
||||
els = driver.find_elements_by_tag_name("text")
|
||||
assert els[2].text == "Activity"
|
||||
|
||||
driver.back()
|
||||
|
||||
el = driver.find_element_by_class_name("android.widget.ListView")
|
||||
js_params = {"element": el.id, "text": "Views"}
|
||||
driver.execute_script("mobile: scrollTo", js_params)
|
||||
|
||||
driver.quit()
|
||||
@@ -0,0 +1,159 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from appium import webdriver
|
||||
from appium.webdriver.common.touch_action import TouchAction
|
||||
from appium.webdriver.common.multi_action import MultiAction
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
class ComplexAndroidTests(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/ApiDemos/bin/ApiDemos-debug.apk'
|
||||
)
|
||||
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
def test_find_elements(self):
|
||||
# pause a moment, so xml generation can occur
|
||||
sleep(2)
|
||||
|
||||
els = self.driver.find_elements_by_xpath('//android.widget.TextView')
|
||||
self.assertEqual('API Demos', els[0].text)
|
||||
|
||||
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.click()
|
||||
|
||||
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
|
||||
# there are more, but at least 10 visible
|
||||
self.assertLess(10, len(els))
|
||||
# the list includes 2 before the main visible elements
|
||||
self.assertEqual('Action Bar', els[2].text)
|
||||
|
||||
els = self.driver.find_elements_by_xpath('//android.widget.TextView')
|
||||
self.assertLess(10, len(els))
|
||||
self.assertEqual('Action Bar', els[1].text)
|
||||
|
||||
def test_scroll(self):
|
||||
sleep(2)
|
||||
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')
|
||||
|
||||
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()
|
||||
|
||||
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')
|
||||
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.click()
|
||||
|
||||
# paint
|
||||
e1 = TouchAction()
|
||||
e1.press(x=150, y=100).release()
|
||||
|
||||
e2 = TouchAction()
|
||||
e2.press(x=250, y=100).release()
|
||||
|
||||
smile = TouchAction()
|
||||
smile.press(x=110, y=200) \
|
||||
.move_to(x=1, y=1) \
|
||||
.move_to(x=1, y=1) \
|
||||
.move_to(x=1, y=1) \
|
||||
.move_to(x=1, y=1) \
|
||||
.move_to(x=1, y=1) \
|
||||
.move_to(x=2, y=1) \
|
||||
.move_to(x=2, y=1) \
|
||||
.move_to(x=2, y=1) \
|
||||
.move_to(x=2, y=1) \
|
||||
.move_to(x=2, y=1) \
|
||||
.move_to(x=3, y=1) \
|
||||
.move_to(x=3, y=1) \
|
||||
.move_to(x=3, y=1) \
|
||||
.move_to(x=3, y=1) \
|
||||
.move_to(x=3, y=1) \
|
||||
.move_to(x=4, y=1) \
|
||||
.move_to(x=4, y=1) \
|
||||
.move_to(x=4, y=1) \
|
||||
.move_to(x=4, y=1) \
|
||||
.move_to(x=4, y=1) \
|
||||
.move_to(x=5, y=1) \
|
||||
.move_to(x=5, y=1) \
|
||||
.move_to(x=5, y=1) \
|
||||
.move_to(x=5, y=1) \
|
||||
.move_to(x=5, y=1) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=0) \
|
||||
.move_to(x=5, y=-1) \
|
||||
.move_to(x=5, y=-1) \
|
||||
.move_to(x=5, y=-1) \
|
||||
.move_to(x=5, y=-1) \
|
||||
.move_to(x=5, y=-1) \
|
||||
.move_to(x=4, y=-1) \
|
||||
.move_to(x=4, y=-1) \
|
||||
.move_to(x=4, y=-1) \
|
||||
.move_to(x=4, y=-1) \
|
||||
.move_to(x=4, y=-1) \
|
||||
.move_to(x=3, y=-1) \
|
||||
.move_to(x=3, y=-1) \
|
||||
.move_to(x=3, y=-1) \
|
||||
.move_to(x=3, y=-1) \
|
||||
.move_to(x=3, y=-1) \
|
||||
.move_to(x=2, y=-1) \
|
||||
.move_to(x=2, y=-1) \
|
||||
.move_to(x=2, y=-1) \
|
||||
.move_to(x=2, y=-1) \
|
||||
.move_to(x=2, y=-1) \
|
||||
.move_to(x=1, y=-1) \
|
||||
.move_to(x=1, y=-1) \
|
||||
.move_to(x=1, y=-1) \
|
||||
.move_to(x=1, y=-1) \
|
||||
.move_to(x=1, y=-1)
|
||||
smile.release()
|
||||
|
||||
ma = MultiAction(self.driver)
|
||||
ma.add(e1, e2, smile)
|
||||
ma.perform()
|
||||
|
||||
# so you can see it
|
||||
sleep(10)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ComplexAndroidTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
@@ -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)
|
||||
|
||||
@@ -1,31 +1,70 @@
|
||||
import os
|
||||
from selenium import webdriver
|
||||
import httplib
|
||||
import base64
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
desired_caps = {}
|
||||
desired_caps['device'] = 'Android'
|
||||
desired_caps['browserName'] = ''
|
||||
desired_caps['version'] = '4.2'
|
||||
desired_caps['app'] = 'http://appium.s3.amazonaws.com/NotesList.apk'
|
||||
desired_caps['app-package'] = 'com.example.android.notepad'
|
||||
desired_caps['app-activity'] = '.NotesList'
|
||||
import unittest
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
SAUCE_USERNAME = os.environ.get('SAUCE_USERNAME')
|
||||
SAUCE_ACCESS_KEY = os.environ.get('SAUCE_ACCESS_KEY')
|
||||
|
||||
driver = webdriver.Remote('http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY), desired_caps)
|
||||
class SimpleAndroidSauceTests(unittest.TestCase):
|
||||
|
||||
el = driver.find_element_by_name("New note")
|
||||
el.click()
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
app = "http://appium.s3.amazonaws.com/NotesList.apk"
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY),
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'platformVersion': '4.2',
|
||||
'app': app,
|
||||
'name': 'Appium Python Android Test',
|
||||
'appPackage': 'com.example.android.notepad',
|
||||
'appActivity': '.NotesList'
|
||||
})
|
||||
|
||||
el = driver.find_element_by_tag_name("textfield")
|
||||
el.send_keys("This is a new note!")
|
||||
def tearDown(self):
|
||||
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
|
||||
self.driver.quit()
|
||||
|
||||
el = driver.find_element_by_name("Save")
|
||||
el.click()
|
||||
def _set_test_status(self, jobid, passed=True):
|
||||
# Report the status of your test to Sauce
|
||||
body_content = json.dumps({"passed": passed})
|
||||
connection = httplib.HTTPConnection("saucelabs.com")
|
||||
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (SAUCE_USERNAME, jobid),
|
||||
body_content,
|
||||
headers={"Authorization": "Basic %s" % base64string})
|
||||
result = connection.getresponse()
|
||||
return result.status == 200
|
||||
|
||||
els = driver.find_elements_by_tag_name("text")
|
||||
assert els[2].text == "This is a new note!"
|
||||
def test_create_note(self):
|
||||
driver = webdriver.Remote('http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY), desired_caps)
|
||||
|
||||
els[2].click()
|
||||
el = driver.find_element_by_name("New note")
|
||||
el.click()
|
||||
|
||||
driver.quit()
|
||||
el = driver.find_element_by_tag_name("textfield")
|
||||
el.send_keys("This is a new note!")
|
||||
|
||||
el = driver.find_element_by_name("Save")
|
||||
el.click()
|
||||
|
||||
els = driver.find_elements_by_tag_name("text")
|
||||
assert els[2].text == "This is a new note!"
|
||||
|
||||
els[2].click()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not (SAUCE_USERNAME and SAUCE_ACCESS_KEY):
|
||||
print "Make sure you have SAUCE_USERNAME and SAUCE_ACCESS_KEY set as environment variables."
|
||||
else:
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
import unittest
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
# Returns abs path relative to this file and not cwd
|
||||
PATH = lambda p: os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), p)
|
||||
)
|
||||
|
||||
class SimpleAndroidTests(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/ApiDemos/bin/ApiDemos-debug.apk'
|
||||
)
|
||||
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
def tearDown(self):
|
||||
# end the session
|
||||
self.driver.quit()
|
||||
|
||||
def test_find_elements(self):
|
||||
el = self.driver.find_element_by_accessibility_id('Graphics')
|
||||
el.click()
|
||||
el = self.driver.find_element_by_accessibility_id('Arcs')
|
||||
self.assertIsNotNone(el)
|
||||
|
||||
self.driver.back()
|
||||
|
||||
el = self.driver.find_element_by_name("App")
|
||||
self.assertIsNotNone(el)
|
||||
|
||||
els = self.driver.find_elements_by_android_uiautomator("new UiSelector().clickable(true)")
|
||||
self.assertEqual(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)
|
||||
|
||||
|
||||
def test_simple_actions(self):
|
||||
el = self.driver.find_element_by_accessibility_id('Graphics')
|
||||
el.click()
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleAndroidTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
+13
-6
@@ -2,15 +2,16 @@ import os
|
||||
import glob
|
||||
import unittest
|
||||
from time import sleep
|
||||
from selenium import webdriver
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
class TestAndroidWebView(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
app = os.path.abspath(
|
||||
glob.glob(os.path.join(
|
||||
os.path.dirname(__file__), '../../apps/selendroid-test-app.apk')))
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
'../../apps/selendroid-test-app.apk'))
|
||||
desired_caps = {
|
||||
'device': 'selendroid',
|
||||
'app': app,
|
||||
@@ -22,15 +23,21 @@ class TestAndroidWebView(unittest.TestCase):
|
||||
desired_caps)
|
||||
|
||||
def test(self):
|
||||
button = self.driver.find_element_by_id('buttonStartWebview')
|
||||
button = self.driver.find_element_by_name('buttonStartWebviewCD')
|
||||
button.click()
|
||||
|
||||
self.driver.switch_to_window('WEBVIEW')
|
||||
self.driver.switch_to.context('WEBVIEW')
|
||||
|
||||
input_field = self.driver.find_element_by_id('name_input')
|
||||
input_field.send_keys('Mathieu')
|
||||
input_field.clear()
|
||||
input_field.send_keys('Appium User')
|
||||
input_field.submit()
|
||||
|
||||
# test that everything is a-ok
|
||||
source = self.driver.page_source
|
||||
self.assertNotEqual(-1, source.find('This is my way of saying hello'))
|
||||
self.assertNotEqual(-1, source.find('"Appium User"'))
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
+84
-93
@@ -1,27 +1,24 @@
|
||||
"""Be sure to use the latest selenium version
|
||||
as there might be some problems with JSON serialization
|
||||
|
||||
Before running the test make sure you started appium server
|
||||
with UICatalog app: grunt appium:UICatalog
|
||||
|
||||
TODO: flick, drag etc.
|
||||
"""
|
||||
More involved iOS tests, using UICatalog application.
|
||||
"""
|
||||
import unittest
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from appium import webdriver
|
||||
from appium.webdriver.common.touch_action import TouchAction
|
||||
# from selenium.webdriver.common.action_chains import ActionChains
|
||||
from selenium.webdriver.common.touch_actions import TouchActions
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
# from selenium.webdriver.common.keys import Keys
|
||||
import urllib2
|
||||
import json
|
||||
from time import sleep
|
||||
|
||||
def str_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for x in range(size))
|
||||
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
class ComplexIOSTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
@@ -32,59 +29,62 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://127.0.0.1:4723/wd/hub',
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'device': 'iPhone Simulator',
|
||||
'platform': 'Mac',
|
||||
'version': '6.0',
|
||||
'app': app
|
||||
})
|
||||
self._values = []
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
def _open_menu_position(self, index):
|
||||
# Opens up the menu at position [index] : starts at 0.
|
||||
table = self.driver.find_element_by_tag_name("tableView")
|
||||
self._row = table.find_elements_by_tag_name("tableCell")[index]
|
||||
table = self.driver.find_element_by_class_name("UIATableView")
|
||||
self._row = table.find_elements_by_class_name("UIATableCell")[index]
|
||||
self._row.click()
|
||||
|
||||
def test_find_element(self):
|
||||
# first view in UICatalog is a table
|
||||
table = self.driver.find_element_by_tag_name("tableView")
|
||||
table = self.driver.find_element_by_class_name("UIATableView")
|
||||
self.assertIsNotNone(table)
|
||||
|
||||
# is number of cells/rows inside table correct
|
||||
rows = table.find_elements_by_tag_name("tableCell")
|
||||
rows = table.find_elements_by_class_name("UIATableCell")
|
||||
self.assertEqual(12, len(rows))
|
||||
|
||||
# is first one about buttons
|
||||
self.assertEqual(rows[0].get_attribute("name"), "Buttons, Various uses of UIButton")
|
||||
|
||||
# there is nav bar inside the app
|
||||
nav_bar = self.driver.find_element_by_tag_name("navigationBar")
|
||||
nav_bar = self.driver.find_element_by_class_name("UIANavigationBar")
|
||||
self.assertTrue(nav_bar)
|
||||
|
||||
def test_frames(self):
|
||||
table = self.driver.find_element_by_tag_name("tableView")
|
||||
# go into webview frame
|
||||
self._open_menu_position(7)
|
||||
scroll = self.driver.find_element_by_tag_name("scrollview")
|
||||
webview = scroll.find_element_by_tag_name("webview")
|
||||
#find the URL field
|
||||
textfield = self.driver.find_element_by_name("URL entry")
|
||||
self.assertEqual(textfield.get_attribute("value"), "http://www.apple.com")
|
||||
|
||||
textfield.find_element_by_tag_name("button").click()
|
||||
# send www.google.com and press the Go button (\n)
|
||||
textfield.send_keys("http://www.google.com\\n")
|
||||
# get the window handles (webview)
|
||||
handle = self.driver.window_handles[0]
|
||||
self.driver.switch_to_window(handle)
|
||||
# Find the google logo
|
||||
logo = self.driver.find_element_by_id("hplogo")
|
||||
self.assertTrue(logo)
|
||||
self.driver.execute_script("mobile: leaveWebView")
|
||||
scroll = self.driver.find_element_by_class_name("UIAScrollView")
|
||||
webview = scroll.find_element_by_class_name("UIAWebView")
|
||||
|
||||
# get the contexts and switch to webview
|
||||
contexts = self.driver.contexts
|
||||
self.assertEqual([u'NATIVE_APP', u'WEBVIEW_1'], contexts)
|
||||
self.driver.switch_to.context(contexts[1])
|
||||
|
||||
# Find the store link
|
||||
sleep(4) # let the page load, perhaps
|
||||
logo = self.driver.find_element_by_id('gn-apple')
|
||||
self.assertIsNotNone(logo)
|
||||
|
||||
# leave the webview
|
||||
self.driver.switch_to.context(contexts[0])
|
||||
|
||||
# Verify we are out of the webview
|
||||
scroll_after = self.driver.find_element_by_tag_name("scrollview")
|
||||
scroll_after = self.driver.find_element_by_class_name("UIAScrollView")
|
||||
self.assertTrue(scroll_after)
|
||||
|
||||
def test_location(self):
|
||||
# get third row location
|
||||
row = self.driver.find_elements_by_tag_name("tableCell")[2]
|
||||
row = self.driver.find_elements_by_class_name("UIATableCell")[2]
|
||||
self.assertEqual(row.location['x'], 0)
|
||||
self.assertEqual(row.location['y'], 152)
|
||||
|
||||
@@ -92,52 +92,54 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
# make screenshot and get is as base64
|
||||
screenshot = self.driver.get_screenshot_as_base64()
|
||||
self.assertTrue(screenshot)
|
||||
|
||||
# make screenshot and save it to the local filesystem
|
||||
success = self.driver.get_screenshot_as_file("foo.png")
|
||||
self.assertTrue(success)
|
||||
self.assertTrue(os.path.isfile("foo.png"))
|
||||
|
||||
# get rid of the file
|
||||
os.remove("foo.png")
|
||||
|
||||
def test_attributes(self):
|
||||
# go to the toolbar section
|
||||
self._open_menu_position(8)
|
||||
|
||||
segmented_control = self.driver.find_element_by_tag_name("segemented")
|
||||
segmented_control = self.driver.find_element_by_class_name("UIASegmentedControl")
|
||||
# segmented_control is enabled by default
|
||||
self.assertTrue(segmented_control.is_enabled())
|
||||
self.assertTrue(segmented_control.is_displayed())
|
||||
# row is from previous view, should not be visible
|
||||
self.assertTrue(self._row.is_displayed())
|
||||
|
||||
#verify the text is what we expect
|
||||
tinted_text = self.driver.find_elements_by_tag_name("text")[4]
|
||||
self.assertEqual(tinted_text.text, "UISegmentControlStyleBar: (tinted)")
|
||||
tinted_control = self.driver.find_elements_by_tag_name("segemented")[4]
|
||||
tinted_buttons = tinted_control.find_elements_by_tag_name("button")
|
||||
# row is from previous view, should not be visible
|
||||
self.assertFalse(self._row.is_displayed())
|
||||
|
||||
tinted_control = self.driver.find_elements_by_class_name("UIASegmentedControl")[4]
|
||||
tinted_buttons = tinted_control.find_elements_by_class_name("UIAButton")
|
||||
|
||||
#verify the control has three buttons
|
||||
self.assertEqual(3, len(tinted_buttons))
|
||||
#verify the buttons have the right properties
|
||||
self.assertEquals(tinted_buttons[0].get_attribute("value"), '')
|
||||
self.assertEquals(tinted_buttons[1].get_attribute("value"), '1')
|
||||
self.assertEquals(tinted_buttons[2].get_attribute("value"), '')
|
||||
|
||||
#verify the buttons have the right text
|
||||
self.assertEquals(tinted_buttons[0].get_attribute('name'), 'Check')
|
||||
self.assertEquals(tinted_buttons[1].get_attribute('name'), 'Search')
|
||||
self.assertEquals(tinted_buttons[2].get_attribute('name'), 'Tools')
|
||||
|
||||
def test_text_field_edit(self):
|
||||
# go to the text fields section
|
||||
self._open_menu_position(2)
|
||||
text_field = self.driver.find_elements_by_tag_name("textField")[0]
|
||||
|
||||
text_field = self.driver.find_elements_by_class_name("UIATextField")[0]
|
||||
|
||||
# get default/empty text
|
||||
default_val = text_field.get_attribute("value")
|
||||
|
||||
# write some random text to element
|
||||
rnd_string = str_generator()
|
||||
text_field.send_keys(rnd_string)
|
||||
self.assertEqual(text_field.get_attribute("value"), rnd_string)
|
||||
# send some random keys
|
||||
rnd_string2 = str_generator()
|
||||
swipe = ActionChains(self.driver).send_keys(rnd_string2)
|
||||
swipe.perform()
|
||||
# check if text is there
|
||||
self.assertEqual(text_field.get_attribute("value"), rnd_string2)
|
||||
# clear
|
||||
|
||||
# clear and check if is empty/has default text
|
||||
text_field.clear()
|
||||
# check if is empty/has default text
|
||||
self.assertEqual(text_field.get_attribute("value"), default_val)
|
||||
|
||||
def test_alert_interaction(self):
|
||||
@@ -145,46 +147,38 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
self._open_menu_position(10)
|
||||
elements = self.driver.find_elements_by_name("Show Simple")
|
||||
|
||||
# # TOFIX: Looks like alert object is not proper state
|
||||
# triggerOk = elements[2]
|
||||
# triggerOk.click()
|
||||
# TOFIX: Looks like alert object is not proper state
|
||||
# something to do with UIActionSheet vs. UIAlertView?
|
||||
triggerOk = elements[0]
|
||||
triggerOk.click()
|
||||
alert = self.driver.switch_to_alert()
|
||||
|
||||
# # check if title of alert is correct
|
||||
# alert = self.driver.switch_to_alert()
|
||||
# this does not work here.
|
||||
# 'An attempt was made to operate on a modal dialog when one was not open.'
|
||||
# check if title of alert is correct
|
||||
# self.assertEqual(alert.text, "UIAlertView")
|
||||
# # dismiss alert
|
||||
# alert.dismiss()
|
||||
|
||||
# dismiss alert
|
||||
alert.accept()
|
||||
|
||||
# trigger modal alert with cancel & ok buttons
|
||||
triggerOkCancel = elements[1]
|
||||
triggerOkCancel.click()
|
||||
alert = self.driver.switch_to_alert()
|
||||
# check if title of alert is correct
|
||||
self.assertEqual(alert.text, "UIAlertView")
|
||||
alert.accept()
|
||||
|
||||
def test_scroll(self):
|
||||
# scroll menu
|
||||
# get initial third row location
|
||||
row = self.driver.find_elements_by_tag_name("tableCell")[2]
|
||||
location1 = row.location
|
||||
# perform swipe gesture
|
||||
swipe = TouchActions(self.driver).flick(0, -20)
|
||||
swipe.perform()
|
||||
# get new row coordinates
|
||||
location2 = row.location
|
||||
self.assertEqual(location1['x'], location2['x'])
|
||||
self.assertNotEqual(location1['y'], location2['y'])
|
||||
# check if title of alert is correct
|
||||
self.assertEqual(alert.text, "UIAlertView <Alert message>")
|
||||
alert.accept()
|
||||
|
||||
def test_slider(self):
|
||||
# go to controls
|
||||
self._open_menu_position(1)
|
||||
self._open_menu_position(10)
|
||||
|
||||
# get the slider
|
||||
slider = self.driver.find_element_by_tag_name("slider")
|
||||
self.assertEqual(slider.get_attribute("value"), "50%")
|
||||
drag = TouchActions(self.driver)
|
||||
drag.flick_element(slider, -0.5, 0, 0)
|
||||
drag.perform()
|
||||
slider = self.driver.find_element_by_class_name("UIASlider")
|
||||
self.assertEqual(slider.get_attribute("value"), "42%")
|
||||
|
||||
slider.set_value(0)
|
||||
self.assertEqual(slider.get_attribute("value"), "0%")
|
||||
|
||||
def test_sessions(self):
|
||||
@@ -192,8 +186,8 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
self.assertEqual(self.driver.session_id, data['sessionId'])
|
||||
|
||||
def test_size(self):
|
||||
table = self.driver.find_element_by_tag_name("tableView").size
|
||||
row = self.driver.find_elements_by_tag_name("tableCell")[0].size
|
||||
table = self.driver.find_element_by_class_name("UIATableView").size
|
||||
row = self.driver.find_elements_by_class_name("UIATableCell")[0].size
|
||||
self.assertEqual(table['width'], row['width'])
|
||||
self.assertNotEqual(table['height'], row['height'])
|
||||
|
||||
@@ -211,9 +205,6 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
self.assertNotEqual(source_main, source_textfields)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(ComplexIOSTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
import httplib
|
||||
import base64
|
||||
from random import randint
|
||||
from selenium import webdriver
|
||||
from appium import webdriver
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
@@ -18,7 +18,7 @@ SAUCE_USERNAME=os.environ.get('SAUCE_USERNAME')
|
||||
SAUCE_ACCESS_KEY=os.environ.get('SAUCE_ACCESS_KEY')
|
||||
base64string = base64.encodestring('%s:%s' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY))[:-1]
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
class SimpleIOSSauceTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
@@ -27,20 +27,16 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
command_executor='http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY),
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'platform': 'Mac 10.8',
|
||||
'device': 'iPhone Simulator',
|
||||
'version': '6.1',
|
||||
'app': app
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'iPhone Simulator',
|
||||
'platformVersion': '6.1',
|
||||
'app': app,
|
||||
'name': 'Appium Python iOS Test'
|
||||
})
|
||||
self._values = []
|
||||
|
||||
def _populate(self):
|
||||
# populate text fields with two random number
|
||||
elems = self.driver.find_elements_by_tag_name('textField')
|
||||
for elem in elems:
|
||||
rndNum = randint(0, 10)
|
||||
elem.send_keys(rndNum)
|
||||
self._values.append(rndNum)
|
||||
def tearDown(self):
|
||||
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
|
||||
self.driver.quit()
|
||||
|
||||
def _set_test_status(self, jobid, passed=True):
|
||||
# Report the status of your test to Sauce
|
||||
@@ -52,24 +48,33 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
result = connection.getresponse()
|
||||
return result.status == 200
|
||||
|
||||
def _populate(self):
|
||||
# populate text fields with two random numbers
|
||||
els = self.driver.find_elements_by_ios_uiautomation('elements()')
|
||||
|
||||
self._sum = 0
|
||||
for i in range(2):
|
||||
rnd = randint(0, 10)
|
||||
els[i].send_keys(rnd)
|
||||
self._sum += rnd
|
||||
|
||||
def test_ui_computation(self):
|
||||
# populate text fields with values
|
||||
self._populate()
|
||||
|
||||
# trigger computation by using the button
|
||||
buttons = self.driver.find_elements_by_tag_name("button")
|
||||
buttons[0].click()
|
||||
self.driver.find_element_by_accessibility_id('ComputeSumButton').click()
|
||||
|
||||
# is sum equal ?
|
||||
texts = self.driver.find_elements_by_tag_name("staticText")
|
||||
# sauce does not handle class name, so get fourth element
|
||||
# sum = self.driver.find_elements_by_class_name("UIAStaticText")[0].text
|
||||
sum = self.driver.find_element_by_ios_uiautomation('elements()[3]').text
|
||||
try:
|
||||
self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
|
||||
self.assertEqual(int(sum), self._sum)
|
||||
self._set_test_status(self.driver.session_id, True)
|
||||
except:
|
||||
self._set_test_status(self.driver.session_id, False)
|
||||
|
||||
def tearDown(self):
|
||||
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
|
||||
self.driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not (SAUCE_USERNAME and SAUCE_ACCESS_KEY):
|
||||
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
Simple iOS tests, showing accessing elements and getting/setting text from them.
|
||||
"""
|
||||
import unittest
|
||||
import os
|
||||
from random import randint
|
||||
from appium import webdriver
|
||||
from time import sleep
|
||||
|
||||
class SimpleIOSTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
app = os.path.join(os.path.dirname(__file__),
|
||||
'../../apps/TestApp/build/Release-iphonesimulator',
|
||||
'TestApp.app')
|
||||
app = os.path.abspath(app)
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://127.0.0.1:4723/wd/hub',
|
||||
desired_capabilities={
|
||||
'app': app
|
||||
})
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
def _populate(self):
|
||||
# populate text fields with two random numbers
|
||||
els = self.driver.find_elements_by_ios_uiautomation('elements()')
|
||||
|
||||
self._sum = 0
|
||||
for i in range(2):
|
||||
rnd = randint(0, 10)
|
||||
els[i].send_keys(rnd)
|
||||
self._sum += rnd
|
||||
|
||||
def test_ui_computation(self):
|
||||
# populate text fields with values
|
||||
self._populate()
|
||||
|
||||
# trigger computation by using the button
|
||||
self.driver.find_element_by_accessibility_id('ComputeSumButton').click()
|
||||
|
||||
# is sum equal ?
|
||||
# sauce does not handle class name, so get fourth element
|
||||
sum = self.driver.find_element_by_ios_uiautomation('elements()[3]').text
|
||||
self.assertEqual(int(sum), self._sum)
|
||||
|
||||
def test_scroll(self):
|
||||
els = self.driver.find_elements_by_class_name('UIAButton')
|
||||
els[5].click()
|
||||
|
||||
sleep(1)
|
||||
el = self.driver.find_element_by_name('OK')
|
||||
el.click()
|
||||
|
||||
sleep(1)
|
||||
el = self.driver.find_element_by_xpath('//UIAMapView[1]')
|
||||
|
||||
location = el.location
|
||||
self.driver.swipe(startx=location['x'], starty=location['y'], endx=0.5, endy=location['y'], duration=0.8)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleIOSTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
@@ -1,2 +0,0 @@
|
||||
nose==1.3.0
|
||||
selenium==2.32.0
|
||||
@@ -38,22 +38,21 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
||||
class MyRequestHandler(SimpleHTTPRequestHandler):
|
||||
"""Serve a sample HTML page so we can check if test works properly"""
|
||||
def do_GET(self):
|
||||
f = StringIO()
|
||||
f.write("<html><body>Welcome to the flipside!</body></html>")
|
||||
f.seek(0)
|
||||
|
||||
f = StringIO()
|
||||
f.write("<html><body>Welcome to the flipside!</body></html>")
|
||||
f.seek(0)
|
||||
#send code 200 response
|
||||
self.send_response(200)
|
||||
|
||||
#send code 200 response
|
||||
self.send_response(200)
|
||||
#send header first
|
||||
self.send_header('Content-type', 'text-html')
|
||||
self.end_headers()
|
||||
|
||||
#send header first
|
||||
self.send_header('Content-type', 'text-html')
|
||||
self.end_headers()
|
||||
|
||||
#send file content to client
|
||||
self.wfile.write(f.read())
|
||||
f.close()
|
||||
return
|
||||
#send file content to client
|
||||
self.wfile.write(f.read())
|
||||
f.close()
|
||||
return
|
||||
|
||||
|
||||
class Selenium2OnSauce(unittest.TestCase):
|
||||
@@ -101,12 +100,14 @@ class Selenium2OnSauce(unittest.TestCase):
|
||||
self.setUpWebServer()
|
||||
self.setUpTunnel()
|
||||
|
||||
caps = {'browserName': ''}
|
||||
caps['platform'] = "OS X 10.8"
|
||||
caps['version'] = "6"
|
||||
caps['app'] = 'safari'
|
||||
caps['device'] = 'iPhone Simulator'
|
||||
caps['name'] = 'Appium - iOS - python'
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'iPhone Simulator',
|
||||
'platformVersion': '6.1',
|
||||
'app': app,
|
||||
'name': 'Appium Python iOS Test (Connect)'
|
||||
})
|
||||
|
||||
self.driver = webdriver.Remote(
|
||||
desired_capabilities=caps,
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
from selenium import webdriver
|
||||
|
||||
# Returns abs path relative to this file and not cwd
|
||||
PATH = lambda p: os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), p)
|
||||
)
|
||||
|
||||
# think times can be useful e.g. when testing with an emulator
|
||||
THINK_TIME = 5.
|
||||
|
||||
desired_caps = {}
|
||||
desired_caps['device'] = 'selendroid'
|
||||
desired_caps['browserName'] = ''
|
||||
desired_caps['version'] = '4.3'
|
||||
desired_caps['app'] = PATH('../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk')
|
||||
desired_caps['app-package'] = 'com.example.android.apis'
|
||||
desired_caps['app-activity'] = '.ApiDemos'
|
||||
|
||||
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
el = driver.find_element_by_partial_link_text("Animat")
|
||||
assert el.text == "Animation"
|
||||
|
||||
el = driver.find_element_by_class_name("android.widget.TextView")
|
||||
assert el.text == "Accessibility"
|
||||
|
||||
el = driver.find_element_by_link_text("App")
|
||||
el.click()
|
||||
time.sleep(THINK_TIME)
|
||||
|
||||
els = driver.find_elements_by_class_name("android.widget.TextView")
|
||||
assert els[1].text == "Activity"
|
||||
|
||||
driver.back()
|
||||
time.sleep(THINK_TIME)
|
||||
|
||||
el = driver.find_element_by_link_text("Animation")
|
||||
flick = webdriver.TouchActions(driver).flick_element(el, 0, -100, 0)
|
||||
flick.perform()
|
||||
|
||||
el = driver.find_element_by_link_text("Views")
|
||||
el.click()
|
||||
time.sleep(THINK_TIME)
|
||||
|
||||
driver.quit()
|
||||
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
from time import sleep
|
||||
import unittest
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
# Returns abs path relative to this file and not cwd
|
||||
PATH = lambda p: os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), p)
|
||||
)
|
||||
|
||||
# think times can be useful e.g. when testing with an emulator
|
||||
THINK_TIME = 5.
|
||||
|
||||
class SimpleSalendroidTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
desired_caps = {}
|
||||
desired_caps['platformName'] = 'Android'
|
||||
desired_caps['platformVersion'] = '4.1'
|
||||
desired_caps['deviceName'] = 'Android Emulator'
|
||||
desired_caps['automationName'] = "selendroid"
|
||||
desired_caps['app'] = PATH(
|
||||
'../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk'
|
||||
)
|
||||
desired_caps['appPackage'] = 'com.example.android.apis'
|
||||
desired_caps['appActivity'] = '.ApiDemos'
|
||||
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
def tearDown(self):
|
||||
# end the session
|
||||
self.driver.quit()
|
||||
|
||||
def test_selendroid(self):
|
||||
el = self.driver.find_element_by_name("Animation")
|
||||
# assert el.text == "Animation"
|
||||
self.assertEqual('Animation', el.text)
|
||||
|
||||
el = self.driver.find_element_by_class_name("android.widget.TextView")
|
||||
# assert el.text == "Accessibility"
|
||||
self.assertEqual('API Demos', el.text)
|
||||
|
||||
el = self.driver.find_element_by_name("App")
|
||||
el.click()
|
||||
sleep(THINK_TIME)
|
||||
|
||||
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.driver.back()
|
||||
sleep(THINK_TIME)
|
||||
|
||||
el = self.driver.find_element_by_name("Animation")
|
||||
self.assertEqual('Animation', el.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleSalendroidTests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
@@ -1,55 +0,0 @@
|
||||
"""Be sure to use the latest selenium version
|
||||
as there might be some problems with JSON serialization
|
||||
|
||||
Before running the test make sure you started appium server
|
||||
with TestApp app: grunt appium:TestApp
|
||||
"""
|
||||
import unittest
|
||||
import os
|
||||
from random import randint
|
||||
from selenium import webdriver
|
||||
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
app = os.path.join(os.path.dirname(__file__),
|
||||
'../../apps/TestApp/build/Release-iphonesimulator',
|
||||
'TestApp.app')
|
||||
app = os.path.abspath(app)
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://127.0.0.1:4723/wd/hub',
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'device': 'iPhone Simulator',
|
||||
'platform': 'Mac',
|
||||
'version': '6.0',
|
||||
'app': app
|
||||
})
|
||||
self._values = []
|
||||
|
||||
def _populate(self):
|
||||
# populate text fields with two random number
|
||||
elems = self.driver.find_elements_by_tag_name('textField')
|
||||
for elem in elems:
|
||||
rndNum = randint(0, 10)
|
||||
elem.send_keys(rndNum)
|
||||
self._values.append(rndNum)
|
||||
|
||||
def test_ui_computation(self):
|
||||
# populate text fields with values
|
||||
self._populate()
|
||||
# trigger computation by using the button
|
||||
buttons = self.driver.find_elements_by_tag_name("button")
|
||||
buttons[0].click()
|
||||
# is sum equal ?
|
||||
texts = self.driver.find_elements_by_tag_name("staticText")
|
||||
self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,52 +0,0 @@
|
||||
"""Be sure to use the latest selenium version
|
||||
as there might be some problems with JSON serialization
|
||||
|
||||
Before running the test make sure you started appium server
|
||||
with TestApp app: grunt appium:TestApp
|
||||
"""
|
||||
import unittest
|
||||
import os
|
||||
from random import randint
|
||||
from selenium import webdriver
|
||||
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# set up appium
|
||||
app = "io.appium.TestApp"
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://127.0.0.1:4723/wd/hub',
|
||||
desired_capabilities={
|
||||
'browserName': '',
|
||||
'device': 'iPhone Simulator',
|
||||
'platform': 'Mac',
|
||||
'version': '6.0',
|
||||
'app': app
|
||||
})
|
||||
self._values = []
|
||||
|
||||
def _populate(self):
|
||||
# populate text fields with two random number
|
||||
elems = self.driver.find_elements_by_tag_name('textField')
|
||||
for elem in elems:
|
||||
rndNum = randint(0, 10)
|
||||
elem.send_keys(rndNum)
|
||||
self._values.append(rndNum)
|
||||
|
||||
def test_ui_computation(self):
|
||||
# populate text fields with values
|
||||
self._populate()
|
||||
# trigger computation by using the button
|
||||
buttons = self.driver.find_elements_by_tag_name("button")
|
||||
buttons[0].click()
|
||||
# is sum equal ?
|
||||
texts = self.driver.find_elements_by_tag_name("staticText")
|
||||
self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user