若要通过中间层访问 Appium 服务器,请配置 Python 的 HTTP 命令通道:

from appium import webdriver
from appium.webdriver.client_config import AppiumClientConfig
from selenium.webdriver.common.proxy import Proxy, ProxyType

route = Proxy()
route.proxy_type = ProxyType.MANUAL
route.http_proxy = 'http://proxy.example:8080'
route.ssl_proxy = 'http://proxy.example:8080'

config = AppiumClientConfig(
    remote_server_addr='https://appium.example',
    proxy=route,
)
driver = webdriver.Remote(
    options=device_options,
    client_config=config,
)

device_options 是应用现有的选项对象。保留其设备/浏览器能力,并通过现有测试生命周期管理 driver.quit。

AppiumClientConfig 继承 Selenium 的 ClientConfig。手动选择使用 http_proxy 指定 HTTP 服务器地址,使用 ssl_proxy 指定 HTTPS 地址。此处取值包含 URL scheme,因为它们配置的是 HTTP 连接管理器。对于可通过允许的公共路由访问的 Appium 端点,请从 HTTP 代理列表 中为这些取值选择一个 HTTP 候选。

在会话内部发送的代理能力要求远程环境转发自己的流量。它无法帮助 Python 提交更早的会话创建请求。需要时请单独配置那条路径。

请使用提供此公开接口的兼容 Appium/Selenium 组合。给已安装的 remote_connection 模块打补丁针对的是较旧的客户端方案,而不是这条配置路径。

相关文章