Macaca实践(基于web端)

作者: 海尔兄弟_ | 来源:发表于2016-09-18 15:31 被阅读1962次

Macaca

Macaca是阿里开源的一套完整的自动化测试解决方案。同时支持PC和移动端测试,支持的语言有JS,Java,Python。本文介绍PC端。

安装

1.安装node.js
2.安装管理工具CNPM
3.安装macaca

安装命令
cnpm i macaca-client -g
装完后查看版本
$ macaca -V
查看环境
$ macaca doctor

确保环境搭建成功。
4.安装macaca-cli

cnpm i macaca-cli -g 

5.安装webdriver-client

cnpm install webdriver-client

6.安装maraca-electron

cnpm install macaca-electron -g

7.安装 macaca-chrome

cnpm install macaca-chrome -g

8.安装 macaca python client

python3 install wd

使用官方实例

先去我是链接下载官方实例代码。官方的代码使用的是基于electron开发的Macaca驱动,之后我们使用chrome。
下载好之后,执行脚本。

maraca run -o ./log.html -d ./macaca-test/macaca-desktop-sample.js

如果要使用chrome,修改脚本。



再执行脚本即可。

使用Python来编写脚本

Macaca只支持Python3.4以上版本,官方api
启动Macaca服务

macaca server --verbose

看到以下输出后,即为成功。



下面编写python脚本,脚本基于python的单元测试框架unites,不熟悉的自行Google。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__author__ = 'LiBin'
__mtime__ = '16/9/18'
              ┏┓   ┏┓
             ┏┛┻━━━┛┻┓
             ┃   ☃    ┃
             ┃ ┳┛  ┗┳  ┃
             ┃    ┻    ┃
             ┗━┓      ┏━┛
              ┃       ┗━━━┓
              ┃  神兽保佑  ┣┓
              ┃ 永无BUG! ┏┛
              ┗┓┓┏━┳┓┏┛
               ┃┫┫ ┃┫┫
               ┗┻┛ ┗┻┛
"""
import unittest
from macaca import WebDriver
from time import sleep

desired_caps = {
    'platformName': 'Desktop',
    'browserName': 'Chrome',
}

server_url = {
    'hostname': '10.1.1.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.baidu.com')
        self.assertEqual(self.driver.title, '百度一下,你就知道')

    def test_search_macaca(self):
        self.driver.element_by_id('kw').send_keys('macaca')
        self.driver.element_by_id('su').click()
        sleep(2)
        title = self.driver.title
        self.assertTrue('macaca', title)

if __name__ == '__main__':
    unittest.main()

可以从脚本看出,macaca和selenium的api非常的相似,熟悉selenium的可以很快上手。

吐槽一下测试报告


macaca自带的这个报告真的是有些low。

相关文章

  • Macaca实践(基于web端)

    Macaca Macaca是阿里开源的一套完整的自动化测试解决方案。同时支持PC和移动端测试,支持的语言有JS,J...

  • UI 自动化框架调研总结

    导语 前面写了两篇文章介绍了个人基于Macaca在UI自动化上的实践心得,那我们为什么会选择了Macaca呢,这篇...

  • 自动化测试Macaca

    Macaca简介: Macaca是由阿里巴巴公司开发的一套自动化解决方案,适用于PC端和移动端。 Macaca P...

  • macaca从入门到放弃爱之初体验

    macaca是阿里巴巴用nodejs写的一个自动化测试框架 兼顾移动端和web端测试 它有三个版本,nodejs,...

  • PostgreSQL 客户端程序 pgweb (五)

    基于web的客户端程序pgweb pgweb是用go语言写的,基于web的PostgreSQL客户端程序。用它可以...

  • HTTP学习笔记

    Web 页面的实现 Web 基于 HTTP 协议通信 客户端(Client)的 Web 浏览器从 Web 服务器端...

  • 常用命令

    常用命令 安装 npm i macaca-cl -g 服务端 macaca server (正常模式) macac...

  • 软件测试面试题目(一)

    1.APP测试和web测试有哪些差异点 1)兼容性测试 web端是基于浏览器,app端是基于手机。 则...

  • 前后端的身份认证

    Web 开发模式 目前主流的 Web 开发模式有两种,分别是: 基于服务端渲染的传统 Web 开发模式 基于前后端...

  • (一)什么是macaca?他能做什么?

    1.Macaca是针对多平台的开源自动化解决方案。支出web,ios,android的自动化测试 2.Macaca...

网友评论

  • tracyshmily:请教一下,执行的时候报错
    E
    ======================================================================
    ERROR: setUpClass (__main__.MacacaTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
    File "D:\macaca\macaca-test\macaca-desktop-sample2.test.py", line 37, in setUpClass
    cls.driver.init()
    File "D:\Python\lib\site-packages\macaca\util.py", line 145, in fluent_interface
    ret = func(instance, *args, **kwargs)
    File "D:\Python\lib\site-packages\macaca\webdriver.py", line 148, in init
    }, False)
    File "D:\Python\lib\site-packages\macaca\webdriver.py", line 66, in _execute
    res = self.remote_invoker.execute(command, data)
    File "D:\Python\lib\site-packages\macaca\remote_invoker.py", line 110, in execute
    return self._request(method, url, body)
    File "D:\Python\lib\site-packages\macaca\remote_invoker.py", line 144, in _request
    res = s.send(prepped, timeout=self._timeout or None)
    File "D:\Python\lib\site-packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
    File "D:\Python\lib\site-packages\requests\adapters.py", line 473, in send
    raise ConnectionError(err, request=request)
    ConnectionError: ('Connection aborted.', BadStatusLine("''",))

    ----------------------------------------------------------------------
    Ran 0 tests in 120.013s

    FAILED (errors=1)
    海尔兄弟_:过了这么久,macaca应该更新了。最近忙好久没弄这个了。
  • 5730306e0382:为什么链接打开都是404啊
    海尔兄弟_:不好意思,macaca更新过快。链接很多都已失效,最近比较忙,暂时没时间更新。
    你阔以找找别的教程先玩着=。=
  • 5730306e0382:安装python本地端安装不成功是怎么回事啊
  • sunshineliu:作者已经用这个方案测试过么,稳定性如何?
    海尔兄弟_:@sunshineliu 稳定性取决于你的脚本,和框架无关。

本文标题:Macaca实践(基于web端)

本文链接:https://www.haomeiwen.com/subject/gaxgettx.html