Commit 461ae9ca authored by seveniruby's avatar seveniruby
Browse files

init

parents
## 大连内训
- app自动化测试理论
- app自动化测试与page object模式
- 测试框架封装与自动遍历
- 多设备兼容性测试
## 相关链接
- https://ceshiren.com/t/topic/14425
\ No newline at end of file
from appium import webdriver
from page.main_page import MainPage
class App:
def __init__(self):
caps = {}
caps["appPackage"] = "io.appium.android.apis"
caps["appActivity"] = ".ApiDemos"
caps["platformName"] = "android"
caps["ensureWebviewsHavePages"] = True
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
self.driver.implicitly_wait(10)
def default(self):
return MainPage(self.driver)
def back(self):
self.driver.back()
from selenium.webdriver.remote.webdriver import WebDriver
class BasePage:
def __init__(self, driver):
self.driver: WebDriver=driver
def back(self):
self.driver.back()
\ No newline at end of file
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.remote.webdriver import WebDriver
from page.base_page import BasePage
class CustomTitlePage(BasePage):
def change_left_title(self, title):
try:
edit = self.driver.find_element(MobileBy.ID, 'left_text_edit')
edit.clear()
edit.send_keys(title)
self.driver.find_element(MobileBy.ID, 'left_text_button').click()
res = self.driver.find_element(MobileBy.ID, 'left_text').text
except:
# exception handle
# return origin location
pass
return res
def change_right_title(self, title):
return "right title"
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from page.base_page import BasePage
from page.custom_title_page import CustomTitlePage
from page.search_page import SearchPage
class MainPage(BasePage):
def invoke_search(self):
el1 = self.driver.find_element_by_accessibility_id("App")
el1.click()
el2 = self.driver.find_element_by_accessibility_id("Search")
el2.click()
el3 = self.driver.find_element_by_accessibility_id("Invoke Search")
el3.click()
return SearchPage(self.driver)
def custom_title(self):
self.driver.find_element(MobileBy.ACCESSIBILITY_ID, "App").click()
self.driver.find_element(MobileBy.ACCESSIBILITY_ID, "Activity").click()
self.driver.find_element(MobileBy.ACCESSIBILITY_ID, "Custom Title").click()
return CustomTitlePage(self.driver)
def other(self):
pass
\ No newline at end of file
class SearchPage:
def __init__(self,driver):
self.driver=driver
def search(self, prefill, appdata):
el4 = self.driver.find_element_by_id("io.appium.android.apis:id/txt_query_prefill")
el4.send_keys(prefill)
el5 = self.driver.find_element_by_id("io.appium.android.apis:id/txt_query_appdata")
el5.send_keys(appdata)
return self
def get_result(self):
return "456"
\ No newline at end of file
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
class TestDemo:
def setup(self):
caps = {}
caps["appPackage"] = "io.appium.android.apis"
caps["appActivity"] = ".ApiDemos"
caps["platformName"] = "android"
caps["ensureWebviewsHavePages"] = True
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
def test_app(self):
driver = self.driver
el1 = driver.find_element_by_accessibility_id("App")
el1.click()
el2 = driver.find_element_by_accessibility_id("Search")
el2.click()
el3 = driver.find_element_by_accessibility_id("Invoke Search")
el3.click()
el4 = driver.find_element_by_id("io.appium.android.apis:id/txt_query_prefill")
el4.send_keys("123")
el5 = driver.find_element_by_id("io.appium.android.apis:id/txt_query_appdata")
el5.send_keys("abc")
def teardown(self):
self.driver.quit()
import pytest
from page.app import App
class TestSearch:
def setup_class(self):
self.default = App().default()
def test_search(self):
res = self.default.invoke_search().search("456", "def").get_result()
assert res == "456"
def test_search2(self):
res = self.default.invoke_search().search("789", "def").get_result()
assert res == "789"
@pytest.mark.parametrize("title", [
"1",
"123",
# "abc",
# "_+-*"
# "",
# "1" * 10
])
def test_custom_title(self, title):
title_page = self.default.custom_title()
assert title_page.change_left_title(title) == title
self.default.back()
self.default.back()
self.default.back()
self.default.back()
def test_custom_right_title(self):
assert self.default.custom_title().change_right_title("456") == "456"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment