How to systematically add hooks to Appium Inspector recorded tests?

I’m working on automating some tests using Appium Inspector, and I want to systematically add extra logic (hooks) to the tests it generates. However, I’m running into a problem with how Appium Inspector outputs code, to generate code, I start a session connected to my phone, start recording, and then preform a series of clicks in Appium inspector The generated Python code looks like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)")
el1.click()
el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button")
el2.click()
el3 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className("android.view.ViewGroup").instance(6)")
el3.click()
el4 = driver.find_element(by=AppiumBy.ID, value="com.android.permissioncontroller:id/permission_allow_one_time_button")
el4.click()
</code>
<code>el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)") el1.click() el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button") el2.click() el3 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className("android.view.ViewGroup").instance(6)") el3.click() el4 = driver.find_element(by=AppiumBy.ID, value="com.android.permissioncontroller:id/permission_allow_one_time_button") el4.click() </code>
el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)")
el1.click()
el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button")
el2.click()
el3 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className("android.view.ViewGroup").instance(6)")
el3.click()
el4 = driver.find_element(by=AppiumBy.ID, value="com.android.permissioncontroller:id/permission_allow_one_time_button")
el4.click()

This flat, procedural style makes it hard to systematically inject hooks or manage the logic programmatically.

for example id like to add sleeps, and test that the page generated correctly after each step, as it stands now id have to add all of these in individually where as id much prefer to add them as some form of “decorator” function

What I’d like is for the generated test to be represented in one of the following ways:

  1. As a collection of reusable functions, e.g.:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>def action_1():
    el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)")
    el1.click()
    def action_2():
    el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button")
    el2.click()
    def get_test():
    return [action_1, action_2, ...]
    </code>
    <code>def action_1(): el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)") el1.click() def action_2(): el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button") el2.click() def get_test(): return [action_1, action_2, ...] </code>
    def action_1():
        el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text("English (United States)").instance(0)")
        el1.click()
    
    def action_2():
        el2 = driver.find_element(by=AppiumBy.CLASS_NAME, value="android.widget.Button")
        el2.click()
    
    def get_test():
        return [action_1, action_2, ...]
    
    

    which would allow me to collect the functions in a list and run my logic “around” the actions taken

  2. Or as a structured data format like JSON for the test steps:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>[
    {
    "action": "click",
    "by": "AppiumBy.ANDROID_UIAUTOMATOR",
    "value": "new UiSelector().text("English (United States)").instance(0)"
    },
    {
    "action": "click",
    "by": "AppiumBy.CLASS_NAME",
    "value": "android.widget.Button"
    },
    ...
    ]
    </code>
    <code>[ { "action": "click", "by": "AppiumBy.ANDROID_UIAUTOMATOR", "value": "new UiSelector().text("English (United States)").instance(0)" }, { "action": "click", "by": "AppiumBy.CLASS_NAME", "value": "android.widget.Button" }, ... ] </code>
    [
        {
            "action": "click",
            "by": "AppiumBy.ANDROID_UIAUTOMATOR",
            "value": "new UiSelector().text("English (United States)").instance(0)"
        },
        {
            "action": "click",
            "by": "AppiumBy.CLASS_NAME",
            "value": "android.widget.Button"
        },
        ...
    ]
    

    which would allow me to create the functions myself and “get back” to the first solution

This way, I could inject hooks or modify the test dynamically without manually parsing the generated Python code.

Is there a way to configure Appium Inspector to output the tests in a more structured format, or is there a library/tool that can parse and transform the generated Python code into one of these representations? Alternatively, are there best practices for handling this kind of situation when working with Appium Inspector?

Tried manually parsing the generated Python code:
I attempted to parse the Python code output by Appium Inspector using a regular expression-based approach. However, this quickly became brittle and difficult to maintain because Appium’s output format can change slightly depending on test configuration.

Looked for Appium Inspector configuration options:
I couldn’t find any built-in settings or plugins in Appium Inspector that would allow me to output a structured format like JSON or modular Python functions.

Expected some kind of hook in Appium Inspector:
I was hoping that Appium Inspector would provide an intermediate representation or allow me to export test steps in a format that’s easier to process programmatically.

New contributor

potzko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật