Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 60 additions & 7 deletions docs/getting-started-with-flutter-dart-android-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ slug: getting-started-with-flutter-dart-android-automation/

import CodeBlock from '@theme/CodeBlock';
import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<script type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify({
Expand Down Expand Up @@ -58,12 +60,63 @@ If you do not have any **Flutter Android** app (.apk) and an **Flutter Test Suit

## Run Your First Test

### Step 1: Upload Your Application
### Step 1: Create your Android Flutter app and test suite for testing
For testing, you need to build a Flutter app and test suite. You can create Flutter applications and test suites using either Flutter cli or Gradlew. The steps below demonstrate how to create apks with Gradlew.

- Create an instrumentation test file in your application's directory `android/app/src/androidTest/java/com/example/lambdatestSampleApp/`. Replace **com**, **example**, and **lambdatestSampleApp** values with those from your app's package name.

```java title="SampleTest.java"
package com.example.lambdatestSampleApp;
import androidx.test.rule.SampleTestRule;
import dev.flutter.plugins.integration_test.FlutterTestRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;
import com.example.lambdatestSampleApp.Sample;
@RunWith(FlutterTestRunner.class)
public class SampleTest {
@Rule
public SampleTestRule<Sample> rule = new SampleTestRule<>(Sample.class, true, false);
}
```

- Update your application's `lambdatestSampleApp/android/app/build.gradle` file to use androidx's version of `AndroidJUnitRunner` and include the `androidx` libraries as dependencies.

```java title="build.gradle"
android {
...
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
```

- Use the following `Gradle` commands to build an instrumentation `test.apk` file(test suite) using the `Sample.java` created in the `androidTest` directory as mentioned in step 1.

```java title="Terminal"
//Go to the android folder which contains the "gradlew" script used for building Android apps from the terminal
pushd android
//Build an Android test APK (uses the Sample.java file created in step 1)
./gradlew app:assembleAndroidTest
//Build a debug APK by passing the integration test file
./gradlew app:assembleDebug -Ptarget="INTEGRATION_TEST_FILE_PATH"
//Go back to the root of the project
popd
```

Upload your **android** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API:
:::info
Avoiding this step might result in **No Tests Ran** issue on the dashboard
:::

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

### Step 2: Upload Your Application

Upload your **android** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API:

**Using App File:**

Expand Down Expand Up @@ -99,7 +152,7 @@ Response of above cURL will be a **JSON** object containing the `App URL` of the

:::

### Step 2: Uploading Test Suite
### Step 3: Uploading Test Suite

Upload your **test suite** (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API:

Expand Down Expand Up @@ -137,7 +190,7 @@ Response of above cURL will be a **JSON** object containing the `App URL` of the

:::

### Step 3: Executing The Test
### Step 4: Executing The Test

#### Basic Authentication

Expand Down Expand Up @@ -200,7 +253,7 @@ curl --location --request POST "https://mobile-api.lambdatest.com/framework/v1/f
</TabItem>
</Tabs>

### Step 4: View Test Execution
### Step 5: View Test Execution

Once you have run your tests, you can view the test execution along with logs. You will be able to see the test cases passing or failing. You can view the same at [LambdaTest Automation](https://appautomation.lambdatest.com/build).

Expand Down