Skip to content

Instantly share code, notes, and snippets.

@Kingson
Created November 20, 2013 09:04
Show Gist options
  • Save Kingson/7560033 to your computer and use it in GitHub Desktop.
Save Kingson/7560033 to your computer and use it in GitHub Desktop.
Appium
#! /usr/bin/env python
# coding=utf-8
"""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
import time
from selenium import webdriver
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
# set up appium
# app = "io.appium.DouDouY"
app = os.path.join(os.path.dirname(__file__),
'../../apps/DDY/build/',
'DouDouY.app')
app = os.path.abspath(app)
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'browserName': 'iOS',
'device': 'iPhone Simulator',
'platform': 'Mac',
'version': '7.0',
'app': app
})
# self._values = []
js_snippet = "mobile: flick"
args = {"startX": 160, "startY": 230, 'endX':10, 'endY':230, 'touchCount':1, 'duration':2}
self.driver.execute_script(js_snippet, args)
def _populate(self):
# populate text fields with two random number
time.sleep(5)
buttons = self.driver.find_elements_by_tag_name('button')
buttons[4].click()
# self.driver.find_element_by_name('登录').click()
# for elem in elems:
# rndNum = randint(0, 10)
# elem.send_keys(rndNum)
# self._values.append(rndNum)
def test_computation(self):
# populate text fields with values
date = ["zhoujs","bbbb"]
self._populate()
# trigger computation by using the button
# print self.driver.page_source
elems = self.driver.find_elements_by_tag_name("textField")
# elems[0].send_keys(date[0])
# elems[1].send_keys(date[1])
for elem in elems:
# rndNum = randint(0, 10)
elem.send_keys(date[0]+ "\\n" + date[1])
# self._values.append(i)
# is sum equal ?
# self.driver.execute_script("mobile: hideKeyboard")
buttons = self.driver.find_elements_by_tag_name('UIAButton')
for button in buttons:
print button.text
if button.text.encode('utf-8') == "登录":
button.click()
break
texts = self.driver.find_elements_by_tag_name("staticText")
for text in texts:
print text.text
# buttons[0].click
# texts = self.driver.find_elements_by_tag_name("staticText")
# self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
def tearDown(self):
# pass
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment