Appium Geckodriver
This is Appium driver for automating Firefox on different platforms, including Android.
The driver only supports Firefox and Gecko-based web views (Android only) automation using W3C WebDriver protocol.
Under the hood this driver is a wrapper/proxy over geckodriver
binary. Check the driver release notes and the official documentation to get more details on the supported features and possible pitfalls.
Note
Since version 1.0.0 Gecko driver has dropped the support of Appium 1, and is only compatible to Appium 2. Use the appium driver install gecko
command to add it to your Appium 2 dist.
Usage
It is mandatory to have both Firefox browser installed and the geckodriver binary downloaded on the platform where automated tests are going to be executed. Firefox could be downloaded from the official download site and the driver binary could be retrieved from the GitHub releases page. The binary must be put into one of the folders included to PATH environment variable. On macOS it also might be necessary to run xcattr -cr "<binary_path>"
to avoid notarization issues.
Then you need to decide where the automated test is going to be executed. Gecko driver supports the following target platforms:
- macOS
- Windows
- Linux
- Android (note that
android
cannot be passed as a value to platformName
capability; it should always equal to the host platform name)
In order to run your automated tests on Android it is necessary to have Android SDK installed, so the destination device is marked as online
in the adb devices -l
command output.
Gecko driver allows to define multiple criterions for platform selection and also to fine-tune your automation session properties. This could be done via the following session capabilities:
Example
import pytest
import time
from appium import webdriver
from appium.options.gecko import GeckoOptions
from selenium.webdriver.common.by import By
def generate_options():
common_caps = {
'browserName': 'MozillaFirefox',
'platformName': 'mac',
}
android_options = GeckoOptions().load_capabilities(common_caps)
android_options.firefox_options = {
'androidDeviceSerial': '<device/emulator serial>',
'androidPackage': 'org.mozilla.firefox',
}
desktop_options = GeckoOptions().load_capabilities(common_caps)
return [android_options, desktop_options]
@pytest.fixture(params=generate_options())
def driver(request):
drv = webdriver.Remote('http://127.0.0.1:4723', options=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/')
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()
assert wait_until_truthy(
lambda: len(driver.execute_script("return document.querySelectorAll('li.feature:not(.is-hidden)')")) > 0)
def test_feature_status_page_filters(driver):
driver.get('https://webkit.org/status/')
assert wait_until_truthy(
lambda: len(driver.execute_script("return document.querySelectorAll('.filter-toggle')")) == 7)
for checked_filter in filter(lambda f: f.is_selected(), filters):
checked_filter.click()
for filt in filters:
filt.click()
assert filt.is_selected()
filt.click()
Development
npm install
npm run lint
npm run test