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

相关推荐
花酒锄作田12 小时前
Pydantic校验配置文件
python
hboot13 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python