Skip to content

Commit

Permalink
Support appium (#220)
Browse files Browse the repository at this point in the history
* Optionally support appium as a driver provider

* Handle non relevant warnings emitted during tests

* Fix PytestcollectionWarning
  • Loading branch information
BeyondEvil committed Jun 12, 2019
1 parent ee2cbdf commit aa86d78
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ __pycache__
*.pyc
build
dist
Pipfile*
Pipfile.lock
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
tox = "*"
flake8 = "*"
black = "*"
pre-commit = "*"

[packages]
pytest-selenium = {editable = true,path = "."}
2 changes: 1 addition & 1 deletion docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ against the supported Python versions.
Drivers
-------
To run the tests you'll going to need some browser drivers.
To run the tests you're going to need some browser drivers.

Chromedriver
~~~~~~~~~~~~
Expand Down
13 changes: 12 additions & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Installation
Requirements
------------

pytest-selenium will work with Python 3.6 and 2.7.
pytest-selenium will work with Python >=3.6 and 2.7.

Install pytest-selenium
-----------------------
Expand All @@ -20,3 +20,14 @@ To install from source:
.. code-block:: bash
$ python setup.py develop
Optional packages
-----------------

Appium
~~~~~~
To install pytest-selenium with `appium <https://appium.io/>`_ support:

.. code-block:: bash
$ pip install pytest-selenium[appium]
31 changes: 27 additions & 4 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ User Guide
Quick Start
***********

The pytest-selenium plugin provides a method scoped selenium
The pytest-selenium plugin provides a function scoped selenium
`fixture <http://pytest.org/latest/fixture.html>`_ for your tests. This means
that any test with selenium as an argument will cause a browser instance to be
invoked. The browser may run locally or remotely depending on your
Expand Down Expand Up @@ -269,7 +269,7 @@ the default when running tests against a remote driver.

To run your automated tests, simply specify ``Remote`` as your driver. Browser
selection is determined using capabilities. Check the
`desired capabilities documentation <https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#used-by-the-selenium-server-for-browser-selection>`_
`desired capabilities documentation <https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#used-by-the-selenium-server-for-browser-selection>`__
for details of accepted values. There are also a number of
`browser specific capabilities <https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#browser-specific-capabilities>`_
that can be set. Be sure to also check the documentation for your chosen
Expand All @@ -279,7 +279,8 @@ driver, as the accepted capabilities may differ::

Note that if your server is not running locally or is running on an alternate
port you will need to specify the ``--host`` and ``--port`` command line
options::
options, or by setting the ``SELENIUM_HOST`` and ``SELENIUM_PORT`` environment
variables::

pytest --driver Remote --host selenium.hostname --port 5555 --capability browserName firefox

Expand Down Expand Up @@ -506,11 +507,33 @@ for full details of what can be configured.

.. _capabilities:

Appium
------

**Note:** Appium support is not installed by default, see: `Installation <https://pytest-selenium.readthedocs.io/en/latest/installing.html>`_

To run tests against mobile devices, you can use `Appium <https://appium.io>`_.
This requires that you have the Appium server running.

By default Appium will listen on host 127.0.0.1 and port 4723.

To run your automated tests, simply specify ``Appium`` as your driver. Device
selection is determined using capabilities. Check the
`desired capabilities documentation <https://appium.io/docs/en/writing-running-appium/caps/>`__
for details of accepted values.

Note that if your Appium server is not running locally or is running on an
alternate port you will need to specify the ``--host`` and ``--port``
command line options, or by setting the ``APPIUM_HOST`` and ``APPIUM_PORT``
environment variables::

pytest --driver Appium --host appium.hostname --port 5555

Specifying Capabilities
***********************

Configuration options are specified using a capabilities dictionary. This is
required when using a Selenium server to specify the target environment, but
required when using an Selenium server to specify the target environment, but
can also be used to configure local drivers.

Command Line Capabilities
Expand Down
14 changes: 14 additions & 0 deletions pytest_selenium/drivers/appium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os

HOST = os.environ.get("APPIUM_HOST", "localhost")
PORT = os.environ.get("APPIUM_PORT", 4723)


def driver_kwargs(capabilities, host, port, **kwargs):
executor = "http://{0}:{1}/wd/hub".format(host, port)
kwargs = {"command_executor": executor, "desired_capabilities": capabilities}
return kwargs
7 changes: 7 additions & 0 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
}
)

try:
from appium import webdriver as appiumdriver

SUPPORTED_DRIVERS["Appium"] = appiumdriver.Remote
except ImportError:
pass # Appium is optional.


def _merge(a, b):
""" merges b and a configurations.
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
"safari_driver = pytest_selenium.drivers.safari",
"saucelabs_driver = pytest_selenium.drivers.saucelabs",
"testingbot_driver = pytest_selenium.drivers.testingbot",
"appium_driver = pytest_selenium.drivers.appium",
]
},
setup_requires=["setuptools_scm"],
extras_require={"appium": ["appium-python-client>=0.44"]},
license="Mozilla Public License 2.0 (MPL 2.0)",
keywords="py.test pytest selenium saucelabs browserstack webqa qa " "mozilla",
keywords="py.test pytest selenium saucelabs browserstack webqa qa",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Framework :: Pytest",
Expand Down
7 changes: 4 additions & 3 deletions testing/test_testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pytest

from functools import partial
from pytest_selenium.drivers.testingbot import TestingBot, HOST, PORT

"'as TB' to avoid pytest trying to collect the class"
from pytest_selenium.drivers.testingbot import HOST, PORT, TestingBot as TB

pytestmark = [pytest.mark.skip_selenium, pytest.mark.nondestructive]

Expand Down Expand Up @@ -95,5 +97,4 @@ def test_invalid_host(failure, monkeypatch, tmpdir):
("protocol", "host", "port"), [("http", "localhost", "4445"), ("https", HOST, PORT)]
)
def test_executor_url(protocol, host, port):
tb = TestingBot(host, port)
assert tb.executor == "{}://{}:{}/wd/hub".format(protocol, host, port)
assert TB(host, port).executor == "{}://{}:{}/wd/hub".format(protocol, host, port)
12 changes: 12 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ commands = flake8 {posargs:.}
[flake8]
max-line-length = 88
exclude = .eggs,.tox,docs

[pytest]
# Set test-directory explicitly to avoid PytestCollectionWarning
testpaths = testing
# Register markers used by tests
markers =
edge
safari
chrome
skip_selenium
nondestructive
phantomjs

0 comments on commit aa86d78

Please sign in to comment.