-
Notifications
You must be signed in to change notification settings - Fork 566
Add unit tests for keyboard API #452
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,3 +32,69 @@ def test_hide_keyboard(self): | |||||||||||||
appium_command('/session/1234567890/appium/device/hide_keyboard') | ||||||||||||||
) | ||||||||||||||
assert isinstance(driver.hide_keyboard(), WebDriver) | ||||||||||||||
|
||||||||||||||
@httpretty.activate | ||||||||||||||
def test_press_keycode(self): | ||||||||||||||
driver = android_w3c_driver() | ||||||||||||||
httpretty.register_uri( | ||||||||||||||
httpretty.POST, | ||||||||||||||
appium_command('/session/1234567890/appium/device/press_keycode'), | ||||||||||||||
body='{"value": "86"}' | ||||||||||||||
) | ||||||||||||||
driver.press_keycode(86) | ||||||||||||||
d = get_httpretty_request_body((httpretty.last_request())) | ||||||||||||||
assert d['keycode'] == 86 | ||||||||||||||
|
||||||||||||||
@httpretty.activate | ||||||||||||||
def test_long_press_keycode(self): | ||||||||||||||
driver = android_w3c_driver() | ||||||||||||||
httpretty.register_uri( | ||||||||||||||
httpretty.POST, | ||||||||||||||
appium_command('/session/1234567890/appium/device/long_press_keycode'), | ||||||||||||||
body='{"value": "86"}' | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||||||||||||||
) | ||||||||||||||
driver.long_press_keycode(86) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check returned value type |
||||||||||||||
d = get_httpretty_request_body((httpretty.last_request())) | ||||||||||||||
assert d['keycode'] == 86 | ||||||||||||||
|
||||||||||||||
@httpretty.activate | ||||||||||||||
def test_keyevent(self): | ||||||||||||||
driver = android_w3c_driver() | ||||||||||||||
httpretty.register_uri( | ||||||||||||||
httpretty.POST, | ||||||||||||||
appium_command('/session/1234567890/appium/device/keyevent'), | ||||||||||||||
body='{keycode: 86}' | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body should be JSON format |
||||||||||||||
) | ||||||||||||||
assert isinstance(driver.keyevent(86), WebDriver) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
@httpretty.activate | ||||||||||||||
def test_press_keycode_with_flags(self): | ||||||||||||||
driver = android_w3c_driver() | ||||||||||||||
httpretty.register_uri( | ||||||||||||||
httpretty.POST, | ||||||||||||||
appium_command('/session/1234567890/appium/device/press_keycode'), | ||||||||||||||
body='{keycode: 86, metastate: 2097153, flags: 44}' | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body should be JSON format |
||||||||||||||
) | ||||||||||||||
# metastate is META_SHIFT_ON and META_NUM_LOCK_ON | ||||||||||||||
# flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM | ||||||||||||||
assert isinstance( | ||||||||||||||
driver.press_keycode( | ||||||||||||||
86, metastate=[ | ||||||||||||||
0x00000001, 0x00200000], flags=[ | ||||||||||||||
0x20, 0x00000004, 0x00000008]), WebDriver) | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add check arguments which are passed to appium server.
Suggested change
|
||||||||||||||
@httpretty.activate | ||||||||||||||
def test_long_press_keycode_with_flags(self): | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||||||||||||||
driver = android_w3c_driver() | ||||||||||||||
httpretty.register_uri( | ||||||||||||||
httpretty.POST, | ||||||||||||||
appium_command('/session/1234567890/appium/device/long_press_keycode'), | ||||||||||||||
body='{keycode: 86, metastate: 2097153, flags: 44}' | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body should be JSON format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Kazu. I understand. Pretty much all the unit tests out there don't have this JSON format do you think all those needs change as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on what the test check. res = driver.do_some_command
assert res == 'some result' # Check the response value. In this case, we must set the return value. Maybe, almost cases are not necessary since the client simply returns the result without modification inside the client. As a client, what request body has is important. So, the request check is necessary though. Btw, the above body should be |
||||||||||||||
) | ||||||||||||||
# metastate is META_SHIFT_ON and META_NUM_LOCK_ON | ||||||||||||||
# flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM | ||||||||||||||
assert isinstance( | ||||||||||||||
driver.long_press_keycode( | ||||||||||||||
86, metastate=[ | ||||||||||||||
0x00000001, 0x00200000], flags=[ | ||||||||||||||
0x20, 0x00000004, 0x00000008]), WebDriver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is unnecessary, so delete this line.
This body simulates the value which appium server returns.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused.
"This body simulates the value which appium server returns."
my previous commit had exactly that...
@KazuCocoa ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KazuCocoa please have a check again.
As tips, you will pass tests when both L42 is deleted and L42 is
body={}
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ki4070ma I don't understand why don't we need to mock the response? I would agree on @KazuCocoa @manoj9788 way of writing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, in my opinion, its value (
body={blabla}
) doesn't impact to any other codes and result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ki4070ma Feel free to approve it. I think this is the right way to mock it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either is fine to add a response or not as a client-side check. (It depends on the case if the client would like to check internal parsing against the response.)
btw, the return value by the server is like
{ value: '' }
, i remember.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, guys! so many confusions on this.
I think mocking and validating the request is always the way to go and doesn't make sense to rely on the server having the values and it wouldn't impact if there are any bug from the server-side since this is a completely client-side unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm merging this @KazuCocoa.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks for many your comments.
[JFYI]
Seems right.