Skip to content

Support set_gsm_signal #357

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

Merged
merged 9 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
5 changes: 0 additions & 5 deletions appium/webdriver/extensions/gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ def set_gsm_signal(self, strength):
:Args:
- strength: Signal strength. Can be set Gsm.NONE_OR_UNKNOWN/POOR/MODERATE/GOOD/GREAT

:Raises:
- TypeError - Raises a TypeError if the argument is out of range

:Usage:
self.driver.set_gsm_signal(Gsm.GOOD)
"""
if strength not in [self.NONE_OR_UNKNOWN, self.POOR, self.MODERATE, self.GOOD, self.GREAT]:
Copy link
Member

@KazuCocoa KazuCocoa May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is pretty good to show users which args can use for this method as either warn or error
(Here is client-side logic matter)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added warning log instead of throwing exception.
Here is behavior.

➜  mobile git:(master) ✗ python SampleAndroidTest.py
test_01_test_name (__main__.SimpleTest) ... 100 is out of range. Use the value like Gsm.GOOD for signal strength.
ERROR

======================================================================
ERROR: test_01_test_name (__main__.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "SampleAndroidTest.py", line 48, in test_01_test_name
    self.driver.set_gsm_signal(100)
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/appium/webdriver/extensions/gsm.py", line 41, in set_gsm_signal
    self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/appium/webdriver/errorhandler.py", line 24, in check_response
    super(MobileErrorHandler, self).check_response(response)
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Invalid signal strength param 100. Supported values: 0,1,2,3,4


----------------------------------------------------------------------
Ran 1 test in 20.444s

FAILED (errors=1)

Copy link
Member

@KazuCocoa KazuCocoa May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits]
what about something like {name for name, value in vars(self).items() if name.isupper()} to show the consts instead of the number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood for 1ca58f4

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Invalid signal strength param 100. Supported values: 0,1,2,3,4

This log comes from https://github.com/appium/appium-adb/blob/527c8b417d7b62717ececfdf068309b0ee4dbd8f/lib/tools/adb-emu-commands.js#L168 .
So can't handle from client side.

Added log is here.

➜  mobile git:(master) ✗ python SampleAndroidTest.py                                                                                                           
test_01_test_name (__main__.SimpleTest) ... 100 is out of range. Use the value in ['Gsm.NONE_OR_UNKNOWN', 'Gsm.POOR', 'Gsm.MODERATE', 'Gsm.GOOD', 'Gsm.GREAT'].
ERROR
(--snip--)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. I misunderstood it was the warning in this pr

raise TypeError("{} is out of range. Use the value like Gsm.GOOD.".format(strength))
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning an error message if a user selects out of https://github.com/appium/python-client/pull/357/files#diff-bb5916ee1320d1333f6c9ba19cf04705R22 ?

if strength not in [NONE_OR_UNKNOWN, .....]:
    return 'error message'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, seems good.
If throwing exception is too enough, please let me know.

return self

Expand Down
26 changes: 1 addition & 25 deletions test/unit/webdriver/device/gsm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import httpretty
import pytest

from appium.webdriver.webdriver import WebDriver
from appium.webdriver.extensions.gsm import Gsm
Expand All @@ -35,20 +34,7 @@ def test_gsm_signal_strength(self):
assert Gsm.GREAT == 4

@httpretty.activate
def test_set_gsm_signal_none_or_unknown(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/gsm_signal'),
)
assert isinstance(driver.set_gsm_signal(Gsm.NONE_OR_UNKNOWN), WebDriver)

d = get_httpretty_request_body(httpretty.last_request())
assert d['signalStrength'] == Gsm.NONE_OR_UNKNOWN
assert d['signalStrengh'] == Gsm.NONE_OR_UNKNOWN

@httpretty.activate
def test_set_gsm_signal_great(self):
def test_set_gsm_signal(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
Expand All @@ -59,13 +45,3 @@ def test_set_gsm_signal_great(self):
d = get_httpretty_request_body(httpretty.last_request())
assert d['signalStrength'] == Gsm.GREAT
assert d['signalStrengh'] == Gsm.GREAT

@httpretty.activate
def test_set_gsm_signal_out_of_range(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/gsm_signal'),
)
with pytest.raises(TypeError):
driver.set_gsm_signal(100)