Repository navigation
Add unit tests for keyboard API - #452
Conversation
test: add unit test unlock (appium#450)
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/press_keycode'), | ||
| body='{keycode: 86}' |
There was a problem hiding this comment.
Here can be json.dumps(dict(keycode=86)) to buld JSON or write JSON like '{"keycode": "86"}'
There was a problem hiding this comment.
do you think the below is good?
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.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/press_keycode'), | ||
| body='{"value": "86"}' |
There was a problem hiding this comment.
This line is unnecessary, so delete this line.
This body simulates the value which appium server returns.
There was a problem hiding this comment.
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.
@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.
@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.
Hum, in my opinion, its value (body={blabla}) doesn't impact to any other codes and result.
There was a problem hiding this comment.
@ki4070ma Feel free to approve it. I think this is the right way to mock it.
There was a problem hiding this comment.
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.
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.
ok, thanks for many your comments.
[JFYI]
btw, the return value by the server is like { value: '' }, i remember.
Seems right.
[debug] [WD Proxy] Got response with status 200: {"sessionId":"80c32258-b7fa-4f1e-bc5b-b76b11d9a082","value":null}
[HTTP] --> POST /wd/hub/session/b7a19413-0f4f-4a52-ab52-b9aa630cffb8/appium/device/press_keycode
[HTTP] {"keycode":86}
[debug] [W3C (b7a19413)] Calling AppiumDriver.pressKeyCode() with args: [86,null,null,null,null,"b7a19413-0f4f-4a52-ab52-b9aa630cffb8"]
[debug] [WD Proxy] Matched '/appium/device/press_keycode' to command name 'pressKeyCode'
[debug] [WD Proxy] Proxying [POST /appium/device/press_keycode] to [POST http://localhost:8200/wd/hub/session/80c32258-b7fa-4f1e-bc5b-b76b11d9a082/appium/device/press_keycode] with body: {"keycode":86,"metastate":null,"flags":null}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"80c32258-b7fa-4f1e-bc5b-b76b11d9a082","value":null}
[debug] [W3C (b7a19413)] Responding to client with driver.pressKeyCode() result: null
[HTTP] <-- POST /wd/hub/session/b7a19413-0f4f-4a52-ab52-b9aa630cffb8/appium/device/press_keycode 200 28 ms - 14
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/long_press_keycode'), | ||
| body='{"value": "86"}' |
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/keyevent'), | ||
| body='{keycode: 86}' |
| appium_command('/session/1234567890/appium/device/keyevent'), | ||
| body='{keycode: 86}' | ||
| ) | ||
| assert isinstance(driver.keyevent(86), WebDriver) |
There was a problem hiding this comment.
| assert isinstance(driver.keyevent(86), WebDriver) | |
| assert isinstance(driver.keyevent(86), WebDriver) | |
| d = get_httpretty_request_body((httpretty.last_request())) | |
| assert d['keyevent'] == 86 | |
| assert d.get('metastate') is None |
| appium_command('/session/1234567890/appium/device/long_press_keycode'), | ||
| body='{"value": "86"}' | ||
| ) | ||
| driver.long_press_keycode(86) |
There was a problem hiding this comment.
Check returned value type
| 86, metastate=[ | ||
| 0x00000001, 0x00200000], flags=[ | ||
| 0x20, 0x00000004, 0x00000008]), WebDriver) | ||
|
|
There was a problem hiding this comment.
Add check arguments which are passed to appium server.
| d = get_httpretty_request_body((httpretty.last_request())) | |
| assert d['keycode'] == 86 | |
| assert d['metastate'] == [0x00000001, 0x00200000] | |
| assert d['flags'] == [0x20, 0x00000004, 0x00000008] |
| 0x20, 0x00000004, 0x00000008]), WebDriver) | ||
|
|
||
| @httpretty.activate | ||
| def test_long_press_keycode_with_flags(self): |
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/press_keycode'), | ||
| body='{"value": "86"}' |
There was a problem hiding this comment.
@ki4070ma I don't understand why don't we need to mock the response? I would agree on @KazuCocoa @manoj9788 way of writing it.
|
Thanks @SrinivasanTarget |
KazuCocoa
left a comment
There was a problem hiding this comment.
just left JSON format comments
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| appium_command('/session/1234567890/appium/device/keyevent'), | ||
| body='{keycode: 86}' |
There was a problem hiding this comment.
The body should be JSON format
| 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.
The body should be JSON format
| 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.
The body should be JSON format
There was a problem hiding this comment.
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?
All the other tests just use body and send key,val params directly. Thoughts?
There was a problem hiding this comment.
It depends on what the test check.
I mean:
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 {"value: ''"} as the response.
No description provided.