PPT
https://pdf.ceshiren.com/ck21/appium1
代码地址
学习路线
2022_App自动化测试学习大纲.xmind.zip (214.5 KB)
@pytest.mark.parametrize('name,phone',[('成小郭3','18767465762')])
def test_addcontact(self,name,phone):
"""
通讯录添加成员用例步骤:
进入【通讯录】页面
点击【添加成员】
点击【手动输入添加】
输入【姓名】【手机号】并点击【保存】
验证点:
登录成功提示信息
"""
self.driver.find_element(AppiumBy.XPATH,"//*[@text='通讯录']").click()
self.driver.find_element(AppiumBy.XPATH,'//*[@text="添加成员"]').click()
self.driver.find_element(AppiumBy.XPATH,'//*[@text="手动输入添加"]').click()
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/bsm').clear()
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/bsm').send_keys(name)
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/hgi').clear()
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/hgi').send_keys(phone)
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/at6').click()
self.driver.find_element(AppiumBy.ID,'com.tencent.wework:id/kbo').click()
result = self.driver.find_element(AppiumBy.XPATH,f'//*[@text="{name}"]').text
print(result)
assert result == name
pass
def test_addcontact(self):
"""
通讯录添加成员用例步骤:
进入【通讯录】页面
点击【添加成员】
点击【手动输入添加】
输入【姓名】【手机号】并点击【保存】
验证点:
登录成功提示信息
"""
self.driver.find_element(MobileBy.XPATH, "//*[@text='通讯录']").click()
self.driver.find_element(MobileBy.XPATH, "//*[@text='添加成员']").click()
self.driver.find_element(MobileBy.XPATH, "//*[@text='手动输入添加']").click()
self.driver.find_element(MobileBy.XPATH, "//*[contains(@text,'姓名')]/../*[@text='必填']").send_keys("bbbcc")
self.driver.find_element(MobileBy.XPATH, "//*[contains(@text,'手机')]/..//*[@text='必填']").send_keys("18800000005")
self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()
element_toast = self.driver.find_element(MobileBy.XPATH,
"//*[@class='android.widget.Toast']")
result = element_toast.get_attribute("text")
# 断言
assert "添加成功" == result
建议:
外出打卡练习代码:
mainpage:
from selenium.webdriver.common.by import By
from app_appium_shizhan_of_mine.pageobject.address import AddressPage
from app_appium_shizhan_of_mine.pageobject.basepage import BasePage
class MainPage(BasePage):
def click_addresslist(self):
'''点击通讯录'''
self.driver.find_element(By.XPATH,'//*[@text="通讯录"]').click()
return AddressPage(self.driver)
def click_workbench(self):
'''点击工作台'''
self.driver.find_element(By.XPATH,'//*[@text="工作台"]').click()
from app_appium_shizhan_of_mine.pageobject.workbenchpage import WorkbenchPage
return WorkbenchPage(self.driver)
WorkbenchPage:
from selenium.webdriver.common.by import By
from app_appium_shizhan_of_mine.pageobject.basepage import BasePage
class WorkbenchPage(BasePage):
def click_clock(self):
'''点击打卡button'''
self.driver.find_element(By.XPATH,'//*[@text="打卡"]').click()
from app_appium_shizhan_of_mine.pageobject.clockpage import ClockPage
return ClockPage(self.driver)
ClockPage:
from selenium.webdriver.common.by import By
from app_appium_shizhan_of_mine.pageobject.basepage import BasePage
class ClockPage(BasePage):
def click_Punch_out(self):
'''点击外出打卡'''
self.driver.find_element(By.XPATH,'//*[@text="外出打卡"]').click()
self.driver.find_element(By.ID,'com.tencent.wework:id/b4k').click()
result_text=self.driver.find_element(By.ID,'com.tencent.wework:id/p7').text
return result_text
testcase截图:
课后练习:使用Appium实现删除联系人操作
def test_delete_contact(self):
# 1、点击【通讯录】菜单
self.driver.find_element(AppiumBy.XPATH, "//*[@text='通讯录']").click()
# 2、点击通讯录管理图标
self.driver.find_element(AppiumBy.XPATH, "//*[@resource-id='com.tencent.wework:id/kor']").click()
# 获取删除成员前通讯录列表中成员的数量
res = self.driver.find_element(AppiumBy.XPATH, "//*[contains(@text, '人未加入')]").text
# 3、点击指定的人名进行删除操作
self.driver.find_element(AppiumBy.XPATH, "//*[@text='郝娟']").click()
self.swipe_find('删除成员').click()
self.driver.find_element(AppiumBy.XPATH, "//*[@text='确定']").click()
# 获取删除成员之后总的成员数量
time.sleep(3)
res_New = self.driver.find_element(AppiumBy.XPATH, "//*[contains(@text, '人未加入')]").text
assert int(res[1])-1 == int(res_New[1])