
1. 前言
2. 如何使用AirtestIDE驱动Firefox浏览器
1)基础知识
2)下载GeckoDriver(注意选择对应操作系统的版本)

3)解压获得geckodriver.exe
4)给geckodriver.exe设置为系统环境变量


5)在AirtestIDE驱动Firefox做简单的自动化测试

# -*- encoding=utf8 -*-
from airtest.core.api import *
from airtest.cli.parser import cli_setup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebFirefox
import time
#创建Chrome浏览器驱动实例
browser = WebFirefox(firefox_binary=r"C:\Program Files\MozillaFirefox\firefox.exe")
# 访问网页
browser.get('https://www.baidu.com')
#打印页面标题
print(browser.title)
#休眠3秒
time.sleep(3)
#关闭浏览器
browser.quit()
① 版本说明
② 启动报错
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
WebFirefox
时,将firefox.exe可执行文件路径当做参数传递给
WebFirefox
,之后就可以正常运行了。
3. 如何脱离AirtestIDE驱动Firefox(vscode为例)
1)前置条件:安装VScode、配置python环境
2)python配置airtest、airtest-selenium
pip install airtest
pip install airtest-selenium
小编的pip版本太旧了,还需更新pip,使用命令:python -m pip install --upgrade pip

3)在cmd控制台测试环境是否配置成功

4)测试脚本demo,解决报错

① No module named pynput
pynput
库,直接
pip install
安装上即可。
② TypeError: init() got an unexpected keyword argument......
proxy.py
文件;
argument 'timeout'
报错的话删掉
timeout=timeout
的参数;
argument 'firefox_options'
报错的话删掉
firefox_opt
ions=firefox_options
的参数。
5)脱离AirtestIDE驱动Firefox

4. 小结



本文分享自微信公众号 - AirtestProject(AirtestProject)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。