CukeTest Python API

The Python version of CukeTest's automation API, method definitions and usage are similar to the JavaScript version, so you can directly refer to the API introduction in the documentation; however, since the majority of the API is asynchronous, an introduction to Python's co-process writing method for calling asynchronous methods is needed.

Installation

Extract the zip package auto-0.0.0-[python_version]-64_[build_version].zip and you can use it. If you can't reference the auto module in your python code, you can add the extracted auto-0.0.0-[python_version] folder path to the module search path with sys.path.append().

Usage

Python
import asyncio # Loading Python Concurrent Library
from leanproAuto import Util # Loading the CukeTest Automation Library
# Define an automated operation method (asynchronous)
def launch_notepad(): 
    pid = Util.launchProcess("notepad.exe")
    asyncio.sleep(2)
    Util.stopProcess(pid)

# Call the asynchronous method with asyncio.run
if __name__ == "__main__":
    asyncio.run(launch_notepad())

The py code uses the Util library (auto.util), which corresponds to the Util library in JavaScript, see Util (common tool functions) for details. In addition to that, the following API libraries are provided.

Writing Tests

If you write tests with this API, you can do so with the help of the pytest library, which is described below.

Installing pytest dependencies

pip install pytest pytest-asyncio websocket-client greenlet pyee websockets

Creating Tests

Follow the pytest naming convention

Test scripts based on the pytest testing framework, whether adding new test classes, or new test methods, need to follow pytest's naming conventions to ensure that they are correctly identified as test classes/methods. The following is a brief description of the pytest naming convention.

  • The test file needs to be in the format test_*.py or *_test.py.
  • Test classes need to be in a format starting with Test.
  • Test methods need to be in a format starting with test (whether or not they are in a test class).

Add new test project

Create a new py file, the file name must be test_*.py or *_test.py. The content can start with the following template:

Python
import asyncio
import os
import config
from os import path
from leanproAuto import Screen, Mouse, Keyboard, Util

class Test_____:
    def test____(self): 
        ...

Run test

The pytest testing framework provides command line tools to run tests, with the following usage:

py -m pytest -k [Testing tasks] -s

For example, run all test methods whose method names contain the text windows.

py -m pytest -k windows -s

For example, to run all test methods whose method names do not contain the text qt.

py -m pytest -k "not qt" -s

Sample

A number of examples are provided in the Python package and can be found in the auto-0.0.0-[python_version]/test folder. These examples can be run quickly using the tool options provided by the pytest library.

For example, the auto-0.0.0-[python_version]/test/test_win.py file contains a number of scripts for automating Windows applications, and if you need to call the test_win_notepad() method in it - used to automate the Notepad application menu, you can run the following command.

cd auto-0.0.0-[python_version]
python -m pytest -k test_win_notepad -s

You can see that the method runs, opens Notepad, and then closes it via a menu action.

results matching ""

    No results matching ""