This is the 21st day of my participation in the August More Text Challenge

Netease Cloud Music for Windows with Airtest (1)

3. Preparation of test cases

In this experiment, a set of successful login cases and a set of failed login cases are designed for the netease cloud music login, which are stored in logintest. TXT.

13270976346,tjm981130, 13270976346,tjm971130,

4. Write the Airtest script

The test script is as follows:


# -*- encoding=utf8 -*-
__author__ = "admin"

from airtest.core.api import *

auto_setup(__file__)

# Search music case

Read the test case
with open("D:\\Airtest_Test\\loginTest.txt",encoding='utf-8') as f:
    content=f.readlines()
data_list=[]
for line in content:
    data_list.append([str(line.split(",") [0]),str(line.split(",") [1]])# login
touch(Template(r"tpl1608983218414.png", record_pos=(0.299, -0.266), resolution=(1920.1080)))

touch(Template(r"tpl1609035178281.png", record_pos=(-0.001.0.093), resolution=(1920.1080)))


sleep(1)
touch(Template(r"tpl1608981293166.png", record_pos=(-0.072.0.104), resolution=(1920.1080)))
def input_pwd(index) :
    touch(Template(r"tpl1608981390693.png", record_pos=(0.022, -0.036), resolution=(1920.1080)))
    accountstr=data_list[index][0]
    print(accountstr)
    text(str(accountstr))
    sleep(1)
    touch(Template(r"tpl1608981404680.png", record_pos=(-0.024, -0.017), resolution=(1920.1080)))
    password=data_list[index][1]
    print(password)
    text(str(password))
    sleep(1)
    touch(Template(r"tpl1608981588454.png", record_pos=(0.003.0.025), resolution=(1920.1080)))
for index in range(0.2) :if(exists(Template(r"tpl1608983376213.png", record_pos=(-0.265, -0.065), resolution=(1920.1080)))):
        touch(Template(r"tpl1608983415046.png", record_pos=(-0.282, -0.106), resolution=(1920.1080)))
        keyevent("^a")
        keyevent("{DEL}")
        touch(Template(r"tpl1608984487238.png", record_pos=(-0.043, -0.016), resolution=(1920.1080)))
        keyevent("^a")
        keyevent("{DEL}")

    input_pwd(index)

# Search for music

sleep(2)
touch(Template(r"tpl1608982011365.png", record_pos=(-0.305, -0.266), resolution=(1920.1080)))

text("Jiangnan")
#touch(Template(r"tpl1608982102725.png", record_pos=(-0.326, -0.236), resolution=(1920, 1080)))
# enter to search
keyevent("{ENTER}")
sleep(1)
touch(Template(r"tpl1609040382463.png", record_pos=(-0.237, -0.106), resolution=(1920.1080)))


Get the window for the current connection
dev = device()
# Take the mouse and simulate the right click operation of the mouse
dev.mouse.right_click( (504.336))
sleep(3)

Add the song to the specified playlist
keyevent("^s")
touch(Template(r"tpl1609042019881.png", record_pos=(-0.059.0.046), resolution=(1920.1080)))
sleep(3)

# Go to the playlist to see if the song has been added successfully and play the playlist
touch(Template(r"tpl1609040760016.png", record_pos=(-0.454.0.052), resolution=(1920.1080)))

touch(Template(r"tpl1609043299145.png", record_pos=(-0.245, -0.184), resolution=(1920.1080)))
Copy the code

Notes for scripting:

  • inkeyevent()Do not use in{}The characters in the box are entered into the input box of the Windows window as strings to be entered.
  • Sleep () is often used to give the server response time.
  • Emulated keyboard and mouse operations on Windows are somewhat different from those on Android. See the official Windows PLATFORM API documentation for details.