Python Support
CukeTest supports the development of automation scripts using Python scripts. cukeTest provides a set of automation libraries for Python language calls and supports recording, if you prefer to use Python language for development compared to JavaScript, you can follow the steps below to start Python development automation.
Basic Information
CukeTest has a built-in interpreter for Python 3.8 (64-bit) to run Python projects and Python scripts in CukeTest.
Verify that your version supports Python development?
Currently CukeTest version 1.7.9 and above supports Python for development.
CukeTest Lite version does not support Python for now, please contact us for a trial if you need it.
Python Support Coverage
Python supports features that are almost identical to JavaScript, including capabilities such as
- Automation APIs: Support for Qt and Windows automation, as well as APIs for keyboard and mouse operation automation.
- Recording capabilities: Support for Qt and Windows automation for recording generation, the
- Project management: Based on PyTest test framework for automation test development; also compatible with existing PyTest projects.
- Run Reports: Provide simple HTML reports of project runs.
Enable Python
If you need to switch to the Python language for development, switch to the Python language to.
- If you are opening CukeTest for the first time, then in the initial settings, just switch the script language to python.
- If you have used CukeTest in the past, then select menu "File" -> "Settings" -> "General" and switch the script language to python. python**.
- If you already have the CukeTest project open, then you can switch by clicking on the word "JavaScript" in the bottom right corner of the status bar.
Create your first Python automation project
Create an empty project
After enable-python, click "New Project" to create an empty Python project according to the template.
Start with sample
After enable-python, open all Python samples in Teaching Samples on the welcome page or menu "Help" -> "Samples", and choose the one that suits your needs according to the introduction. Choose the sample that suits your needs and create it.
Python API
Python currently offers the following automation libraries.
- Windows Automation Module
WinAuto
: Module for completing Windows automation operations. Click to see the detailed documentation of Windows Automation API. The call is shaped like.Pythonfrom leanproAuto import WinAuto: model = WinAuto.loadModel("model1.tmodel") model.getWindow("Window").activate()
- Cross-platform Qt Automation Module
QtAuto
: Module for completing cross-platform Qt automation operations. Click to view the detailed documentation of Cross-platform Qt Automation API.Mouse Automation ModulePythonfrom leanproAuto import QtAuto: model = QtAuto.loadModel("model1.tmodel") QtAuto.launchQtProcessAsync() model.getWindow("Window").activate()
Mouse
: Module for completing mouse operations, such as mouse click, move, drag and drop, etc. Click to view detailed documentation of mouse automation API.Pythonfrom leanproAuto import Mouse Mouse.moveSmooth(1920,1080) Mouse.click(2)
- Keyboard Automation Module
Keyboard
: Module for completing keyboard operations, such as typing, pressing key combinations and other operations. Click to view the detailed documentation of Keyboard Automation API.Pythonfrom leanproAuto import Keyboard Keyboard.keyDown("control") Keyboard.keyTap("a") Keyboard.keyUp("control")
- Screen Automation Module
Screen
: Module for completing screen operations, such as taking screenshots, getting screen information and other operations. Click to view the detailed documentation of Screen Automation API.Pythonfrom leanproAuto import Screen Screen.capture()
- Common function module
Util
: A module that holds common functions used in automation testing, such as starting applications, delay functions, etc. Click to view the detailed documentation of Common Functions API.Pythonfrom leanproAuto import Util Util.launchProcess("notepad.exe") Util.delay()
- Run Settings module
RunSettingss
: module for setting some running state, such as setting API call interval, etc. Click to see detailed documentation of run settings.Pythonfrom leanproAuto import RunSettings RunSettings.set({"defaultTimeout": 50000, "slowMo": 1000})
Using Python Automation API
Introducing the Python Automation API
Due to the syntax differences between Python and JavaScript, the way to introduce automation API libraries is different. Here with the use of Python's with
keyword can make the code cleaner:.
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, CukeTest also supports generating Python automation scripts in the same way. After enable-Python, the following methods generate Python automation scripts.
Generate from recording
Click the "Record" drop-down button in the main interface, configure the recording options or directly select the technology type to start recording, you can start recording and generating Python automation scripts, see Recording Options for details.
Generated from Model Manager
In desktop automation, you can also generate and run code from the model manager.