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

Support set_gsm_signal #357

merged 9 commits into from
May 1, 2019

Conversation

ki4070ma
Copy link
Collaborator

For #353

MODERATE,
GOOD,
GREAT
) = list(map(str, range(5))) # TODO: Need to check where int 0 will be dropped as arg
Copy link
Collaborator Author

@ki4070ma ki4070ma Apr 29, 2019

Choose a reason for hiding this comment

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

Here is log when int 0, not '0', is used.
4 is used instead of 0 in adb execution.

[HTTP] --> POST /wd/hub/session/806d31f9-84d0-4bd4-8264-cd6af8dd7ebb/appium/device/gsm_signal
(★) [HTTP] {"signalStrength":0,"sessionId":"806d31f9-84d0-4bd4-8264-cd6af8dd7ebb"}
[W3C (806d31f9)] Calling AppiumDriver.gsmSignal() with args: [null,"806d31f9-84d0-4bd4-8264-cd6af8dd7ebb"]
[ADB] gsm signal-profile  changes the reported strength on next (15s) update.
[ADB] Getting connected emulators
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] 1 emulator(s) connected
(★)[ADB] Running '/Users/atsushimori/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 emu gsm signal-profile 4'

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@ki4070ma ki4070ma Apr 30, 2019

Choose a reason for hiding this comment

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

Yes, I've checked.
It's problem that 4(Gsm.GREAT) is set on the device when self.driver.set_gsm_signal(0)(Gsm.NONE_OR_UNKNOWN) is called. But self.driver.set_gsm_signal('0') works.

I'll look into appium-adb codes more.

Copy link
Member

Choose a reason for hiding this comment

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

Your [W3C (806d31f9)] Calling AppiumDriver.gsmSignal() with args: [null,"806d31f9-84d0-4bd4-8264-cd6af8dd7ebb"] should be like below when you send the request to server.
null is the cause of using 4 which is the default value.

[debug] [W3C (0df92b78)] Calling AppiumDriver.gsmSignal() with args: [0,"0df92b78-87ce-441e-93c7-2baf70eef29d"]

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. Hum, I'll keep current implementation and remove my comments.

string "0" works.

[HTTP] --> POST /wd/hub/session/604c1c76-bb99-4e47-b998-7ba2590a9fa6/appium/device/gsm_signal
(★)[HTTP] {"signalStrengh":"0","sessionId":"604c1c76-bb99-4e47-b998-7ba2590a9fa6"}
[W3C (604c1c76)] Calling AppiumDriver.gsmSignal() with args: ["0","604c1c76-bb99-4e47-b998-7ba2590a9fa6"]
[ADB] gsm signal-profile  changes the reported strength on next (15s) update.
[ADB] Getting connected emulators
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] 1 emulator(s) connected
(★)[ADB] Running '/Users/atsushimori/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 emu gsm signal-profile 0'

Copy link
Member

Choose a reason for hiding this comment

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

I wonder Python client has an issue to filter 0.
Could you add a unit test as the zero value?

Mine was by Ruby client. If JSON request has 0, Appium should work.

Copy link
Collaborator Author

@ki4070ma ki4070ma Apr 30, 2019

Choose a reason for hiding this comment

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

Just my guess is due to python spec like below.
I'll look into codes more.

➜  mobile git:(master) ✗ python
Python 3.7.1 (default, Dec 29 2018, 23:35:51) 
>>> if 0:
...   print('hoge')
... 
>>> if 1:
...   print('hoge')
... 
hoge

Copy link
Member

@KazuCocoa KazuCocoa Apr 30, 2019

Choose a reason for hiding this comment

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

so far, https://github.com/appium/python-client/pull/357/files#r279606290 is needed. I found an issue.
Then, 0 should work

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 for your info, it works.

MODERATE,
GOOD,
GREAT
) = list(map(str, range(5))) # TODO: Need to check where int 0 will be dropped as arg
Copy link
Member

Choose a reason for hiding this comment

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

:Usage:
self.driver.set_gsm_signal(Gsm.GOOD)
"""
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength})
Copy link
Member

Choose a reason for hiding this comment

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

Which Appium version did you run on your local?
We should send two params here because of appium/appium-base-driver#308

{'signalStrength': strength,'signalStrengh': strength})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which Appium version did you run on your local?

v1.12.1

Thanks for your notice, I'll support both params.

Copy link
Collaborator Author

@ki4070ma ki4070ma Apr 30, 2019

Choose a reason for hiding this comment

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

@KazuCocoa

We should send two params here because of appium/appium-base-driver#308

Let me confirm, this reason is to cover old appium case, right?
(If so, I'll check another client behavior like java.)

  • appium v1.10 (accept only "signalStrengh")
  • appium v1.11+ (accept both "signalStrengh" and "signalStrength")

I'm having below error log when sending {'signalStrength': strength,'signalStrengh': strength}) to appium v1.10.
I can send {'signalStrength': strength,'signalStrengh': strength}) to appium v1.12.1, but I think {'signalStrength': strength}) is enough in this case.

➜  mobile git:(master) ✗ python SampleAndroidTest.py
test_01_test_name (__main__.SimpleTest) ... 0
ERROR

======================================================================
ERROR: test_01_test_name (__main__.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "SampleAndroidTest.py", line 42, in test_01_test_name
    self.driver.set_gsm_signal(Gsm.POOR)
  File "/Users/atsushimori/.pyenv/versions/3.7.1/lib/python3.7/site-packages/appium/webdriver/extensions/gsm.py", line 38, 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.InvalidArgumentException: Message: Parameters were incorrect. We wanted {"required":["signalStrengh"]} and you sent ["signalStrength","signalStrengh","sessionId"]


----------------------------------------------------------------------
Ran 1 test in 22.366s

FAILED (errors=1)

Copy link
Member

Choose a reason for hiding this comment

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

ah, yeah. The current way looks good.
Thanks for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to {'signalStrength': strength,'signalStrengh': strength}) for #357 (comment)

:Usage:
self.driver.set_gsm_signal(Gsm.GOOD)
"""
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.

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

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

thanks

Since arg validation already done by server side
: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

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

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

Looks good to me

@ki4070ma ki4070ma merged commit 308fd1b into appium:master May 1, 2019
@ki4070ma
Copy link
Collaborator Author

ki4070ma commented May 1, 2019

Will rename gsm.py, Gsm to gsm_signal, GsmSignal in the next pr because gsm.py, Gsm can't cover GsmVoice, GsmCall with current style.

@ki4070ma ki4070ma deleted the gsm branch May 1, 2019 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants