准备
自动化测试用例
from appium import webdriver
import pytest
class TestDemo:
def setup(self):
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "hogwarts"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = True
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
self.driver.implicitly_wait(10)
def test_demo(self):
el3 = self.driver.find_element_by_id("com.xueqiu.android:id/home_search")
el3.click()
el4 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
el4.send_keys("alibaba")
el5 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.TextView[1]")
el5.click()
el6 = self.driver.find_element_by_id("com.xueqiu.android:id/current_price")
el6.click()
def teardown(self):
self.driver.quit()
Page Object 用例
from page.app import App
class TestDemo:
#todo: use setup_class
def setup(self):
self.search_page= App.start().to_search_page()
def test_demo(self):
assert self.search_page.search("xiaomi").get_current_price() > 6
#todo: 参数化
def test_search_alibaba(self):
assert self.search_page.search("alibaba").get_current_price() > 100
def teardown(self):
App.quit()