Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies for Pytest-Appium to be used again by others #1

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0cb31f8
Changed get_json to use the requests library for the ability to add n…
tking16 Oct 23, 2019
857f30a
Deprected MarkInfo resolution
tking16 Aug 7, 2020
3a9e54a
attempting to fix driver_class and kwargs errors
tking16 Aug 7, 2020
2c2ee8d
Revert "Deprected MarkInfo resolution"
tking16 Aug 10, 2020
fb3a2d3
Merge branch 'pytest-upgrade-from-pytest-3-to-pytest-6' of https://gi…
tking16 Aug 10, 2020
61515e0
trying to revert my mistakes
tking16 Aug 10, 2020
00af697
removed warning by making driver_class and driver_kwargs not fixtures
tking16 Aug 10, 2020
d8bac1f
removed pytest.yield_fixture from driver func
tking16 Aug 10, 2020
dcb475b
replacing old pytest.yield_fixutres
tking16 Aug 10, 2020
2ad6933
replacing old pytest.yield_fixutres
tking16 Aug 11, 2020
1472bf9
replacing old pytest.yield_fixutres
tking16 Aug 11, 2020
e8bd328
removing egg files which should be ignored
tking16 Aug 11, 2020
6e17bdb
attempt to disable Android Logcat gathering
tking16 Apr 1, 2021
fbb0b2c
fixing TypeError for deprecated desired_capabilities Kwarg
tking16 Jun 9, 2023
b5fb37c
reverting changes
tking16 Jun 9, 2023
36fe4b4
Replacing Deprecated MobileBy with AppiumBy
tking16 Sep 11, 2023
22304ce
Replacing Deprecated MobileBy with AppiumBy
tking16 Sep 11, 2023
18b5f08
Revert "Replacing Deprecated MobileBy with AppiumBy"
tking16 Sep 11, 2023
90be9f2
Revert "Replacing Deprecated MobileBy with AppiumBy"
tking16 Sep 11, 2023
32b0b5e
Since Appium 2, is no longer needed, so removing it from the driver …
tking16 Dec 7, 2023
2831e0d
Added videos to pytest-html report
tking16 Feb 20, 2024
1434fa8
Attempting to add failsafe for 'incorrect Padding' Base64 error
tking16 Apr 10, 2024
f2d4909
Adding Failsafe for _gather_screenshot too
tking16 Apr 10, 2024
7e5e8a8
Reverting changes
tking16 Apr 10, 2024
ecaa5b1
Ensuring null videos aren't attached to screenshot
tking16 Apr 11, 2024
f2b5290
Using pass instead of return for when video fails so actual error if …
tking16 Jun 4, 2024
299ef14
Making sure video is definately none
tking16 Jun 4, 2024
937a42c
Allowing report to carry on if video can't be uploaded
tking16 Jun 5, 2024
dce58cf
Reverting changes
tking16 Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
**/.cache
**/__pycache__

**/.vscode
**/.vscode

.pytest_appium.egg-info
6 changes: 4 additions & 2 deletions pytest_appium/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import urllib #.request
import time
import requests


def _decode_response(response):
Expand All @@ -12,8 +13,9 @@ def _decode_response(response):
return json.loads(data.decode(encoding))


def get_json(url):
return _decode_response(urllib.request.urlopen(url))
def get_json(url, headers: dict=None):
r = requests.get(url, headers=headers)
return r.json()


def post_json(url, data):
Expand Down
17 changes: 9 additions & 8 deletions pytest_appium/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ def session_capabilities(request, variables):
return capabilities


@pytest.fixture
def driver_kwargs(request, capabilities):
""" """
# Assertions of capabilitys should go here
#appium_user = f'{0.appium_username}:{0.appium_access_key}@'
kwargs = dict(
command_executor='http://{0.appium_host}:{0.appium_port}/wd/hub'.format(request.config.option),
command_executor='http://{0.appium_host}:{0.appium_port}'.format(request.config.option),
desired_capabilities=capabilities,
browser_profile=None,
proxy=None,
Expand All @@ -64,13 +63,15 @@ def driver_kwargs(request, capabilities):
return kwargs


@pytest.fixture
def driver_class(request):
"""Appium driver class"""
return webdriver.Remote

@pytest.fixture
def driver_class_fixture(request):
return driver_class(request)


@pytest.yield_fixture
def driver(request, driver_class, driver_kwargs):
"""Returns a AppiumDriver instance based on options and capabilities"""
driver = driver_class(**driver_kwargs)
Expand Down Expand Up @@ -137,7 +138,7 @@ def _appium_is_device_available(appium_wd_api_endpoint, desiredCapabilities={},
#'ios_device_available': appium_is_device_available_ios,
}

@pytest.yield_fixture(scope='session')
@pytest.fixture(scope='session')
def driver_session_(request, session_capabilities):
"""
Appium Session
Expand Down Expand Up @@ -176,7 +177,7 @@ def wait_for_appium():
raise Exception(f"""Unable to connect to Appium server {appium_url}""")


@pytest.yield_fixture
@pytest.fixture
def driver_session(request, driver_session_):
"""
Appium Session
Expand All @@ -186,7 +187,7 @@ def driver_session(request, driver_session_):
#driver_session_.reset()


@pytest.yield_fixture
@pytest.fixture
def appium(driver_session):
"""Alias for driver_session"""
yield driver_session
Expand All @@ -213,7 +214,7 @@ def test_example():
# Filter tests that are not targeted for this platform
current_platform = config._variables.get('capabilities',{}).get('platformName','').lower()
def select_test(item):
platform_marker = item.get_marker("platform")
platform_marker = item.get_closest_marker("platform")
if platform_marker and platform_marker.args and current_platform:
test_platform_specified = platform_marker.args[0].lower()
if test_platform_specified != current_platform:
Expand Down
17 changes: 16 additions & 1 deletion pytest_appium/html_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def _gather_screenshot(item, report, driver, summary, extra):
# add screenshot to the html report
extra.append(pytest_html.extras.image(screenshot, 'Screenshot'))

def _gather_video(item, report, driver, summary, extra):
try:
video = driver.stop_recording_screen()
except Exception as e:
summary.append('WARNING: Failed to gather video: {0}'.format(e))
return
pytest_html = item.config.pluginmanager.getplugin('html')
if video and pytest_html is not None:
# add screenshot to the html report
extra.append(pytest_html.extras.mp4(video, 'Video'))


def _gather_page_source(item, report, driver, summary, extra):
try:
Expand Down Expand Up @@ -117,10 +128,14 @@ def pytest_runtest_makereport(self, item, call):
_gather_app_strings(item, report, driver, summary, extra)
if 'screenshot' not in exclude:
_gather_screenshot(item, report, driver, summary, extra)
if 'video' not in exclude:
_gather_video(item, report, driver, summary, extra)
if 'page_source' not in exclude:
_gather_page_source(item, report, driver, summary, extra)
if 'logs' not in exclude:
_gather_logs(item, report, driver, summary, extra)
pass # log gathering on Android is very time-consuming,
# and seems to fail on Jenkins anyway
# _gather_logs(item, report, driver, summary, extra)
item.config.hook.pytest_appium_capture_debug(item=item, report=report, extra=extra)
item.config.hook.pytest_appium_runtest_makereport(item=item, report=report, summary=summary, extra=extra)
if summary:
Expand Down