App啓動參數如下(存放在Yaml文件中):
automationName: UiAutomator2
platformName: Android
platformVersion: 7
deviceName: Android Emulator
appPackage: com.ellabook
appActivity: com.ellabook.startup.StartActivity
noReset: False
unicodeKeyboard: True
# 將鍵盤給隱藏起來
resetKeyboard: True
其他信息:
Appium 1.15
模擬器: 雷電模擬器4.0.7
測試框架: pytest
conftest.py內容如下:
def basedriver(port=4723, **kwargs):
""" 根據設置的參數,啓動會話,並返回會話對象
:param port: 會話啓動端口號---int
:param kwargs: 啓動參數
:return: 會話對象
"""
yamls = YAML(typ='safe')
yaml_path = os.path.join(CAPS_PATH, "desire_caps.yaml")
fs = open(yaml_path, encoding='UTF-8')
desire_caps = yamls.load(fs)
if kwargs:
for key, value in kwargs.items():
desire_caps[key] = value
driver = webdriver.Remote("http://localhost:{}/wd/hub".format(port), desire_caps)
return driver
@pytest.fixture(scope="class")
def initdriver_first_start():
"""App首次啓動"""
driver = basedriver(noReset=False)
yield driver
driver.close()
測試用例py文件內容:
@pytest.mark.usefixtures("initdriver_first_start")
class TestAPPStart:
"""APP啓動頁測試:
是否進入啓動頁 、banner圖正常滑動、點擊"開始看書吧"進入登錄界面
"""
def test_0_into_start(self, initdriver_first_start):
"""APP首次啓動,啓動頁是否展示“開始閱讀吧”按鈕 """
driver = initdriver_first_start
AppStartPage(driver).check_read_book_is_exist()
def test_banner_left_slip(self, initdriver_first_start):
"""APP首次啓動,啓動頁廣告圖能夠向左滑"""
driver = initdriver_first_start
AppStartPage(driver).slide_start_banner("left") # App首次啓動,banner廣告圖正常切換
def test_banner_right_slip(self, initdriver_first_start):
"""APP首次啓動,啓動頁廣告圖能夠能夠向右滑"""
driver = initdriver_first_start
AppStartPage(driver).slide_start_banner("right") # App首次啓動,banner廣告圖正常切換
def test_click_button(self, initdriver_first_start):
"""APP首次啓動,點擊開始按鈕,查看是否進入登錄界面"""
driver = initdriver_first_start
AppStartPage(driver).click_start_read() # 點擊“開始閱讀” 按鈕
LoginPage(driver).check_into_login_idle() # 查看是否進入登錄界面
APP啓動頁測試 測試類(pytest/py.test方式)運行,此時用例執行完成後,在進行測試類的teardown時,卻報錯:
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - undefined