To automate picture picker and file picker in Flutter apps utilizing Flutter integration assessments, you should use the flutter_driver
bundle, which supplies a set of APIs for interacting with the applying below check (AUT).
To simulate a person deciding on a picture or file, you should use the faucet
technique of the FlutterDriver
class to faucet on the corresponding button or widget that opens the picture picker or file picker dialog. As soon as the dialog is open, you should use the sendText
technique to ship the trail of the picture or file that you just need to choose to the dialog, after which use the faucet
technique to faucet on the “OK” or “Choose” button to substantiate the choice.
This is an instance code snippet that demonstrates how one can automate picture picker and file picker utilizing Flutter integration assessments:
import 'bundle:flutter_driver/flutter_driver.dart';
void foremost() {
group('Picture and File Picker Take a look at', () {
closing imagePickerButtonFinder = discover.byValueKey('image_picker_button');
closing filePickerButtonFinder = discover.byValueKey('file_picker_button');
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.join();
});
tearDownAll(() async {
if (driver != null) {
await driver.shut();
}
});
check('Choose Picture', () async {
// Faucet on the picture picker button
await driver.faucet(imagePickerButtonFinder);
// Ship the trail of the picture to the dialog
await driver.sendText('/path/to/picture.jpg');
// Faucet on the "OK" or "Choose" button to substantiate the choice
await driver.faucet(discover.textual content('OK'));
});
check('Choose File', () async {
// Faucet on the file picker button
await driver.faucet(filePickerButtonFinder);
// Ship the trail of the file to the dialog
await driver.sendText('/path/to/file.txt');
// Faucet on the "OK" or "Choose" button to substantiate the choice
await driver.faucet(discover.textual content('Choose'));
});
});
}
Within the above instance, I outline two assessments, one for choosing a picture and one for choosing a file. I exploit the discover.byValueKey technique to find the buttons or widgets that open the picture picker or file picker dialog.
In every check, I first faucet on the corresponding button to open the dialog. I then use the sendText technique to ship the trail of the picture or file that I need to choose to the dialog. Lastly, I faucet on the “OK” or “Choose” button to substantiate the choice.
Observe that this code assumes that the picture picker and file picker dialogs in your app settle for textual content enter for choosing the file path. In case your app makes use of a unique mechanism for choosing information, you may have to adapt the code accordingly.
I hope this helps.