def testaddcontact(self): """ Summary:testAddContact: Add a contact. Steps: 1. Open Contacts app 2. Add contact 3. Exit Contacts app """ #get contact number before add beforeNO = self.getcontactnumber() #step 2 if no contact if d.exists(text='No contacts.'): d(text='Create a new contact').click.wait() if d.exists(text='Keep local'): d(text='Keep local').click.wait() self.inputcontactinfo() #step 2 if exists contact else: d(description='Add Contact').click.wait() if d.exists(text='Keep local'): d(text='Keep local').click.wait() self.inputcontactinfo() #get contact number after add time.sleep(3) afterNO = self.getcontactnumber() #assert afterNO = beforeNO + 1 assert afterNO == beforeNO + 1
def test_power_resource_found(self): '''Check if the power resources can be found.''' self.appmgr.go_to_resources_for_ocfdemo() time.sleep(data_settings.app_found_res_and_wait) self.resource_found = d.exists(className='android.view.View', descriptionContains='/a/power') self.assertTrue(self.resource_found, 'The power resource is not found.')
def test_ambient_light_resource_found(self): '''Check if the ambient light resource can be found.''' self.appmgr.go_to_resources_for_ocfdemo() time.sleep(data_settings.app_found_res_and_wait) self.resource_found = d.exists(className='android.view.View', descriptionContains='/a/illuminance') self.assertTrue(self.resource_found, 'The ambient light resource is not found.')
def testdeletecontact(self): """ Summary:testAddContact: Add a contact. Steps: 1. Open Contacts app 2. Delete contact 3. Exit Contacts app """ #get contact number before delete beforeNO = self.getcontactnumber() #step 2 if beforeNO=0 if beforeNO == 0: d(text='Create a new contact').click.wait() if d.exists(text='Keep local'): d(text='Keep local').click.wait() self.inputcontactinfo() d(resourceId='android:id/up').click.wait() time.sleep(3) beforeNO = self.getcontactnumber() #single tap the first contact d.click(338,478) #delete contact d(description='More options',index='1').click.wait() d(text='Delete').click.wait() d(text='OK').click.wait() time.sleep(3) afterNO = self.getcontactnumber() #assert afterNO = beforeNO - 1 assert afterNO == beforeNO - 1
def launchcamera(self): d(description='Apps').click.wait() while not d.exists(text='Camera'): d().swipe.right() time.sleep(3) d(text='Camera').click.wait() d(description="Shutter button").wait.exists(timeout=3000) time.sleep(5)
def test_switch_resource_found(self): '''Check if the switch resources can be found.''' self.appmgr.go_to_resources_for_ocfdemo() time.sleep(10) self.resource_found = d.exists(className='android.view.View', descriptionContains='/a/binarySwitch') self.assertTrue(self.resource_found, 'The switch resource is not found.')
def testCall(self): import time #d.sleep(9) assert 0, 'phone failure' assert d.exists(text='Phone') , 'Phone app not appear on home screen' d(text='Phone').click.wait() d(description='one').click() d(description='zero').click() d(description='zero').click() d(description='eight').click() d(description='six').click() assert d.exists(text="10086") if d.exists(description='dial'): d(description='dial').click.wait() assert d(text="Dialing").wait.exists(timeout=5000), 'call not connected in 10 secs' assert d(text="0:10").wait.exists(timeout=20000), 'call duration should be 10 secs' d(className='android.widget.Button', index=1).click.wait() assert d(description='dial').wait.exists(timeout=3000)
def messageAppOpen(): app_Open = subprocess.Popen( "adb shell am start -a android.intent.action.MAIN -n com.google.android.apps.messaging/com.google.android.apps.messaging.ui.ConversationListActivity", stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) if app_Open.returncode: print("Message app is unable to launch:") else: if d.exists(text="Messages"): time.sleep(2) #d.press.back() print("Message app is launched successfully:") app_Open.stdout.close()
def testCall(self): """ Samary:testCall Step1:male a call from phone book """ import time #d.sleep(9) assert 0, 'phone failure' assert d.exists(text='Phone'), 'Phone app not appear on home screen' d(text='Phone').click.wait() d(description='one').click() d(description='zero').click() d(description='zero').click() d(description='eight').click() d(description='six').click() assert d.exists(text="10086") if d.exists(description='dial'): d(description='dial').click.wait() assert d(text="Dialing").wait.exists( timeout=5000), 'call not connected in 10 secs' assert d(text="0:10").wait.exists( timeout=20000), 'call duration should be 10 secs' d(className='android.widget.Button', index=1).click.wait() assert d(description='dial').wait.exists(timeout=3000)
def test_ocfdemo_build_install_launch(self): ''' Check if there're any errors during the following steps: 1. git clone the cordova-plugin-ocf-demo 2. build the app 3. install and launch it ''' clone_cmd = [ 'git', 'clone', '--depth', '1', '--single-branch', '--branch', 'master', self.cordova_pluin_ocf_demo_url ] clone_proc = subprocess.Popen(clone_cmd, cwd=self.workspace_dir) clone_proc.wait() self.assertEqual(clone_proc.returncode, 0, 'clone the cordova_pluin_ocf_demo failed.') build_cmds = [['npm', 'install'], ['bower', 'install'], ['grunt', 'platform:add:android'], ['grunt', 'build']] for build_cmd in build_cmds: build_proc = subprocess.Popen(build_cmd, cwd=self.prj_dir) build_proc.wait() self.assertEqual( build_proc.returncode, 0, 'Failed to build when running [{0}]'.format(build_cmd)) self.assertTrue(os.path.exists(self.prj_dir), 'cordova-plugin-ocf-demo apk is not found!') install_cmd = ['adb', 'install', self.apk_path] install_proc = subprocess.Popen(install_cmd, cwd=self.prj_dir) install_proc.wait() self.assertEqual(install_proc.returncode, 0, 'Failed to install OCF Demo apk') self.appmgr.launch_app(self.pkg_id) time.sleep(5) btn = d(className='android.widget.Button', index=0) btn.click() title_found = d.exists(className='android.view.View', descriptionContains='OCF Demo') self.assertTrue(title_found, 'Launching the app OK?')
def test_power_z_device_found(self): ''''Check if the OCF device can be found.''' self.appmgr.go_to_devices_for_ocfdemo() time.sleep(data_settings.app_found_dev_and_wait) self.device_found = d.exists(descriptionContains='UUID') self.device_found = self.device_found and d.exists(descriptionContains='URL') self.device_found = self.device_found and d.exists(descriptionContains='Name') self.device_found = self.device_found and d.exists(descriptionContains='Data models') self.device_found = self.device_found and d.exists(descriptionContains='Core spec version') self.device_found = self.device_found and d.exists(descriptionContains='Role') self.assertTrue(self.device_found, 'OCF device is not found.')
def clearall(self): if not d.exists(text='No conversations.'): d(description='More options',index='2').click.wait() d(text='Delete all threads').click.wait() d(text='Delete',index='1').click.wait() assert d.exists(text='No conversations.')
def launchcontact(self): #launch contact d(text='People').click.wait() #if google account pop up if d.exists(text='Make it Google'): d(text='Not now').click.wait()
d.long_click(x, y) d.swipe(sx, sy, ex, ey, steps=10) d.screenshot("home.png") d.dump("hierarchy.xml") xml = d.dump() - text, textContains, textMatches, textStartsWith - className, classNameMatches - description, descriptionContains, descriptionMatches, descriptionStartsWith - checkable, checked, clickable, longClickable - scrollable, enabled,focusable, focused, selected - packageName, packageNameMatches - resourceId, resourceIdMatches - index, instance ''' d(text='Clock', className='android.widget.TextView') d(className="android.widget.ListView").child(text="Bluetooth") d(text="Google").sibling(className="android.widget.ImageView") d(text="Wi‑Fi").right(className="android.widget.Switch").click() d(text="Settings").exists # True if exists, else False d.exists(text="Settings") # alias of above property. d(text="Settings").info d(text="Settings").click() print 111