Skip to content

Added format to device_time as argument#312

Merged
mykola-mokhnach merged 8 commits intoappium:masterfrom
ki4070ma:add-format-to-devicetime
Jan 10, 2019
Merged

Added format to device_time as argument#312
mykola-mokhnach merged 8 commits intoappium:masterfrom
ki4070ma:add-format-to-devicetime

Conversation

@ki4070ma
Copy link
Copy Markdown
Collaborator

@ki4070ma ki4070ma commented Jan 8, 2019

For #311

Which option should I take? (Maybe No.2?)

  1. Removed property decorator from device_time
    • c2c5f98
    • [Pros] Normal api style
    • [Cons] Impact to current users
  2. Added another api like device_time_format()
    • [Pros] No impact to current users
    • [Cons] Increased similar api (e.g. device_time, device_time_format())

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

How about the third option - we keep the property and add a new setter for datetime format?

@ki4070ma
Copy link
Copy Markdown
Collaborator Author

ki4070ma commented Jan 8, 2019

Thanks for your comment.
Do you mean that 'new setter' is for property?
If yes, setter for property can't be used in my understanding.

https://docs.python.org/3/library/functions.html?highlight=property#property

if no, could you tell more for details?

@KazuCocoa
Copy link
Copy Markdown
Member

KazuCocoa commented Jan 8, 2019

It means like below, I assume

    @property
    def device_time(self):
        if self._device_time_format:
            return self.execute(Command.POST_DEVICE_TIME, {'format': format})['value']
        else:
            return self.execute(Command.GET_DEVICE_TIME, {})['value']
            
    def set_device_time_format(self, format):
        self._device_time format = format

@ki4070ma
Copy link
Copy Markdown
Collaborator Author

ki4070ma commented Jan 8, 2019

@KazuCocoa @mykola-mokhnach
Thanks, I see. I didn't have such idea to have the instance member.
Your idea looks better, I'll follow it.

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')
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@KazuCocoa

Can I change to only 'POST'?
My motivation is just to avoid complicated naming around below codes.

self.command_executor._commands[Command.GET_DEVICE_TIME] = \
('GET', '/session/$sessionId/appium/device/system_time')

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@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)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

TODO: Need to check next released Appium server version which includes appium/appium-base-driver#294

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gocha. The next is 1.11.0. Current number is correct

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I've removed 'DO NOT MERGE' from issue's title.

return self.execute(Command.GET_DEVICE_TIME, {})['value']
return self.execute(Command.GET_DEVICE_TIME_GET, {})['value']

def get_device_time(self, format=''):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the default value should be None

:Usage:
self.driver.get_device_time(self, "YYYY-MM-DD")
"""
data = {'format': format} if format else {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if format is None then device_time should be returned

@ki4070ma ki4070ma changed the title [DO NOT MERGE] Added format to device_time as argument Added format to device_time as argument Jan 10, 2019
"""
if format:
return self.execute(Command.GET_DEVICE_TIME_POST, {'format': format})['value']
else:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done by 54815e8

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

: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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also add that if unset then the result of device_time is returned by default

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done by 771324b

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

I would also move the device-time related methods to a separate extension class, like in
#307

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

Although, this can be done in the other PR

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