Skip to content

FletTestApp

FletTestApp #

Flet app test controller coordinates running a Python-based Flet app alongside a Flutter integration test.

This class launches the Python Flet app, starts the Flutter test process, and facilitates programmatic interaction with the app's controls for automated UI testing.

PARAMETER DESCRIPTION
flutter_app_dir

Path to the Flutter app directory containing integration tests.

TYPE: PathLike

flet_app_main

A callable or coroutine function representing the main entry point of the Flet app under test. This will be invoked with an ft.Page instance when the app starts.

TYPE: Any DEFAULT: None

assets_dir

Path to the directory containing static assets for the Flet app. Defaults to "assets" if not provided.

TYPE: PathLike | None DEFAULT: None

test_path

Path to the Python test file. Used to determine the location for golden screenshot comparisons.

TYPE: str | None DEFAULT: None

tcp_port

TCP port to run the Flet server on. If not specified, a free port is automatically selected.

TYPE: int | None DEFAULT: None

test_platform

Target platform for the Flutter integration test (e.g., "windows", "linux", "macos", "android", "ios"). Env override: FLET_TEST_PLATFORM.

TYPE: str | None DEFAULT: None

test_device

Target device ID or name for the Flutter integration test. Env override: FLET_TEST_DEVICE.

TYPE: str | None DEFAULT: None

capture_golden_screenshots

If True, screenshots taken during tests are stored as golden reference images. Env override: FLET_TEST_GOLDEN=1.

TYPE: bool DEFAULT: False

screenshots_pixel_ratio

Device pixel ratio to use when capturing screenshots. Env override: FLET_TEST_SCREENSHOTS_PIXEL_RATIO.

TYPE: float DEFAULT: 2.0

screenshots_similarity_threshold

Minimum percentage similarity required for screenshot comparisons to pass. Env override: FLET_TEST_SCREENSHOTS_SIMILARITY_THRESHOLD.

TYPE: float DEFAULT: 99.0

use_http

If True, use HTTP transport instead of TCP for Flet client-server communication. Env override: FLET_TEST_USE_HTTP=1.

TYPE: bool DEFAULT: False

disable_fvm

If True, do not invoke fvm when running the Flutter test process. Env override: FLET_TEST_DISABLE_FVM=1.

TYPE: bool DEFAULT: False

Environment Variables
  • FLET_TEST_PLATFORM: Overrides test_platform.
  • FLET_TEST_DEVICE: Overrides test_device.
  • FLET_TEST_GOLDEN: Enables golden screenshot capture when set to 1.
  • FLET_TEST_SCREENSHOTS_PIXEL_RATIO: Overrides screenshots_pixel_ratio.
  • FLET_TEST_SCREENSHOTS_SIMILARITY_THRESHOLD: Overrides screenshots_similarity_threshold.
  • FLET_TEST_USE_HTTP: Enables HTTP transport when set to 1.
  • FLET_TEST_DISABLE_FVM: Disables fvm usage when set to 1.

page #

page: Page

Returns an instance of Flet's app Page.

screenshots_pixel_ratio #

screenshots_pixel_ratio = float(
    getenv(
        "FLET_TEST_SCREENSHOTS_PIXEL_RATIO",
        screenshots_pixel_ratio,
    )
)

screenshots_similarity_threshold #

screenshots_similarity_threshold = float(
    getenv(
        "FLET_TEST_SCREENSHOTS_SIMILARITY_THRESHOLD",
        screenshots_similarity_threshold,
    )
)

test_device #

test_device = getenv('FLET_TEST_DEVICE', test_device)

test_platform #

test_platform = getenv('FLET_TEST_PLATFORM', test_platform)

tester #

tester: Tester

Returns an instance of Tester class that programmatically interacts with page controls and the test environment.

assert_control_screenshot #

assert_control_screenshot(
    name: str,
    control: Control,
    pump_times: int = 0,
    pump_duration: DurationValue | None = None,
)

Adds control to a clean page, takes a screenshot and compares it with a golden copy or takes golden screenshot if FLET_TEST_GOLDEN=1 environment variable is set.

PARAMETER DESCRIPTION
name

Screenshot name - will be used as a base for a screenshot filename.

TYPE: str

control

Control to take a screenshot of.

TYPE: Control

assert_screenshot #

assert_screenshot(name: str, screenshot: bytes)

Compares provided screenshot with a golden copy or takes golden screenshot if FLET_TEST_GOLDEN=1 environment variable is set.

PARAMETER DESCRIPTION
name

Screenshot name - will be used as a base for a screenshot filename.

TYPE: str

screenshot

Screenshot contents in PNG format.

TYPE: bytes

start #

start()

Starts Flet app and Flutter integration test process.

teardown #

teardown()

Teardown Flutter integration test process.