简体   繁体   中英

Screen recording of videos while running appium test in parallel (Need help in threading)

The cmd/commands are correct. I am using scrcpy to record the videos. But I need to figure out how to record videos of the Android devices while running my tests in parallel.

Currently, if I start the screen recording, it will not start to run the test in parallel. Cause it will try to wait for my screen recording method to finish first.

INFO: Recording started to mp4 file:

It does not go to the next line of my code and run the test.

But I want to do both concurrently (Recording what is happening on the devices while running the test scripts)

Start screen recording first

def start_screenrecording(udid):

    for o in udid: 
        sport = get_scrcpy_port()
        print("Starting scrcpy screen recording")
        cmd = "scrcpy --no-display " + "--serial " + o + " --record " + o + ".mp4 -p " + str(sport)  

Then start running test scripts in parallel

def run_tests(udid):
    threads=[]

    for idx, device in enumerate(udid):
        cmd = "robot --variable PLATFORM_VERSION:" + str(get_platform_version_of_android_phone(device)) + " --variable DEVICE_UDID:" + str(device) + " --variable APPIUM_PORT:" + str(appiumInstances[idx]) + " --variable DRIVER_PATH:" + driverPath + " --outputdir logs/" + device + "_" + get_model_of_android_phone(device)

        #Start parallel screen recording for all the devices from this point
        #Continue running the test scripts while screen recording is ongoing
        t = threading.Thread(target=run_command, args = (cmd,))
        t.daemon = True
        threads.append(t)

    for x in threads:
        x.start()
        sleep(3)

    for x in threads:
        x.join()

How we run the cmds

def run_command(cmd_array,os_name='posix'):
    p = subprocess.Popen(cmd_array,shell=True,cwd=os.getcwd())
    output,err = p.communicate()
    print('output=%s'%output)
    print('err=%s'%err)
    return output

Scrcpy - https://github.com/Genymobile/scrcpy

Removed the for loop from my question and screen recording starts recording smoothly while executing my test scripts on multiple devices.

def start_screenrecording(udid):
    for o in udid: 
        sport = get_scrcpy_port()
        print("Starting scrcpy screen recording") 

        cmd = "scrcpy --no-display " + "--serial " + o + " --record " + o + ".mp4 -p " + str(sport) 
        scrcpyInstances.append(sport)

        t = threading.Thread(target=run_command, args = (cmd,))
        t.daemon = True
        t.start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM