-
-
Notifications
You must be signed in to change notification settings - Fork 12
Get Started
Welcome to the appium-flutter-integration-driver Wiki! Here, you'll find all the information you need to get started with our open-source project. Whether you're using WDIO or the Appium Java-client, this guide will help you set up and use the driver for Flutter contexts.
- Installing WDIO Flutter By Service π οΈ
- Adding Appium Java-client Dependency π¦
-
Examples π‘
- WDIO Examples π
- Java-client Examples β
To integrate the wdio-flutter-by-service
into your WebdriverIO setup, run the following command from your project root directory:
npm i wdio-flutter-by-service
This package provides support for locating elements in Flutter contexts using WebdriverIO.
If you're using the Appium Java-client, you need to add the appropriate dependency to your gradle
or pom.xml
file.
Add the following implementation line to your build.gradle
file:
// https://mvnrepository.com/artifact/com.github.saikrishna321/flutter
implementation group: 'com.github.saikrishna321', name: 'flutter', version: '1.0'
Add the following dependency to your pom.xml
file:
<!-- https://mvnrepository.com/artifact/com.github.saikrishna321/flutter -->
<dependency>
<groupId>com.github.saikrishna321</groupId>
<artifactId>flutter</artifactId>
<version>1.0</version>
</dependency>
The driver supports finding elements in a Flutter context using the following locators:
text
semantics label
type
key
const loginButton = await browser.flutterByValueKey$('login_button');
await loginButton.click();
const loginButton = await browser.flutterByText$('Login');
await loginButton.click();
const loginButton = await browser.flutterBySemanticsLabel$('login_button');
await loginButton.click();
const toggleButton = await browser.flutterBySemanticsLabel$('toggle_button');
await toggleButton.click();
const messageFields = await browser.flutterBySemanticsLabel$$('message_field');
console.log(messageFields.length); // Outputs the number of elements found
const message = await browser.flutterBySemanticsLabel$('message_field');
// Wait for the element to be absent
await browser.flutterWaitForAbsent({ element: message, timeout: 10 });
// Wait for the element to be visible
await browser.flutterWaitForVisible({ element: message, timeout: 10 });
await browser.flutterScrollTillVisible({
finder: await browser.flutterByText('Java'),
scrollDirection: 'up',
});
const longPressElement = await browser.flutterBySemanticsLabel$('long_press_button');
await browser.flutterLongPress({ element: longPressElement });
const doubleTapElement = await browser.flutterBySemanticsLabel$('double_tap_button');
await browser.flutterDoubleClick({ element: doubleTapElement });
const dragElement = await browser.flutterBySemanticsLabel$('drag_me');
const dropElement = await browser.flutterBySemanticsLabel$('drop_zone');
await browser.flutterDragAndDrop({
source: dragElement,
target: dropElement,
});
const switchButton = await browser.flutterBySemanticsLabel$('switch_button');
const allAttributes = await switchButton.getAttribute('all'); // Will return all attributes attached to the element
console.log(allAttributes);
WebElement loginButton = driver.findElement(FlutterBy.key("login_button"));
loginButton.click();
WebElement loginButton = driver.findElement(FlutterBy.text("Login"));
loginButton.click();
WebElement loginButton = driver.findElement(FlutterBy.semanticsLabel("login_button"));
loginButton.click();
WebElement toggleButton = driver.findElement(FlutterBy.semanticsLabel("toggle_button"));
toggleButton.click();
List<WebElement> messageFields = driver.findElements(FlutterBy.semanticsLabel("message_field"));
System.out.println(messageFields.size()); // Outputs the number of elements found
WebElement messageField = driver.findElement(FlutterBy.semanticsLabel("message_field"));
WebElement toggleButton = driver.findElement(FlutterBy.semanticsLabel("toggle_button"));
WaitForOptions waitOption = new WaitForOptions()
.setElement(messageField)
.setTimeout(Duration.ofSeconds(10));
Assertions.assertEquals(messageField.getText(), "Hello world");
toggleButton.click();
FlutterCommands.waitForInVisible(driver, waitOption);
Assertions.assertEquals(driver.findElements(FlutterBy.semanticsLabel("message_field")).size(), 0);
toggleButton.click();
FlutterCommands.waitForVisible(driver, waitOption);
ScrollOptions scrollOptions = new ScrollOptions(FlutterBy.text("Java"), ScrollOptions.ScrollDirection.UP);
WebElement element = FlutterCommands.scrollTillVisible(driver, scrollOptions);
element.click();
WebElement longPressButton = driver.findElement(FlutterBy.semanticsLabel("long_press_button"));
FlutterCommands.performLongPress(driver, new LongPressOptions().setElement(longPressButton));
WebElement doubleTap = driver.findElement(FlutterBy.semanticsLabel("double_tap_button"))
.findElement(FlutterBy.text("Double Tap"));
FlutterCommands.performDoubleClick(driver, new DoubleClickOptions()
.setElement(doubleTap)
.setPoint(new Point(10, 0))
);
WebElement dragElement = driver.findElement(FlutterBy.semanticsLabel("drag_me"));
WebElement dropElement = driver.findElement(FlutterBy.semanticsLabel("drop_zone"));
FlutterCommands.performDragAndDrop(driver, new DragAndDropOptions(dragElement, dropElement));
WebElement switchButton = driver.findElement(FlutterBy.semanticsLabel("switch_button"));
String allAttributes = switchButton.getAttribute("all"); // Will return all attributes attached to the element
System.out.println(allAttributes);
const firstImageToMock = path.resolve('test/qr.png');
const secondImageToMock = path.resolve('test/SecondImage.png');
const firstInjectedImage = await browser.flutterInjectImage(firstImageToMock);
//Click on the camera button or image picker. This will pick the mocked imaged.
const secondInjectedImage = await browser.flutterInjectImage(secondInjectedImage);
//Click on the camera button or image picker. This will pick the secondInjectedImage.
// Now if you need to again mock the first image
await browser.flutterActivateInjectedImage({ imageId: firstInjectedImage });
//Click on the camera button or image picker. This will pick the firstInjectedImage.
Feel free to explore and contribute to our project. If you have any questions or suggestions, don't hesitate to reach out!