DEV Community

远古大钟
远古大钟

Posted on • Edited on

Use TestCat to automatically control your phone via javascript

Today I will talk about how to use TestCat to automatically control your phone via javascript.

Preparation

  1. Install TestCat from github.
  2. Prepare an Android phone and turn on the Android debugging mode. (How to turn on the Android debugging mode)
  3. Open the TestCat, and connect the mobile phone and the computer PC through the data cable. Congrats, you're ready to test your cat!

Getting Started

1. Preview

Take a simple test case testing whack-a-mole as an introductory example.(TestCat supports English and Chinese)

Test cat and whack-a-mole test case

1. New project

Click the 'File' button in the upper left corner, create a new project as shown below, and follow the prompts

New project

2. Partial screenshots

  1. We pass the screenshot button on the upper right of the test cat device window

Screenshot button

  1. Take pictures of the three moles on the left, middle and right

Screenshot

  1. Name and save it, and the corresponding image will be generated in the image directory

Screenshot

Screenshot

3. Coding

Let the TestCat continuously find out whether the mole appears on the screen of the mobile phone, and if it does, click on the location of the hamster and use the cat.tap('xxx.png') interface. This interface will detect whether the corresponding picture appears on the current screen, if it appears, click it, otherwise nothing happens.

Double-click index.js in the project, add the following code, you can continuously test the whack-a-mole

while(true){
    cat.tap("Left mole.png")
    cat.tap("Middle mole.png")
    cat.tap("Right mole.png")
}
Enter fullscreen mode Exit fullscreen mode


`

The above code constantly checks whether the current display content of the mobile phone has a picture related to the mole, and if so, click the center point of the picture.

congratulations! ! ! You have already fully started with the test cat~

More features

The TestCat is more than this. For more info, please check the API

Top comments (0)