From a0f2c5fd73acbca2f09ac41f198fc2db850e5c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A3=AE?= <1263991649@qq.com> Date: Thu, 26 Aug 2021 21:36:33 +0800 Subject: [PATCH] =?UTF-8?q?appium=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B9=B6=E5=88=A0=E9=99=A4=E6=88=90=E5=91=98=EF=BC=88?= =?UTF-8?q?PO=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PyCharm/testappium/case/__init__.py | 0 PyCharm/testappium/case/add_member_test.py | 29 +++++++++++++++ PyCharm/testappium/page/__init__.py | 0 PyCharm/testappium/page/add_member_page.py | 13 +++++++ PyCharm/testappium/page/app.py | 35 +++++++++++++++++++ PyCharm/testappium/page/base_page.py | 10 ++++++ PyCharm/testappium/page/contact_page.py | 28 +++++++++++++++ PyCharm/testappium/page/editor_member_page.py | 16 +++++++++ PyCharm/testappium/page/main_page.py | 8 +++++ PyCharm/testappium/utils/__init__.py | 0 PyCharm/testappium/utils/get_data.py | 16 +++++++++ 11 files changed, 155 insertions(+) create mode 100644 PyCharm/testappium/case/__init__.py create mode 100644 PyCharm/testappium/case/add_member_test.py create mode 100644 PyCharm/testappium/page/__init__.py create mode 100644 PyCharm/testappium/page/add_member_page.py create mode 100644 PyCharm/testappium/page/app.py create mode 100644 PyCharm/testappium/page/base_page.py create mode 100644 PyCharm/testappium/page/contact_page.py create mode 100644 PyCharm/testappium/page/editor_member_page.py create mode 100644 PyCharm/testappium/page/main_page.py create mode 100644 PyCharm/testappium/utils/__init__.py create mode 100644 PyCharm/testappium/utils/get_data.py diff --git a/PyCharm/testappium/case/__init__.py b/PyCharm/testappium/case/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyCharm/testappium/case/add_member_test.py b/PyCharm/testappium/case/add_member_test.py new file mode 100644 index 0000000..65f5197 --- /dev/null +++ b/PyCharm/testappium/case/add_member_test.py @@ -0,0 +1,29 @@ +from page.app import App +from utils.get_data import GetData + + +class TestAddMember: + def setup_class(self): + self.app = App() + self.data = GetData() + self.name = self.data.get_name() + self.phonenum = self.data.get_phonenum() + + def setup(self): + self.main = self.app.start().goto_main() + + + def teardown_class(self): + self.app.quit() + + def test_add(self): + ele = self.main.click_contact().click_add_member().add_member().editor_member(self.name, + self.phonenum).find_toast() + assert ele + + + def test_delete(self): + print(self.name) + ele2 = self.main.click_contact().delete_member(self.name) + assert ele2 + diff --git a/PyCharm/testappium/page/__init__.py b/PyCharm/testappium/page/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyCharm/testappium/page/add_member_page.py b/PyCharm/testappium/page/add_member_page.py new file mode 100644 index 0000000..73735a5 --- /dev/null +++ b/PyCharm/testappium/page/add_member_page.py @@ -0,0 +1,13 @@ +from page.base_page import BasePage +from page.editor_member_page import Editor + + +class AddMemberPage(BasePage): + def add_member(self): + self.driver.find_element_by_xpath("//*[@text='手动输入添加']").click() + return Editor(self.driver) + + def find_toast(self): + ele = self.driver.find_element_by_xpath("//*[@text='添加成功']") + return ele + diff --git a/PyCharm/testappium/page/app.py b/PyCharm/testappium/page/app.py new file mode 100644 index 0000000..2de67ab --- /dev/null +++ b/PyCharm/testappium/page/app.py @@ -0,0 +1,35 @@ +from appium import webdriver + +from page.base_page import BasePage +from page.main_page import MainPage + + +class App(BasePage): + def start(self): + if self.driver == None: + desire_caps = { # capability 设置 + "platformName": "android", # 要测试的平台 + "deviceName": "127.0.0.1:7555", # 要启动设备的名称 + "appPackage": "com.tencent.wework", # 包名 + "appActivity": ".launch.WwMainActivity", # 要打开的活动页 + "noReset": "true", # 不清理缓存 + "unicodeKeyBoard": "true", # 设置允许输入中文 + "resetKeyBoard": "true", # 同上 + "skipDeviceInitialization": "true", # 跳过设备的初始化 + 'automationName': "uiautomator2" # 用到的平台工具名 + } + self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desire_caps) # 打开设备,并传入capability参数 + self.driver.implicitly_wait(5) # 隐式等待 + else: + self.driver.launch_app() + return self + + def quit(self): + self.driver.quit() + + def goto_main(self): + return MainPage(self.driver) + + + + diff --git a/PyCharm/testappium/page/base_page.py b/PyCharm/testappium/page/base_page.py new file mode 100644 index 0000000..c862261 --- /dev/null +++ b/PyCharm/testappium/page/base_page.py @@ -0,0 +1,10 @@ +from selenium.webdriver.remote.webdriver import WebDriver + + +class BasePage: + def __init__(self,driver:WebDriver=None): + self.driver = driver + + + + diff --git a/PyCharm/testappium/page/contact_page.py b/PyCharm/testappium/page/contact_page.py new file mode 100644 index 0000000..f8324ee --- /dev/null +++ b/PyCharm/testappium/page/contact_page.py @@ -0,0 +1,28 @@ +from appium.webdriver.common.mobileby import MobileBy + +from page.add_member_page import AddMemberPage +from page.base_page import BasePage + + +class ContactPage(BasePage): + def click_add_member(self): + self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, + 'new UiScrollable(new UiSelector().' + 'scrollable(true).instance(0)).' + 'scrollIntoView(new UiSelector().' + 'text("添加成员").instance(0));').click() # 滑动寻找并点击'添加成员' + return AddMemberPage(self.driver) # 跳转到添加成员界面 + + def delete_member(self, name): + self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, + f'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("{name}").instance(0));').click() # 滑动寻找并点击成员姓名 + self.driver.find_element_by_xpath("//*[contains(@text,'个人信息')]/../../../../../*[2]").click() # 点击更多 + self.driver.find_element_by_xpath("//*[@text='编辑成员']").click() # 点击'编辑成员' + self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, + 'new UiScrollable(new UiSelector().' + 'scrollable(true).instance(0)).' + 'scrollIntoView(new UiSelector().' + 'text("删除成员").instance(0));').click() # 滑动寻找并点击'删除成员' + self.driver.find_element_by_xpath("//*[@text='确定']").click() # 点击确定 + return AddMemberPage(self.driver) + diff --git a/PyCharm/testappium/page/editor_member_page.py b/PyCharm/testappium/page/editor_member_page.py new file mode 100644 index 0000000..d87ce43 --- /dev/null +++ b/PyCharm/testappium/page/editor_member_page.py @@ -0,0 +1,16 @@ + +from page.base_page import BasePage + + +class Editor(BasePage): + def editor_member(self,name,phonenumber): + self.driver.find_element_by_xpath( + "//*[contains(@text,'姓名')]/../android.widget.EditText").send_keys(name) + self.driver.find_element_by_xpath( + "//*[contains(@text,'手机')]/../android.widget.RelativeLayout/android.widget.RelativeLayout" + "/android.widget.EditText").send_keys(phonenumber) + self.driver.find_element_by_xpath("//*[@text='保存']").click() + from page.add_member_page import AddMemberPage + return AddMemberPage(self.driver) + + diff --git a/PyCharm/testappium/page/main_page.py b/PyCharm/testappium/page/main_page.py new file mode 100644 index 0000000..3d8afd6 --- /dev/null +++ b/PyCharm/testappium/page/main_page.py @@ -0,0 +1,8 @@ +from page.base_page import BasePage +from page.contact_page import ContactPage + + +class MainPage(BasePage): + def click_contact(self): + self.driver.find_element_by_xpath("//*[@text='通讯录']").click() + return ContactPage(self.driver) \ No newline at end of file diff --git a/PyCharm/testappium/utils/__init__.py b/PyCharm/testappium/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyCharm/testappium/utils/get_data.py b/PyCharm/testappium/utils/get_data.py new file mode 100644 index 0000000..437ef33 --- /dev/null +++ b/PyCharm/testappium/utils/get_data.py @@ -0,0 +1,16 @@ +from faker import Faker + + +class GetData: + def __init__(self): + self.faker = Faker("zh-CN") + + def get_name(self): + return self.faker.name() + + def get_phonenum(self): + return self.faker.phone_number() + +if __name__ == '__main__': + print(GetData().get_name()) + print(GetData().get_phonenum())