appium/appium-geckodriver

Error when running the sample test in an Android emulator

Closed this issue · 4 comments

Hello!

I'm trying to follow the README instructions to try to automate a selenium test in Firefox mobile.
I've running a Dockerized Android emulator with the latest APK Firefox properly installed, as you can see in the image below:

image

I've also downloaded and configured the latest geckodriver in the machine running the emulator, as explained in the README instructions. And I've just slightly modified your python sample test to fit my environemnt. See properties platformName and androidDeviceSerial, the rest is exactly the same as in the README sample:

# Python3 + PyTest
import pytest
import time

from appium import webdriver
from selenium.webdriver.common.by import By


def generate_caps():
    common_caps = {
        # It does not really matter what to put there, although setting 'Firefox' might cause a failure
        # depending on the particular client library
        'browserName': 'MozillaFirefox',
        # automationName capability presence is mandatory for this Gecko Driver to be selected
        'automationName': 'Gecko',
        # Should have the name of the host platform, where the geckodriver binary is deployed
        'platformName': 'linux'
    }
    android_caps = {
        **common_caps,
        'moz:firefoxOptions': {
            'androidDeviceSerial': 'emulator-5554',
            # These capabilities depend on what you are going to automate
            # Refer Mozilla documentation at https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions for more details
            'androidPackage': 'org.mozilla.firefox'
        },
    }
    desktop_browser_caps = {
        **common_caps,
    }
    return [android_caps, desktop_browser_caps]


@pytest.fixture(params=generate_caps())
def driver(request):
    drv = webdriver.Remote('http://172.19.0.3:4723/wd/hub', request.param)
    yield drv
    drv.quit()


class TimeoutError(Exception):
    pass


def wait_until_truthy(func, timeout_sec=5.0, interval_sec=0.5):
    started = time.time()
    original_error = None
    while time.time() - started < timeout_sec:
        original_error = None
        try:
            result = func()
            if result:
                return result
        except Exception as e:
            original_error = e
        time.sleep(interval_sec)
    if original_error is None:
        raise TimeoutError(f'Condition unmet after {timeout_sec}s timeout')
    raise original_error


def test_feature_status_page_search(driver):
    driver.get('https://webkit.org/status/')

    # Enter "CSS" into the search box.
    # Ensures that at least one result appears in search
    # !!! Remember there are no ID and NAME locators in W3C standard
    # These two have been superseded by CSS ones
    search_box = driver.find_element_by_css('#search')
    search_box.send_keys('CSS')
    value = search_box.get_attribute('value')
    assert len(value) > 0
    search_box.submit()
    # Count the visible results when filters are applied
    # so one result shows up in at most one filter
    assert wait_until_truthy(
        lambda: len(driver.execute_script("return document.querySelectorAll('li.feature:not(.is-hidden)')")) > 0)

I'm getting the error below, so I'm kind of stuck here.

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a driver for automationName 'Gecko' and platformName 'linux'. Please check your desired capabilities

I'd like to clarify that this very same setup with this same Android emulator works just beautifully in Chrome, simply changing the generate_caps() method to:

def generate_caps():
    android_caps = {
        # It does not really matter what to put there, although setting 'Firefox' might cause a failure
        # depending on the particular client library
        'browserName': 'Chrome',
        # Should have the name of the host platform, where the geckodriver binary is deployed
        'platformName': 'Android'
    }
    return [android_caps]

Unfortunately Appium version that includes this driver is not published yet. It will be there after 1.20-beta is published

Ok, thank you for the response! Do you know when approximately 1.20-beta is expected?

I hope next week

The driver got published in 1.19.0-rc.4, although the 1.19 release does not include it. It should be available in 1.20 though