Talking about Macaca Automated Testing

1. Introduction to Macaca

Macaca is a set of testing solutions for user-end software, providing automation drivers, peripheral tools, and integrated solutions, aiming to solve the problems of testing, automation, and performance on the terminal.

 



Macaca has the following characteristics:

①Multi-terminal support: Macaca supports the mainstream mobile technology platforms iOS, Android, and the hybrid runtime Webview of the two platforms, as well as the previous desktop browsers.

②Standardization: Macaca provides a standardized driver layer, which eliminates the differences in the test technology stacks of various technology platforms.


③Multi-language stack support: Macaca provides three mainstream language stacks, Node.js, Java, and Python, so that engineers and their teams can choose the appropriate development language. Since Macaca's tool chain is based on Node.js, various factors lead to relatively more support and peripheral tools on the Node.js side.

④Integration and integration: Macaca provides a variety of continuous integration solutions and functional modules, which are easy to integrate into all aspects of R&D and testing.

 

2. Macaca installation

Step 1: Install Node.js.

     What is Node.js? It is a Javascript runtime environment that enables JavaScript to run away from the browser, thus saving the time of writing the background.

   Why install Node.js? Because macaca is developed with node.js tools, its development platform needs to be installed.    

 

Step 2: Install the latest JDK.

    What is JDK (Java Development Kit)? JDK is a Java language development kit, which includes the Java runtime environment, Java tools and Java-based class libraries.

 

 Why install JDK? When testing Android mobile terminals and writing Android programs, not only Android APIs are called, but also some libraries that come with Java. Therefore, JDK must be installed.

 

Step 3: Install Macaca.

    Open a command window and type : npm i -g macaca-cli

  If you see a cute monkey, congratulations on your successful installation! Reinstalling will overwrite the update .  

  

Step 4: Install the macaca-electron driver (different drivers adapt to the support of different platforms).

     Command window input : npm install macaca-electron -g

   npm is easy to be blocked, it is recommended to use Taobao's mirror cnpm: npm install -g cnpm --registry=https://registry.npm.taobao.org


   Remarks : macaca-electron is a Macaca driver developed based on Electron, which is one of the Macaca drivers.

 

Step 5: Check the macaca environment.

     Command window input: macaca doctor ok! Macaca environment installed successfully under windows system!

 

Three, Macaca simple automation script

①Create a new Macaca project directory, macaca-client will run all files with .test.js suffix in the macaca-test folder by default.


②Configure your package.json file:

package.json : mainly used to configure dependent nodejs modules;

repository: used to indicate where the code is stored;

dependencies: are the modules that the configuration depends on, ^version is compatible with the current version;

devDependencies:是用来配置开发环境下依赖的模块。

 



         wd = require('macaca-wd');

    // 引入官方webdriver client 包

 

let driver = wd.promiseChainRemote({

            host: 'localhost',

            port: process.env.MACACA_SERVER_PORT || 3456

        })

    // 定义webdriver client 要链接的服务端 host 和 port。

 



describe()函数是测试描述,每一个describe语句都可以看作是一个测试模块,它只是起着划分各个模块部分的作用,describe语句的第一个参数就是对该模块的描述。

 

it()是一个测试用例,在一个describe块的内部可以执行对个测试用例(it块)。


it语句的回调函数中可以通过书写should.js断言库中的语句进行测试。首先为了使用should.js的断言库,在代码的开头部分必须引入should模块。should语法跟我们日常用的语法几乎一模一样, 非常易于使用。

 



常用函数

get(url) :在当前浏览器中跳转到指定链接

getProperty(name) :查询元素CSS属性的值

elementById(value) :通过元素ID找到该元素

elementByCss(value):通过CSS属性找到该元素

elementByCssSelector(value):通过CSS选择器找到该元素

sendKeys(keys):向当前活动窗口发送指定内容

should.containEql(otherValue):判断值是否包含指定内容

then():异步执行,就是当.then()前的方法执行完后再执行then()内部的程序

 

设置生成报告的路径和文件名

//报告文件路径,默认为mochawesome-report

$ export MOCHAWESOME_REPORTDIR=fileDir

 

//报告文件名,以自己的组件命名,xxx-report

$ export MOCHAWESOME_REPORTFILENAME=filename

 

执行macaca

test目录下 执行 macaca run -d ./macaca-test/xxx.test.js --reporter mochawesom

 



 

四、Macaca其他应用


录制回放器:支持 Android, iOS, PC 端浏览器的录制回放。

计算机视觉:Macaca 提供计算机视觉解决方案,用来处理 View 体系之外的问题。如识别测试过程中的截图、测试游戏类产品等。

浏览器测试:对桌面端浏览器做兼容性测试。

获取 Android 应用的性能:在测试流程中,加入一些性能采集,例如网络、cpu、线程情况、内存等等

 

五、门户及资料

Macaca官网:https://macacajs.github.io/

Macaca nodejs版本API:https://macacajs.github.io/macaca-wd/

Macaca 样例集锦:https://github.com/macaca-sample

Macaca专区地址:https://testerhome.com/topics/node68

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324709465&siteId=291194637