Tim Wintle
Tim Wintle

Reputation: 1

Can't get selenium and android virtual device to talk to each other

I've trawled the internet but can't find anything specific to help me. I'm not overly-technical so please go easy with your answers (ha ha).

I am trying to create a very basic script that goes to a specific URL on a virtual device, enters a username and a password and logs in.

I take the following steps: Start Appium server Run Test

I've tried both of these as approaches for kicking up my instance of chrome on the Android Virtual Device:

Open Application    ${global_appiumEndpoint}      
...    udid=emulator-5554    
...    platformName=Android
...    androidPackage=com.android.chrome
...    platformVersion=10     
...    deviceName=Google Pixel 2     
...    browserName=Chrome    
...    chromedriverExecutableDir=//AutomationDrivers//OLD
...    fastReset=true'''

If I try and interact with the google chrome session created using selenium commands, I get an error of "No browser is open" (even though it is??!), however, commands from the appium library do seem to work (but are not sufficient for my testing)

If I try and kick up an instance of Chrome using this approach:

 ${capabilities}=    Create Dictionary
    Set to dictionary    ${capabilities}    udid    emulator-5554    
    Set to dictionary    ${capabilities}    platformName    Android
    Set to dictionary    ${capabilities}    platformVersion    10     
    Set to dictionary    ${capabilities}    deviceName    Google Pixel 2     
    Set to dictionary    ${capabilities}    browserName    Chrome    
    Set to dictionary    ${capabilities}    chromedriverExecutableDir    //AutomationDrivers//OLD
    Set to dictionary    ${capabilities}    fastReset    true
    Set to dictionary    ${capabilities}    app    com.android.browser
    Create Webdriver    Remote    command_executor=http://localhost:4723/wd/hub    desired_capabilities=${capabilities}

I get told that no application is open (which it is!).

So

  1. What am I doing wrong?
  2. Is it possible for selenium and appium commands to co-exist on the same test because I'm beginning to doubt my sanity!!

Thanks all

Upvotes: 0

Views: 243

Answers (1)

Helio
Helio

Reputation: 3737

One thing is an Android App, the other is an Android Operating System App, like Chrome. The error you have is that there is no App started, because you did not provide an APK, or class path for an App.

When wanting to use SeleniumLibrary to do web testing with AppiumLibrary, you have to Switch context to Web testing (and from Web testing to App testing). There is appropriate keyword in AppiumLibrary, for this.

In your test script, to avoid libraries keyword names conflicts, you have to prefix with the intended one. For example: SeleniumLibrary.Capture Page Screenshot.

I recommend to try the Appium/AppiumLibrary "OrangeDemo" to start an App from APK.


After refreshing my knowledge on using Chrome with AppiumLibrary, I made a basic example:

*** Settings ***
Library           AppiumLibrary    run_on_failure=AppiumLibrary.Log Source

*** Test Cases ***
Open robotframework.org
    [Documentation]    Simple demo of opening Chrome, going to robotframework.org and capture a screenshot.
    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=8.1    deviceName:emulator-5554    browserName=Chrome    automationName=UIAutomator2
    Switch To Context    CHROMIUM
    Go To Url    https://robotframework.org/
    Capture Page Screenshot
    Close Application

Things to know:

  • Before starting server from AppiumDesktop, you need to add in settings the full path to the executable of chromedriver (i.e. chromedriver.exe).
  • To start Chrome on browser, use browserName=, for apps there are different options like, app=<path_to_APK>, appPackage= and appWaitActivity=, also automationName=UIAutomator2 is the more recent for Android.

Upvotes: 1

Related Questions