Python Support
CukeTest supports developing automation scripts using Python. CukeTest provides a set of automation libraries for Python and supports recording. If you prefer using Python over JavaScript for development, follow the steps below to start Python automation development.
Basic Information
CukeTest has a built-in Python 3.8 (64-bit) interpreter for running Python projects and scripts in CukeTest.
Python Support Scope
Python supports features that are nearly identical to JavaScript, including the following capabilities:
- Automation APIs: Supports Qt and Windows automation, as well as keyboard and mouse operation automation APIs.
- Recording capabilities: Supports recording generation for Qt and Windows automation.
- Project management: Automation test development based on the PyTest testing framework; also compatible with existing PyTest projects.
- Run Reports: Provides simple HTML reports of project runs.
Enable Python
If you need to switch to Python for development, simply switch the script language to Python:
- If you are opening CukeTest for the first time, in the initial settings, switch the script language to python.
- If you have used CukeTest before, select menu "File" -> "Settings" -> "General" and switch the script language to python.
- If you already have a CukeTest project open, you can switch by clicking on "JavaScript" in the bottom right corner of the status bar.
Create Your First Python Automation Project
Create an Empty Project
After enabling Python, click "New Project" to create an empty Python project from the template.
Start with Samples
After enabling Python, access all Python samples from Teaching Samples on the welcome page or via menu "Help" -> "Samples". Choose the sample that suits your needs and create it.
Python API
Python currently provides the following automation libraries:
Windows Automation Module
WinAuto: Module for Windows automation operations. See the detailed Windows Automation API documentation. Usage example:Pythonfrom leanproAuto import WinAuto model = WinAuto.loadModel("model1.tmodel") model.getWindow("Window").activate()Cross-platform Qt Automation Module
QtAuto: Module for cross-platform Qt automation operations. See the detailed Cross-platform Qt Automation API documentation.Pythonfrom leanproAuto import QtAuto model = QtAuto.loadModel("model1.tmodel") QtAuto.launchQtProcessAsync() model.getWindow("Window").activate()Mouse Automation Module
Mouse: Module for mouse operations such as clicking, moving, and dragging. See the detailed Mouse Automation API documentation.Pythonfrom leanproAuto import Mouse Mouse.moveSmooth(1920,1080) Mouse.click(2)Keyboard Automation Module
Keyboard: Module for keyboard operations such as typing and pressing key combinations. See the detailed Keyboard Automation API documentation.Pythonfrom leanproAuto import Keyboard Keyboard.keyDown("control") Keyboard.keyTap("a") Keyboard.keyUp("control")Screen Automation Module
Screen: Module for screen operations such as taking screenshots and getting screen information. See the detailed Screen Automation API documentation.Pythonfrom leanproAuto import Screen Screen.capture()Common Functions Module
Util: Module containing common functions for automation testing, such as launching applications and delay functions. See the detailed Common Functions API documentation.Pythonfrom leanproAuto import Util Util.launchProcess("notepad.exe") Util.delay()Run Settings Module
RunSettings: Module for setting runtime states, such as API call intervals. See the detailed Run Settings documentation.The above statement sets the automation API timeout to 10 seconds and the minimum API operation interval to 1 second.Pythonfrom leanproAuto import RunSettings RunSettings.set({"defaultTimeout": 10000, "slowMo": 1000})
Using Python Automation API
Importing the Python Automation API
Due to syntax differences between Python and JavaScript, the way to import automation API libraries differs.
from leanproAuto import WinAuto, QtAuto, Mouse, Keyboard, Screen, Util, RunSettings
model = WinAuto.loadModel("model1.tmodel")
modelQt = QtAuto.loadModel("model1.tmodel")
####################
### Your automatic code ###
####################const { WinAuto } = require("leanpro.win")
let model = WinAuto.loadModel("model1.tmodel")
const { QtAuto } = require("leanpro.qt")
let modelQt = QtAuto.loadModel("model1.tmodel")
const {Mouse, Keyboard, Screen, Util, RunSettings}
(async () => {
/*
* Your automatic code
*/
})()You can toggle the top language tab to see how the equivalent JavaScript language is introduced into the Automation API library.
Generate Python Automation Scripts
Similar to generating JavaScript scripts, CukeTest also supports generating Python automation scripts. After enabling Python, the following methods will generate Python automation scripts.
Generate from Recording
Click the "Record" button's drop-down menu in the main interface, configure recording options or directly select the technology type to start recording. You can then begin recording and generating Python automation scripts. For details, see Recording Interface.
Generate from Model Manager
In desktop automation, you can also generate and run code from the Model Manager.