macaca搭建
对于新鲜的事务总是那么好奇,在自动化的过程中,有幸了解到macaca,记录下安装过程,具体介绍请移步官网:https://github.com/macacajs/
python版本参考:https://testerhome.com/topics/7898 详细教程
第一步:安装node.js 下载地址:https://nodejs.org/en/ 我本人下载的是8.11.1,一键安装,一路next就好,安装好之后添加环境变量,以便备用
第二步:切换淘宝源 npm install -g cnpm --registry=https://registry.npm.taobao.org 国内源很慢,切换过程耐心等待
安装成功:
第三步:通过淘宝源安装 macaca-cli cnpm i macaca-cli -g
第四步:安装 webdriver-client cnpm install webdriver-client
第五步:安装 macaca-electron cnpm install macaca-electron -g
第六步:安装 macaca-chrome cnpm install macaca-chrome -g
第七步:安装python API (这一步我直接通过pip安装的,应该也是没毛病的)
python3 -m pip install wd
第八步:安装谷歌驱动 macaca-chromedriver cnpm install macaca-chromedriver -g
第九步:安装Android驱动 cnpm install macaca-android -g (八,九,十可以根据需求安装)
第十步:安装iOS驱动 cnpm i macaca-ios -g
启动:macaca server --verbose 【加--verbose,打印详细日志】
- python tests/macaca-desktop-sample.test.py 【运行测试】
常用命令:
服务端
- macaca server (正常模式)
- macaca server -p 3456 (设置端口)
- macaca server -p 3456 & (设置端口后台运行)
- macaca server --verbose(输出详细日志)
测试
- macaca run (运行当前目录用例集)
- macaca run -d ./test (运行指定目录下用例集)
检查
- macaca doctor (环境检查)
丢一个官方用法
import unittest
from macaca import WebDriver desired_caps = {
'platformName': 'Desktop', // iOS, Android, Desktop
'browserName': 'Chrome' // Chrome, Electron
'app': 'path/to/app' // Only for mobile
} server_url = {
'hostname': '127.0.0.1',
'port': 3456
} class MacacaTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = WebDriver(desired_caps, server_url)
cls.driver.init() @classmethod
def tearDownClass(cls):
cls.driver.quit() def test_get_url(self):
self.driver.get('https://www.google.com')
self.assertEqual(self.driver.title, 'Google') def test_search_macaca(self):
self.driver \
.element_by_id("lst-ib") \
.send_keys("macaca") \
self.driver \
.element_by_name("btnK") \
.click()
html = self.driver.source
self.assertTrue('macaca' in html) if __name__ == '__main__':
unittest.main()
最新文章
- 【BZOJ-2555】SubString 后缀自动机 + LinkCutTree
- PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
- 配置webdriver环境
- Ubuntu PostgreSQL安装和配置
- 昨天晚上也弄不清楚是自己密码被盗了还是由于ip冲突
- ios 代码截屏模糊问题解决办法
- git for windows+TortoiseGit客户端的使用
- Webform——内嵌word编辑器
- 检查REDO日志相关信息并生成HTML文件的脚本
- Two-phase Termination模式
- 关于XML(一)。
- ui原则
- docker !veth
- Uri API
- ORA-01036: 非法的变量名/编号 解决方案
- HTML5新结构标签和移动端页面布局
- 洛谷 P3379 【模板】最近公共祖先(LCA)Tarjan离线
- Python 多进程基本语法
- Problem A: 平面上的点——Point类 (I)
- 使用python requests模块搭建http load压测环境