Reputation: 1
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:
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:
As a collection of reusable functions, e.g.:
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
Or as a structured data format like JSON for the test steps:
[
{
"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.
Upvotes: 0
Views: 15