请自行在电脑上搭建使用Appium进行安卓APP自动化测试的环境(client编程库,Appium Server,JDK,Android SDK),连接自己的安卓手机或在安卓模拟器中测试安卓软件(安卓自带的软件,或者你手机里安装的软件)。
实验内容:
(1)要求自行编写测试脚本代码,执行测试脚本并分析结果;
(2)至少测试三个APP的一项功能,例如计算器的按键输入功能;
实验要求:
(1)撰写实验报告,主要填写本人测试步骤、测试结果分析和自己的实验体会;
(2)测试步骤要附上自己所编写的三个APP测试的脚本;
(3)测试结果分析要附上截图。
所需appium相关环境:
(环境安装之后再来丰富)
这里SDK下载安装很慢需要耐心等待。
代码:
1.实现浏览器搜索
from appium.webdriver import Remote
# 链接服务地址
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
caps = {"platformName": "Android"}
caps['appPackage'] = 'com.android.browser'
caps['appActivity'] = 'com.android.browser.BrowserActivity'
driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
driver.implicitly_wait(3)
driver.find_element(By.ID, "android:id/button1").click()
driver.implicitly_wait(5)
driver.find_element(By.ID, "com.android.browser:id/bbq").click()
driver.press_keycode(47).press_keycode(51).press_keycode(44).press_keycode(49)
driver.find_element (By.ID,'com.android.browser:id/b_8').click()
2.实现计算器计算测试
from appium.webdriver import Remote
# 链接服务地址
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
caps = {"platformName": "Android"}
caps['appPackage'] = 'com.miui.calculator'
caps['appActivity'] = 'com.miui.calculator.cal.CalculatorActivity'
driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
driver.implicitly_wait(5)
driver.find_element(By.ID, "android:id/button1").click()
driver.find_element(By.XPATH, "/ hierarchy / android.widget.FrameLayout / android.widget.FrameLayout").click()
driver.find_element(By.ID, "com.miui.calculator:id/digit_1").click()
driver.find_element(By.ID, "com.miui.calculator:id/op_add").click()
driver.find_element(By.ID, "com.miui.calculator:id/digit_1").click()
driver.find_element(By.ID, "com.miui.calculator:id/btn_equal_s").click()
3.实现打电话测试
from appium.webdriver import Remote
# 链接服务地址
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
caps = {"platformName": "Android"}
caps['appPackage'] = 'com.android.contacts'
caps['appActivity'] = 'com.android.contacts.activities.TwelveKeyDialer'
driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
driver.implicitly_wait(5)
# 输入电话号码
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="一"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="零"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="零"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="八"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="六"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="一"]/android.view.ViewGroup/android.widget.TextView[1]').click()
driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="一"]/android.view.ViewGroup/android.widget.TextView[1]').click()
# 拨通
driver.find_element(By.ID, 'com.android.contacts:id/call_sim2').click()