[appium-device-farm-7] — How to Install APKs(@runtime) Using “Appium Device Farm” |Step-By-Step Details

Get a step-by-step walkthrough in the video below!
This article covers the process of uploading APK/IPA files at runtime in Appium Device Farm.
Step-1: Launch the appium server explicitly with Device Farm plugin
Command:
appium -ka 800 --use-plugins=device-farm -pa /wd/hub --plugin-device-farm-platform=android --log ./devicefarm.log
Example:

Step-2: Upload the apk/ipa file in “Apps” screen/Tab


Observe that App has been upload successfully & provided App Capability — app:file-1753272517991.apk

Step-3: Add the Automation Filename in the script:
cap.setApp("file-1753272517991.apk");

Step-4: Execute the script

Observe that user able to install the specified apk file under the capability & complete the execution without any exceptions.
“Complete Code: Optimized and Ready to Use”:
package com.appiumguide.devicefarm;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.time.Duration;
/**
* Script Details - "appium-device-farm”- Complete Details on How to Install APKs(@runtime) Using “Appium Device Farm”
*
* appium-java-client version: Latest
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/
public class devicefarm_InstallapkDemo {
private AndroidDriver driver;
File screenshot;
@BeforeTest
public void setup() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setDeviceName("Pixel6");
//Install apk by using device-farm central repo
cap.setApp("file-1753272517991.apk");
cap.autoGrantPermissions();
cap.noReset();
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(100));
}
@Test
public void test() throws InterruptedException, IOException {
driver.activateApp("io.appium.android.apis");
driver.findElement(AppiumBy.accessibilityId("Views")).click();
driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector().scrollable(true))"+
".scrollIntoView(new UiSelector().text(\"Tabs\"))"));
driver.findElement(AppiumBy.accessibilityId("Tabs")).click();
driver.findElement(AppiumBy.accessibilityId("5. Scrollable")).click();
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().setMaxSearchSwipes(10)" +
".scrollIntoView(new UiSelector().text(\"TAB 30\"))"));
Thread.sleep(5000);
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"TAB 30\")")).click();
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().setMaxSearchSwipes(10)" +
".scrollIntoView(new UiSelector().text(\"TAB 1\"))"));
Thread.sleep(5000);
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"TAB 1\")")).click();
}
@AfterTest
public void teardown() {
if(driver!=null) {
driver.quit();
System.out.println("Test Completed");
}
}
}
GitHub Link:
π¬ Explore More! Watch My Latest Videos on YouTube!
Visit My Official Blog:
No comments:
Post a Comment