Brandon Tweed Brandon Tweed - 3 months ago 19
Bash Question

Removing a specific adb shell command in favor of using Appium

I'm reviewing some existing Appium-based automation for an Android app and in a few places there are direct shell calls to adb from within the code. I suspect the author did this because he or she could not find a good way to perform the equivalent action with Appium. Here is the adb command:

adb shell am start -d https://<various_url_details_here>


When the automation executes it has the effect of triggering the 'Open with' dialog so that the user can tap on various options, such as the Browser or an app. Is there a way to execute this specific command with Appium without directly executing shell commands? If such a way exists, is it a good idea?

Answer

Using AndroidDriver.get() function:

private WebDriver driver;

@Before
public void setUp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(..., ...);
    //--------------------------------------------------------------//
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void testcase_001() throws Exception{
    driver.get("https://<various_url_details_here>");  // Here is what you want
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id(...")));
    Thread.sleep(5000);
 }

@After
public void tearDown() throws Exception {
    driver.quit();
}
Comments