appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
440 stars 179 forks source link

how to automate check button enabled in Flutter ?? #693

Closed pornpawit08 closed 2 weeks ago

pornpawit08 commented 1 month ago

I need fucntion to check status button enabled or disable (Python)

Tegardoa commented 1 month ago

I usually declare ValueKey in different state in my .dart file for example: ElevatedButton( key: isDisabled ? ValueKey('disabled-button') : ValueKey('enabled-button') )

In my automation for example in js:

try { 
    button_state = 'disabled';
    await driver.execute('flutter:waitFor', finder.byValueKey('disabled-button'), 3000);
} catch (e) {
    try {
        button_state = 'enabled';
        await driver.execute('flutter:waitFor', finder.byValueKey('enabled-button'), 3000);
    } catch (innerE) {
        button_state = null;
        throw new Error('Button is not found');
    }
}

Maybe you can write like this in python:

try:
    button_state = 'disabled'
    driver.execute_script('flutter:waitFor', finder.byValueKey('disabled-button'), 3000)
except TimeoutException as e:
    try:
        button_state = 'enabled'
        driver.execute_script('flutter:waitFor', finder.byValueKey('enabled-button'), 3000)
    except TimeoutException as innerE:
        button_state = None
        raise Exception('Button is not found')

After all that, you can compare the button_state data as desired

KazuCocoa commented 2 weeks ago

Created https://github.com/appium/appium-flutter-driver/issues/703 to define a command which does the waitFor behind that as part of this driver. Maybe it could be a workaround right now.