Search code examples
pythonandroidseleniumautomated-testsappium

Start (or resume) a driver for an app on the foreground without launching the app?


I'm trying to emulate 2 actions on a Genymotion emulator using Appium:

  1. Go to a specific URL, the website then redirects to the Google Play Store.
  2. Press "INSTALL" on that Google Play Store screen.

I have managed to get the URL, but when I try to start a driver for the Google Play app, it relaunches the app, which I don't want. I need to emulate a click on the INSTALL button right after I get redirected to Google Play. I have looked into running parallel tests, but it seem to launch the app for every test.

This is my code. Any help would be much appreciated!

from appium import webdriver

desired_caps_web = dict(
    platformName='Android',
    platformVersion='8',
    deviceName='Google Pixel',
    automationName='UiAutomator1',
    browserName='Chrome',
    chromedriverExecutable='C:\\Users\\Khoa_Ngo\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe')

driver_web = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps_web)

driver_web.get('https://someURL.com')

desired_caps_vending = dict(
    platformName='Android',
    platformVersion='8',
    deviceName='Google Pixel',
    automationName='UiAutomator1',
    app='/Users/Khoa_Ngo/Google Play Store.apk',  #This is bit of a workaround because I kept running into problems about intent action.
    appPackage='com.android.vending',
    )

driver_vending = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps_vending)

driver_vending.find_elements_by_xpath("//*[contains(@id, 'install')]").click() #Not working

Also how should I emulate the click (last line in code block)?


Solution

  • Add capability autoLaunch=false to desired capabilities.

    autoLaunch Initializing the app under test automatically. Appium does not install/launch the app under test if this is false. Defaults to true

    Description from: http://appium.io/docs/en/writing-running-appium/caps/#android-only