Appium + Android Studio (Instrumented Test vs Unit Test)

I’m pretty newbie programming and started developing an android automation test suite using android studio IDE.
However i can use appium on Unit Test mode only, when i try to use the Instrumented Test mode, it returns an error.I’m using a real device to run the tests.
This test for sending a SMS work good on Unit Testing but fails on Instrumented Testing

@Test
public void sendSMS ()throws InterruptedException {
// comando adb para enviar SMS
// adb shell am start -a android.intent.action.SENDTO -d sms:XXXXXXXXXXX
try {
List adbSMSargs = Arrays.asList("-d sms:" + PHONE_NUMBER);
Map<String, Object> adbSMSCMD = ImmutableMap
.of(“command”, “am start -a android.intent.action.SENDTO”, “args”, adbSMSargs);
driver.executeScript(“mobile:shell”, adbSMSCMD);
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep(2000);
WebElement smsMessage = driver.findElement(By.id(“com.google.android.apps.messaging:id/compose_message_text”));
smsMessage.sendKeys(“Hello, this is a test SMS”);
Thread.sleep(2000);
WebElement smsSendbtn = driver.findElement(By.id(“com.google.android.apps.messaging:id/send_message_button_icon”));
smsSendbtn.click();
}

Error:
04-27 23:59:36.214 11911 11934 E TestRunner: failed: sendSMS(com.example.statictests.ExampleInstrumentedTest)
04-27 23:59:36.214 11911 11934 E TestRunner: ----- begin exception -----
04-27 23:59:36.216 11911 11934 E TestRunner: java.lang.IllegalArgumentException: Unknown HttpClient factory netty
04-27 23:59:36.216 11911 11934 E TestRunner: at org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:73)
04-27 23:59:36.216 11911 11934 E TestRunner: at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:87)
04-27 23:59:36.216 11911 11934 E TestRunner: at io.appium.java_client.AppiumDriver.(AppiumDriver.java:87)
04-27 23:59:36.216 11911 11934 E TestRunner: at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:116)
04-27 23:59:36.216 11911 11934 E TestRunner: at com.example.statictests.ExampleInstrumentedTest.setUp(ExampleInstrumentedTest.java:64)
04-27 23:59:36.216 11911 11934 E TestRunner: at java.lang.reflect.Method.invoke(Native Method)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
04-27 23:59:36.216 11911 11934 E TestRunner: at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:76)
04-27 23:59:36.216 11911 11934 E TestRunner: at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
04-27 23:59:36.216 11911 11934 E TestRunner: at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:162)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.Suite.runChild(Suite.java:128)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.Suite.runChild(Suite.java:27)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
04-27 23:59:36.216 11911 11934 E TestRunner: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
04-27 23:59:36.216 11911 11934 E TestRunner: at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
04-27 23:59:36.216 11911 11934 E TestRunner: at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:444)
04-27 23:59:36.216 11911 11934 E TestRunner: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)
04-27 23:59:36.216 11911 11934 E TestRunner: ----- end exception -----
04-27 23:59:36.220 11911 11934 I TestRunner: finished: sendSMS(com.example.statictests.ExampleInstrumentedTest)

Desire Capabilities:

@Before
public void setUp() throws Exception {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, “android”);
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, “UIAutomator2”);
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, “11.0”);
dc.setCapability(“autoGrantPermissions”,“true”);

    driver =  new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),dc);

While you may get an answer here, you might want to cross post on the Android Studio forum. It seems like an Android Studio issue:

https://androidforums.com/tags/android-studio/

@wreed
Unit test and Instrumentation Test have differences in behavior and functionallity, so i believe is more a question of adapting the appium driver code to work on instrumented test than adapting android studio to appium.

Ok. Wish I could help, but I don’t know anything about this.

1 Like