Skip to content

Commit aa86d78

Browse files
authored
Support appium (pytest-dev#220)
* Optionally support appium as a driver provider * Handle non relevant warnings emitted during tests * Fix PytestcollectionWarning
1 parent ee2cbdf commit aa86d78

File tree

10 files changed

+95
-11
lines changed

10 files changed

+95
-11
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ __pycache__
1010
*.pyc
1111
build
1212
dist
13-
Pipfile*
13+
Pipfile.lock

Diff for: Pipfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
tox = "*"
9+
flake8 = "*"
10+
black = "*"
11+
pre-commit = "*"
12+
13+
[packages]
14+
pytest-selenium = {editable = true,path = "."}

Diff for: docs/development.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ against the supported Python versions.
2727
2828
Drivers
2929
-------
30-
To run the tests you'll going to need some browser drivers.
30+
To run the tests you're going to need some browser drivers.
3131

3232
Chromedriver
3333
~~~~~~~~~~~~

Diff for: docs/installing.rst

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Installation
44
Requirements
55
------------
66

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

99
Install pytest-selenium
1010
-----------------------
@@ -20,3 +20,14 @@ To install from source:
2020
.. code-block:: bash
2121
2222
$ python setup.py develop
23+
24+
Optional packages
25+
-----------------
26+
27+
Appium
28+
~~~~~~
29+
To install pytest-selenium with `appium <https://appium.io/>`_ support:
30+
31+
.. code-block:: bash
32+
33+
$ pip install pytest-selenium[appium]

Diff for: docs/user_guide.rst

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ User Guide
66
Quick Start
77
***********
88

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

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

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

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

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

507508
.. _capabilities:
508509

510+
Appium
511+
------
512+
513+
**Note:** Appium support is not installed by default, see: `Installation <https://pytest-selenium.readthedocs.io/en/latest/installing.html>`_
514+
515+
To run tests against mobile devices, you can use `Appium <https://appium.io>`_.
516+
This requires that you have the Appium server running.
517+
518+
By default Appium will listen on host 127.0.0.1 and port 4723.
519+
520+
To run your automated tests, simply specify ``Appium`` as your driver. Device
521+
selection is determined using capabilities. Check the
522+
`desired capabilities documentation <https://appium.io/docs/en/writing-running-appium/caps/>`__
523+
for details of accepted values.
524+
525+
Note that if your Appium server is not running locally or is running on an
526+
alternate port you will need to specify the ``--host`` and ``--port``
527+
command line options, or by setting the ``APPIUM_HOST`` and ``APPIUM_PORT``
528+
environment variables::
529+
530+
pytest --driver Appium --host appium.hostname --port 5555
531+
509532
Specifying Capabilities
510533
***********************
511534

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

516539
Command Line Capabilities

Diff for: pytest_selenium/drivers/appium.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
import os
6+
7+
HOST = os.environ.get("APPIUM_HOST", "localhost")
8+
PORT = os.environ.get("APPIUM_PORT", 4723)
9+
10+
11+
def driver_kwargs(capabilities, host, port, **kwargs):
12+
executor = "http://{0}:{1}/wd/hub".format(host, port)
13+
kwargs = {"command_executor": executor, "desired_capabilities": capabilities}
14+
return kwargs

Diff for: pytest_selenium/pytest_selenium.py

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
}
3737
)
3838

39+
try:
40+
from appium import webdriver as appiumdriver
41+
42+
SUPPORTED_DRIVERS["Appium"] = appiumdriver.Remote
43+
except ImportError:
44+
pass # Appium is optional.
45+
3946

4047
def _merge(a, b):
4148
""" merges b and a configurations.

Diff for: setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
"safari_driver = pytest_selenium.drivers.safari",
3434
"saucelabs_driver = pytest_selenium.drivers.saucelabs",
3535
"testingbot_driver = pytest_selenium.drivers.testingbot",
36+
"appium_driver = pytest_selenium.drivers.appium",
3637
]
3738
},
3839
setup_requires=["setuptools_scm"],
40+
extras_require={"appium": ["appium-python-client>=0.44"]},
3941
license="Mozilla Public License 2.0 (MPL 2.0)",
40-
keywords="py.test pytest selenium saucelabs browserstack webqa qa " "mozilla",
42+
keywords="py.test pytest selenium saucelabs browserstack webqa qa",
4143
classifiers=[
4244
"Development Status :: 5 - Production/Stable",
4345
"Framework :: Pytest",

Diff for: testing/test_testingbot.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import pytest
77

88
from functools import partial
9-
from pytest_selenium.drivers.testingbot import TestingBot, HOST, PORT
9+
10+
"'as TB' to avoid pytest trying to collect the class"
11+
from pytest_selenium.drivers.testingbot import HOST, PORT, TestingBot as TB
1012

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

@@ -95,5 +97,4 @@ def test_invalid_host(failure, monkeypatch, tmpdir):
9597
("protocol", "host", "port"), [("http", "localhost", "4445"), ("https", HOST, PORT)]
9698
)
9799
def test_executor_url(protocol, host, port):
98-
tb = TestingBot(host, port)
99-
assert tb.executor == "{}://{}:{}/wd/hub".format(protocol, host, port)
100+
assert TB(host, port).executor == "{}://{}:{}/wd/hub".format(protocol, host, port)

Diff for: tox.ini

+12
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ commands = flake8 {posargs:.}
2929
[flake8]
3030
max-line-length = 88
3131
exclude = .eggs,.tox,docs
32+
33+
[pytest]
34+
# Set test-directory explicitly to avoid PytestCollectionWarning
35+
testpaths = testing
36+
# Register markers used by tests
37+
markers =
38+
edge
39+
safari
40+
chrome
41+
skip_selenium
42+
nondestructive
43+
phantomjs

0 commit comments

Comments
 (0)