我正在使用 Appium Android,但我不断收到此错误消息。
E AttributeError:“WebDriver”对象没有属性“launch_app”
close() 也会出现同样的问题 ** 下面是我的conftest.py文件**
import pytest
import allure
from allure_commons.types import AttachmentType
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.android import UiAutomator2Options
appium_server = "http://localhost:4723/wd/hub"
desired_cap = {
# Emulator - Android
"deviceName": "Nexus 4 API 30",
"platformName": "Android",
"platformVersion": "11.0",
"udid": "emulator-5554",
"appPackage": "com.epf.mip.uat",
"appActivity": "com.epf.mip.uat.MainActivity"
}
# Converts capabilities to AppiumOptions instance
capabilities_options = UiAutomator2Options().load_capabilities(desired_cap)
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
return rep
@pytest.fixture()
def appium_android_driver(request):
print("Initializing Appium Android Driver")
driver = webdriver.Remote(command_executor=appium_server, options=capabilities_options)
yield driver
if request.node.rep_call.failed:
allure.attach(driver.get_screenshot_as_png(), name="Screen Before Error", attachment_type=AttachmentType.PNG)
driver.quit()
以下是我的测试代码:
def __init__(self, appium_android_driver):
self.driver = appium_android_driver
def launching_iAkaun_Application(driver):
driver.launch_app()
.
.
主要代码如下: 导入pytest 从 appium.webdriver.appium_service 导入 AppiumService appium_service = AppiumService()
@pytest.mark.usefixtures("appium_android_driver")
class TestSuite_EPF_Android_App:
def test_initialAppLaunch(self, appium_android_driver):
launching_iAkaun_Application(self.driver)
我正在使用 Selenium 4.14.0、pytest 7.4.3、Appium Python 客户端 3.1.0
我需要 launch_app 来关闭和重新打开驱动程序。这样我就可以从 excel 调用测试用例。
Appium v3 没有
launch_app()
方法。您可以在PyPI页面上看到以下消息:
从 v2 到 v3 的快速迁移指南
launch_app
、close_app
和reset
方法:请参考https://github.com/appium/appium/issues/15807所以我建议你查看链接的 GitHub 页面,但它看起来很长而且对我来说不清楚,所以改为尝试 this SO Q&A。