Added format to device_time as argument#312
Added format to device_time as argument#312mykola-mokhnach merged 8 commits intoappium:masterfrom ki4070ma:add-format-to-devicetime
Conversation
|
How about the third option - we keep the property and add a new setter for datetime format? |
|
Thanks for your comment. https://docs.python.org/3/library/functions.html?highlight=property#property if no, could you tell more for details? |
|
It means like below, I assume |
|
@KazuCocoa @mykola-mokhnach |
| self.command_executor._commands[Command.LOCATION_IN_VIEW] = \ | ||
| ('GET', '/session/$sessionId/element/$id/location_in_view') | ||
| self.command_executor._commands[Command.GET_DEVICE_TIME] = \ | ||
| ('GET', '/session/$sessionId/appium/device/system_time') |
There was a problem hiding this comment.
Can I change to only 'POST'?
My motivation is just to avoid complicated naming around below codes.
python-client/appium/webdriver/webdriver.py
Lines 587 to 588 in a40a933
e.g.
self.command_executor._commands[Command.GET_DEVICE_TIME_GET] = \
('GET', '/session/$sessionId/appium/device/system_time')
self.command_executor._commands[Command.GET_DEVICE_TIME_POST] = \
('POST', '/session/$sessionId/appium/device/system_time')
Your idea will be different from other variable naming..
If GET behavior should be kept, I'll update so.
(I'm not sure the impact to current behavior by change from POST to GET.)
Thanks.
There was a problem hiding this comment.
You should define another command like your e.g. as compatibility for released Appium servers.
Current released appium server cannot handle the post method. We observe users who use older Appium servers. Other libraries also use this library in their libs.
Thus, we would like to avoid breaking changes as possible.
(Instead, please leave a comment we can remove it in the future, for instance.)
There was a problem hiding this comment.
I'd also keep the old GET endpoint. I was thinking on that and I think it is more logical to leave the existing property as as and add get_formatted_device_time(self, format) method, which is going to call the new POST. Also, in the documentation for this method it is necessary to mention it is only available since Appium 1.11
There was a problem hiding this comment.
@KazuCocoa @mykola-mokhnach
Thanks a lot, you're right. I should have considered more.
I'll update along to your comments.
| return self.execute(Command.GET_DEVICE_TIME_GET, {})['value'] | ||
|
|
||
| def get_device_time(self, format=''): | ||
| """Returns the date and time from the device. (Only available since Appium 1.11.0) |
There was a problem hiding this comment.
TODO: Need to check next released Appium server version which includes appium/appium-base-driver#294
There was a problem hiding this comment.
Like below. You can try out using current appium@beta.
[HTTP] --> POST /wd/hub/session/5cb5ebe6-099d-4bdf-b516-614dad889d3e/appium/device/system_time
[HTTP] {}
[debug] [W3C (5cb5ebe6)] Calling AppiumDriver.getDeviceTime() with args: [null,"5cb5ebe6-099d-4bdf-b516-614dad889d3e"]
[AndroidDriver] Attempting to capture android device date and time
[debug] [ADB] Running '/Users/kazuaki/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell date +%Y-%m-%dT%T%z'
[debug] [W3C (5cb5ebe6)] Responding to client with driver.getDeviceTime() result: "2019-01-09T18:26:40+09:00"
[HTTP] <-- POST /wd/hub/session/5cb5ebe6-099d-4bdf-b516-614dad889d3e/appium/device/system_time 200 56 ms - 37
[HTTP]
[HTTP] --> POST /wd/hub/session/5cb5ebe6-099d-4bdf-b516-614dad889d3e/appium/device/system_time
[HTTP] {"format":"YYYY-MM-DD"}
[debug] [W3C (5cb5ebe6)] Calling AppiumDriver.getDeviceTime() with args: ["YYYY-MM-DD","5cb5ebe6-099d-4bdf-b516-614dad889d3e"]
[AndroidDriver] Attempting to capture android device date and time
[debug] [ADB] Running '/Users/kazuaki/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell date +%Y-%m-%dT%T%z'
[debug] [W3C (5cb5ebe6)] Responding to client with driver.getDeviceTime() result: "2019-01-09"
[HTTP] <-- POST /wd/hub/session/5cb5ebe6-099d-4bdf-b516-614dad889d3e/appium/device/system_time 200 36 ms - 22
[HTTP]
There was a problem hiding this comment.
Thanks. Yes, I've checked behavior with my changes in my local.
My TODO means I'll need to update version on comment if next version is different from 1.11.0. (e.g. 1.10.1)
If my understanding is wrong, please let me know.
Thanks.
There was a problem hiding this comment.
Gocha. The next is 1.11.0. Current number is correct
There was a problem hiding this comment.
Thanks, I've removed 'DO NOT MERGE' from issue's title.
appium/webdriver/webdriver.py
Outdated
| return self.execute(Command.GET_DEVICE_TIME, {})['value'] | ||
| return self.execute(Command.GET_DEVICE_TIME_GET, {})['value'] | ||
|
|
||
| def get_device_time(self, format=''): |
There was a problem hiding this comment.
the default value should be None
appium/webdriver/webdriver.py
Outdated
| :Usage: | ||
| self.driver.get_device_time(self, "YYYY-MM-DD") | ||
| """ | ||
| data = {'format': format} if format else {} |
There was a problem hiding this comment.
if format is None then device_time should be returned
appium/webdriver/webdriver.py
Outdated
| """ | ||
| if format: | ||
| return self.execute(Command.GET_DEVICE_TIME_POST, {'format': format})['value'] | ||
| else: |
There was a problem hiding this comment.
if format is None (https://docs.quantifiedcode.com/python-anti-patterns/readability/comparison_to_none.html)
also, else is redundant
There was a problem hiding this comment.
if format is None:
return self.device_time
return self.execute(Command.GET_DEVICE_TIME_POST, {'format': format})['value']
is better than below?
if format:
return self.execute(Command.GET_DEVICE_TIME_POST, {'format': format})['value']
return self.device_time
also, else is redundant
oh,,,thanks.
There was a problem hiding this comment.
The PR indicates the default argument is None. It is good to handle return value following the None then. None is better than "", since we can compare them as literal explicitly.
appium/webdriver/webdriver.py
Outdated
| :Args: | ||
| - format - The default format is `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601 | ||
| The set of format specifiers. Read https://momentjs.com/docs/ to get | ||
| the full list of supported datetime format specifiers. |
There was a problem hiding this comment.
please also add that if unset then the result of device_time is returned by default
|
I would also move the device-time related methods to a separate extension class, like in |
|
Although, this can be done in the other PR |
For #311
Which option should I take? (Maybe No.2?)