【Python_Android】: Android Appium Automation Demo for calculator

import os
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)
)


class ContactsAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '6.0'
        desired_caps['deviceName'] = 'emulator-5554'
        desired_caps['appPackage'] = 'com.android.calculator2'
        desired_caps['appActivity'] = '.Calculator'

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.close_app()
        self.driver.quit()

    def test_add_contacts(self):
        """ Demo : 2 + 4 = """

        # Click delete button
        del_btn = self.driver.find_element_by_id("com.android.calculator2:id/del")
        del_btn.click()
        sleep(2)

        # Click Num 2
        Num2 = self.driver.find_element_by_id("com.android.calculator2:id/digit_2")
        Num2.click()
        sleep(2)

        # Click Add
        plus_btn = self.driver.find_element_by_id("com.android.calculator2:id/op_add")
        plus_btn.click()
        sleep(2)

        # Click Num 4
        Num4 = self.driver.find_element_by_id("com.android.calculator2:id/digit_4")
        Num4.click()
        sleep(2)

        # Click on equal
        Equ_btn = self.driver.find_element_by_id("com.android.calculator2:id/eq")
        Equ_btn.click()


if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

 

posted @ 2017-03-27 18:25  skyaiolos0426  阅读(320)  评论(0)    收藏  举报