Appium如何自动判断浏览器驱动

问题:有的测试机chrome是这个版本,有的是另一个版本,怎么能让自动判断去跑呢??

解决办法:使用appium的chromedriverExecutableDir和chromedriverChromeMappingFile

切忌使用chromedriverExecutableDir和chromedriverChromeMappingFile时,一定不要再加chromedriverExecutable

具体appium的caps有哪些可以参考:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

第一步:

python代码(复制以后不要忘记改路径为你自己的):

import pytest

from appium import webdriver

from appium.webdriver.common.mobileby import MobileBy

from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait

from selenium.webdriver.support import expected_conditions

class TestAppiumBrowser:

def setup(self):

"""

初始化driver

:return:

"""

caps = {}

caps['platformName'] = 'android'

caps['platformVersion'] = '6.0'

caps['deviceName'] = 'emulator-5554'

caps['browserName'] = 'Browser'

caps['unicodeKeyBoard'] = 'true'

caps['resetKeyBoard'] = 'true'
# 切忌使用chromedriverExecutableDir和chromedriverChromeMappingFile时,一定不要再加chromedriverExecutable
caps['chromedriverExecutableDir'] = '/放置你的那一堆chromedriver的路径/chromedriver/'
caps['chromedriverChromeMappingFile'] = '/mapping.json文件的路径/mapping.json'

self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)

self.driver.implicitly_wait(10)

@pytest.mark.parametrize('search_value',["appium","软件测试","selenium"])

def test_browser(self, search_value):

"""

测试输入不同的关键字(使用pytest的关键字驱动),验证搜索结果条目>1条

:param search_value:

:return:

"""

打开 http://m.baidu.com

self.driver.get("http://m.baidu.com")

百度搜索框的位置:id=index-kw

search_input_locator = (By.ID,'index-kw')

百度一下按钮的位置:id=index-bn(这里使用的MobileBy其实继承了By,用法一样,扩展一下用例的技能覆盖点)

search_click_locator = (MobileBy.ID,'index-bn')

显示等待,等待直到搜索输入框出现

WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located(search_input_locator))

输入框输入参数

self.driver.find_element(*search_input_locator).send_keys(search_value)

点击【百度一下】

self.driver.find_element(*search_click_locator).click()

获取当前搜索结果页的总条目

result_elements = self.driver.find_elements(By.CSS_SELECTOR,'.c-gap-bottom-small')

断言条目数大于1

assert len(result_elements) > 1

def teardown(self):

"""

最终退出driver

:return:

"""

self.driver.quit()

第二步:创建mapping.json文件,内容举例如下:

{

"2.24": "52.0.2743",

"2.7": "57.0.2987.110"

}

可以看看chromedriver的文件夹:

很简单,就是把各种chromedriver放进来,名字随便起,appium回自动根据mapping里配置的来取对应版本的chromedriver

相关推荐
IVEN_12 小时前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang14 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮14 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling14 小时前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮17 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽17 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健1 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽2 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers