From 449552a11698e87cc3392acd68d33d921f946a55 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Tue, 27 Nov 2018 16:43:26 +0900 Subject: [PATCH 01/17] add httpretty --- ci-requirements.txt | 3 ++- test/unit/webdriver_tests.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/unit/webdriver_tests.py diff --git a/ci-requirements.txt b/ci-requirements.txt index f972f35c..d983ccbd 100644 --- a/ci-requirements.txt +++ b/ci-requirements.txt @@ -2,4 +2,5 @@ selenium==3.141.0 astroid==1.6.5 isort==4.3.4 pylint==1.9.3 -autopep8==1.4.3 \ No newline at end of file +autopep8==1.4.3 +httpretty==0.9.6 diff --git a/test/unit/webdriver_tests.py b/test/unit/webdriver_tests.py new file mode 100644 index 00000000..19827fc8 --- /dev/null +++ b/test/unit/webdriver_tests.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import httpretty +import requests + + +class WebDriverTests(unittest.TestCase): + @httpretty.activate + def test_httpbin(self): + httpretty.register_uri( + httpretty.GET, + "https://httpbin.org/ip", + body='{"origin": "127.0.0.1"}' + ) + + response = requests.get('https://httpbin.org/ip') + self.assertEqual({"origin": "127.0.0.1"}, response.json()) + + +if __name__ == "__main__": + unittest.main() From 5ad04f105f26150b6752b5e6a32f78d4361153f9 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Tue, 27 Nov 2018 20:32:12 +0900 Subject: [PATCH 02/17] add clipboard tests as an example --- test/unit/webdriver/webdriver_tests.py | 84 ++++++++++++++++++++++++++ test/unit/webdriver_tests.py | 25 ++++++-- 2 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 test/unit/webdriver/webdriver_tests.py diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py new file mode 100644 index 00000000..2c74fd3b --- /dev/null +++ b/test/unit/webdriver/webdriver_tests.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import httpretty +import json + +from appium import webdriver + +class WebDriverWebDriverTests(unittest.TestCase): + + @httpretty.activate + def test_create_session(self): + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session', + body = '{ "sessionId": "session-id" }' + ) + + # WebDriver + desired_caps = { + 'platformName': 'Android', + 'deviceName': 'Android Emulator', + 'app': 'path/to/app', + 'newCommandTimeout': 240, + 'automationName': 'UIAutomator2' + } + driver = webdriver.Remote( + 'http://localhost:4723/wd/hub', + desired_caps + ) + + self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) + + request = httpretty.HTTPretty.latest_requests[0] + self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) + + self.assertEqual('session-id', driver.session_id) + + @httpretty.activate + def test_clipboard(self): + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session', + body = '{ "sessionId": "session-id" }' + ) + + # WebDriver + desired_caps = { + 'platformName': 'Android', + 'deviceName': 'Android Emulator', + 'app': 'path/to/app', + 'newCommandTimeout': 240, + 'automationName': 'UIAutomator2' + } + driver = webdriver.Remote( + 'http://localhost:4723/wd/hub', + desired_caps + ) + + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session/session-id/appium/device/set_clipboard', + body = '{"value": ""}' + ) + driver.set_clipboard_text('hello') + + d = json.loads(httpretty.last_request().body) + self.assertEqual("aGVsbG8=", d["content"]) + self.assertEqual("plaintext", d["contentType"]) + +if __name__ == "__main__": + unittest.main() diff --git a/test/unit/webdriver_tests.py b/test/unit/webdriver_tests.py index 19827fc8..058b2642 100644 --- a/test/unit/webdriver_tests.py +++ b/test/unit/webdriver_tests.py @@ -13,21 +13,38 @@ # limitations under the License. import unittest -import httpretty import requests - +import httpretty class WebDriverTests(unittest.TestCase): @httpretty.activate def test_httpbin(self): httpretty.register_uri( - httpretty.GET, + httpretty.POST, "https://httpbin.org/ip", body='{"origin": "127.0.0.1"}' ) - response = requests.get('https://httpbin.org/ip') + response = requests.post( + 'https://httpbin.org/ip', + data = '{"username": "gabrielfalcao"}', + headers = { + 'content-type':'text/json' + } + ) self.assertEqual({"origin": "127.0.0.1"}, response.json()) + self.assertEqual(b'{"username": "gabrielfalcao"}', httpretty.last_request().body) + self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) + + response = requests.post( + 'https://httpbin.org/ip', + data = '{"username": "gabrielfalcao"}', + headers = { + 'content-type':'text/json' + } + ) + self.assertEqual(2, len(httpretty.HTTPretty.latest_requests)) + if __name__ == "__main__": From c03c0839aa5ed1a530549ec553f6a1d527d2d674 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 28 Nov 2018 02:06:43 +0900 Subject: [PATCH 03/17] remove an example --- test/unit/webdriver_tests.py | 51 ------------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 test/unit/webdriver_tests.py diff --git a/test/unit/webdriver_tests.py b/test/unit/webdriver_tests.py deleted file mode 100644 index 058b2642..00000000 --- a/test/unit/webdriver_tests.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import unittest -import requests -import httpretty - -class WebDriverTests(unittest.TestCase): - @httpretty.activate - def test_httpbin(self): - httpretty.register_uri( - httpretty.POST, - "https://httpbin.org/ip", - body='{"origin": "127.0.0.1"}' - ) - - response = requests.post( - 'https://httpbin.org/ip', - data = '{"username": "gabrielfalcao"}', - headers = { - 'content-type':'text/json' - } - ) - self.assertEqual({"origin": "127.0.0.1"}, response.json()) - self.assertEqual(b'{"username": "gabrielfalcao"}', httpretty.last_request().body) - self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) - - response = requests.post( - 'https://httpbin.org/ip', - data = '{"username": "gabrielfalcao"}', - headers = { - 'content-type':'text/json' - } - ) - self.assertEqual(2, len(httpretty.HTTPretty.latest_requests)) - - - -if __name__ == "__main__": - unittest.main() From 4f094df2bd1aeb73daddb3b5fcccd8b36cbb7a95 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 28 Nov 2018 09:52:37 +0900 Subject: [PATCH 04/17] add development.txt --- README.md | 1 + development.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 development.txt diff --git a/README.md b/README.md index 2f718b74..06a06222 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz). ``` - You can customise `CHANGELOG.rst` with commit messages following [.gitchangelog.rc](.gitchangelog.rc) - It generates readable changelog +- `pip install -r development.txt` ## Run tests diff --git a/development.txt b/development.txt new file mode 100644 index 00000000..e04c98bb --- /dev/null +++ b/development.txt @@ -0,0 +1 @@ +-r ci-requirements.txt From ebe27ca4cd4787a9a5cc01a8aed923b927452f0b Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 28 Nov 2018 11:43:44 +0900 Subject: [PATCH 05/17] add test for forceMjsonwp --- test/unit/webdriver/webdriver_tests.py | 47 +++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py index 2c74fd3b..15dc6b55 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_tests.py @@ -25,10 +25,9 @@ def test_create_session(self): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = '{ "sessionId": "session-id" }' + body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' ) - # WebDriver desired_caps = { 'platformName': 'Android', 'deviceName': 'Android Emulator', @@ -46,14 +45,53 @@ def test_create_session(self): request = httpretty.HTTPretty.latest_requests[0] self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) + request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) + self.assertTrue(request_json.get('capabilities') is not None) + self.assertTrue(request_json.get('desiredCapabilities') is not None) + + self.assertEqual('session-id', driver.session_id) + self.assertEqual(True, driver.w3c) + + @httpretty.activate + def test_create_session_forceMjsonwp(self): + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session', + body = '{ "capabilities": {"deviceName": "Android Emulator"}, "status": 0, "sessionId": "session-id"}' + ) + + desired_caps = { + 'platformName': 'Android', + 'deviceName': 'Android Emulator', + 'app': 'path/to/app', + 'newCommandTimeout': 240, + 'automationName': 'UIAutomator2', + 'forceMjsonwp': True + } + driver = webdriver.Remote( + 'http://localhost:4723/wd/hub', + desired_caps + ) + + self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) + + request = httpretty.HTTPretty.latest_requests[0] + self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) + + + request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) + self.assertTrue(request_json.get('capabilities') is None) + self.assertTrue(request_json.get('desiredCapabilities') is not None) + self.assertEqual('session-id', driver.session_id) + self.assertEqual(False, driver.w3c) @httpretty.activate def test_clipboard(self): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = '{ "sessionId": "session-id" }' + body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' ) # WebDriver @@ -81,4 +119,5 @@ def test_clipboard(self): self.assertEqual("plaintext", d["contentType"]) if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverWebDriverTests) + unittest.TextTestRunner(verbosity=2).run(suite) From 8609c0004e73a1004c10d65c7a5be4e7ddb6882c Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 28 Nov 2018 12:04:56 +0900 Subject: [PATCH 06/17] extract a mock into helper --- test/unit/helper/test_helper.py | 40 ++++++++++++++++++++++++++ test/unit/webdriver/webdriver_tests.py | 21 ++------------ 2 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 test/unit/helper/test_helper.py diff --git a/test/unit/helper/test_helper.py b/test/unit/helper/test_helper.py new file mode 100644 index 00000000..15b8ca44 --- /dev/null +++ b/test/unit/helper/test_helper.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import httpretty +import json + +from appium import webdriver + +class TestHelper(): + def mock_android_driver(): + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session', + body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' + ) + + desired_caps = { + 'platformName': 'Android', + 'deviceName': 'Android Emulator', + 'app': 'path/to/app', + 'newCommandTimeout': 240, + 'automationName': 'UIAutomator2' + } + driver = webdriver.Remote( + 'http://localhost:4723/wd/hub', + desired_caps + ) + return driver diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py index 15dc6b55..5735ea55 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_tests.py @@ -16,6 +16,7 @@ import httpretty import json +from test.unit.helper.test_helper import TestHelper from appium import webdriver class WebDriverWebDriverTests(unittest.TestCase): @@ -88,25 +89,7 @@ def test_create_session_forceMjsonwp(self): @httpretty.activate def test_clipboard(self): - httpretty.register_uri( - httpretty.POST, - 'http://localhost:4723/wd/hub/session', - body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' - ) - - # WebDriver - desired_caps = { - 'platformName': 'Android', - 'deviceName': 'Android Emulator', - 'app': 'path/to/app', - 'newCommandTimeout': 240, - 'automationName': 'UIAutomator2' - } - driver = webdriver.Remote( - 'http://localhost:4723/wd/hub', - desired_caps - ) - + driver = TestHelper.mock_android_driver() httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session/session-id/appium/device/set_clipboard', From cab7a2bc52bf6b5431c70df347ceffbad134f575 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 28 Nov 2018 12:09:04 +0900 Subject: [PATCH 07/17] apply formatter --- test/unit/helper/test_helper.py | 3 ++- test/unit/webdriver/webdriver_tests.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/unit/helper/test_helper.py b/test/unit/helper/test_helper.py index 15b8ca44..78e64be8 100644 --- a/test/unit/helper/test_helper.py +++ b/test/unit/helper/test_helper.py @@ -18,12 +18,13 @@ from appium import webdriver + class TestHelper(): def mock_android_driver(): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' + body='{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' ) desired_caps = { diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py index 5735ea55..043f7f5b 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_tests.py @@ -19,6 +19,7 @@ from test.unit.helper.test_helper import TestHelper from appium import webdriver + class WebDriverWebDriverTests(unittest.TestCase): @httpretty.activate @@ -26,7 +27,7 @@ def test_create_session(self): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = '{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' + body='{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' ) desired_caps = { @@ -58,7 +59,7 @@ def test_create_session_forceMjsonwp(self): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = '{ "capabilities": {"deviceName": "Android Emulator"}, "status": 0, "sessionId": "session-id"}' + body='{ "capabilities": {"deviceName": "Android Emulator"}, "status": 0, "sessionId": "session-id"}' ) desired_caps = { @@ -79,7 +80,6 @@ def test_create_session_forceMjsonwp(self): request = httpretty.HTTPretty.latest_requests[0] self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) - request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) self.assertTrue(request_json.get('capabilities') is None) self.assertTrue(request_json.get('desiredCapabilities') is not None) @@ -93,7 +93,7 @@ def test_clipboard(self): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session/session-id/appium/device/set_clipboard', - body = '{"value": ""}' + body='{"value": ""}' ) driver.set_clipboard_text('hello') @@ -101,6 +101,7 @@ def test_clipboard(self): self.assertEqual("aGVsbG8=", d["content"]) self.assertEqual("plaintext", d["contentType"]) + if __name__ == "__main__": suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverWebDriverTests) unittest.TextTestRunner(verbosity=2).run(suite) From e5968616af58f52e124da845e3a9d725fa04fbb8 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Thu, 29 Nov 2018 01:36:48 +0900 Subject: [PATCH 08/17] arrange arguments --- test/unit/helper/test_helper.py | 40 ++++++++++++++++++++++++-- test/unit/webdriver/webdriver_tests.py | 4 +-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/test/unit/helper/test_helper.py b/test/unit/helper/test_helper.py index 78e64be8..f025125a 100644 --- a/test/unit/helper/test_helper.py +++ b/test/unit/helper/test_helper.py @@ -20,18 +20,54 @@ class TestHelper(): + + @staticmethod def mock_android_driver(): + """ + Return a driver which is generated a mock response + + :return: An instance of WebDriver + :rtype: WebDriver + """ + + response_body_json = json.dumps( + { + 'value': { + 'sessionId': '1234567890', + 'capabilities': { + 'platform': 'LINUX', + 'desired': { + 'platformName': 'Android', + 'automationName': 'uiautomator2', + 'platformVersion': '7.1.1', + 'deviceName': 'Android Emulator', + 'app': '/test/apps/ApiDemos-debug.apk', + }, + 'platformName': 'Android', + 'automationName': 'uiautomator2', + 'platformVersion': '7.1.1', + 'deviceName': 'emulator-5554', + 'app': '/test/apps/ApiDemos-debug.apk', + 'deviceUDID': 'emulator-5554', + 'appPackage': 'com.example.android.apis', + 'appWaitPackage': 'com.example.android.apis', + 'appActivity': 'com.example.android.apis.ApiDemos', + 'appWaitActivity': 'com.example.android.apis.ApiDemos' + } + } + } + ) + httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body='{ "value": { "sessionId": "session-id", "capabilities": {"deviceName": "Android Emulator"}}}' + body = response_body_json ) desired_caps = { 'platformName': 'Android', 'deviceName': 'Android Emulator', 'app': 'path/to/app', - 'newCommandTimeout': 240, 'automationName': 'UIAutomator2' } driver = webdriver.Remote( diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py index 043f7f5b..2dfb7835 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_tests.py @@ -34,7 +34,6 @@ def test_create_session(self): 'platformName': 'Android', 'deviceName': 'Android Emulator', 'app': 'path/to/app', - 'newCommandTimeout': 240, 'automationName': 'UIAutomator2' } driver = webdriver.Remote( @@ -66,7 +65,6 @@ def test_create_session_forceMjsonwp(self): 'platformName': 'Android', 'deviceName': 'Android Emulator', 'app': 'path/to/app', - 'newCommandTimeout': 240, 'automationName': 'UIAutomator2', 'forceMjsonwp': True } @@ -92,7 +90,7 @@ def test_clipboard(self): driver = TestHelper.mock_android_driver() httpretty.register_uri( httpretty.POST, - 'http://localhost:4723/wd/hub/session/session-id/appium/device/set_clipboard', + 'http://localhost:4723/wd/hub/session/1234567890/appium/device/set_clipboard', body='{"value": ""}' ) driver.set_clipboard_text('hello') From 05a3bf3ae44f18e726d60865c99988adb2a61df9 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Thu, 29 Nov 2018 17:06:54 +0900 Subject: [PATCH 09/17] make some packages importable --- test/unit/__init__.py | 0 test/unit/helper/__init__.py | 13 +++++++++++++ test/unit/helper/test_helper.py | 2 +- test/unit/webdriver/webdriver_tests.py | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/unit/__init__.py create mode 100644 test/unit/helper/__init__.py diff --git a/test/unit/__init__.py b/test/unit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/helper/__init__.py b/test/unit/helper/__init__.py new file mode 100644 index 00000000..cc173e9d --- /dev/null +++ b/test/unit/helper/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/test/unit/helper/test_helper.py b/test/unit/helper/test_helper.py index f025125a..a8037442 100644 --- a/test/unit/helper/test_helper.py +++ b/test/unit/helper/test_helper.py @@ -61,7 +61,7 @@ def mock_android_driver(): httpretty.register_uri( httpretty.POST, 'http://localhost:4723/wd/hub/session', - body = response_body_json + body=response_body_json ) desired_caps = { diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_tests.py index 2dfb7835..d8488168 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_tests.py @@ -15,9 +15,10 @@ import unittest import httpretty import json +import sys -from test.unit.helper.test_helper import TestHelper from appium import webdriver +from test.unit.helper.test_helper import TestHelper class WebDriverWebDriverTests(unittest.TestCase): From e4461bc0af67f509f60144fba9212e934e9e9ec1 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Thu, 29 Nov 2018 17:43:48 +0900 Subject: [PATCH 10/17] fix structure --- ci.sh | 2 +- test/unit/__init__.py | 13 ++++++ test/unit/webdriver/device/clipboard_test.py | 42 +++++++++++++++++++ .../multi_action_test.py} | 4 +- .../touch_action_test.py} | 4 +- .../{webdriver_tests.py => webdriver_test.py} | 15 ------- 6 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 test/unit/webdriver/device/clipboard_test.py rename test/unit/{multi_action_tests.py => webdriver/multi_action_test.py} (94%) rename test/unit/{touch_action_tests.py => webdriver/touch_action_test.py} (92%) rename test/unit/webdriver/{webdriver_tests.py => webdriver_test.py} (86%) diff --git a/ci.sh b/ci.sh index 2176f419..af4ed337 100755 --- a/ci.sh +++ b/ci.sh @@ -8,4 +8,4 @@ if [[ $result ]] ; then fi python -m pylint --rcfile .pylintrc appium test --py3k -python -m pytest test/unit/* +python -m pytest test/ diff --git a/test/unit/__init__.py b/test/unit/__init__.py index e69de29b..cc173e9d 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py new file mode 100644 index 00000000..dfbb63fc --- /dev/null +++ b/test/unit/webdriver/device/clipboard_test.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import httpretty +import json + +from appium import webdriver +from test.unit.helper.test_helper import TestHelper + + +class WebDriverDeviceClipboardTests(unittest.TestCase): + + @httpretty.activate + def test_clipboard(self): + driver = TestHelper.mock_android_driver() + httpretty.register_uri( + httpretty.POST, + 'http://localhost:4723/wd/hub/session/1234567890/appium/device/set_clipboard', + body='{"value": ""}' + ) + driver.set_clipboard_text('hello') + + d = json.loads(httpretty.last_request().body) + self.assertEqual("aGVsbG8=", d["content"]) + self.assertEqual("plaintext", d["contentType"]) + + +if __name__ == "__main__": + suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverDeviceClipboardTests) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/multi_action_tests.py b/test/unit/webdriver/multi_action_test.py similarity index 94% rename from test/unit/multi_action_tests.py rename to test/unit/webdriver/multi_action_test.py index 4e0133e4..d7a998f5 100644 --- a/test/unit/multi_action_tests.py +++ b/test/unit/webdriver/multi_action_test.py @@ -13,7 +13,6 @@ # limitations under the License. import unittest - from appium.webdriver.common.multi_action import MultiAction from appium.webdriver.common.touch_action import TouchAction @@ -59,4 +58,5 @@ def id(self): if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(MultiActionTests) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/touch_action_tests.py b/test/unit/webdriver/touch_action_test.py similarity index 92% rename from test/unit/touch_action_tests.py rename to test/unit/webdriver/touch_action_test.py index eb4468d4..06c2929c 100644 --- a/test/unit/touch_action_tests.py +++ b/test/unit/webdriver/touch_action_test.py @@ -13,7 +13,6 @@ # limitations under the License. import unittest - from appium.webdriver.common.touch_action import TouchAction @@ -51,4 +50,5 @@ def id(self): if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(TouchActionTests) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/webdriver/webdriver_tests.py b/test/unit/webdriver/webdriver_test.py similarity index 86% rename from test/unit/webdriver/webdriver_tests.py rename to test/unit/webdriver/webdriver_test.py index d8488168..1fbe703d 100644 --- a/test/unit/webdriver/webdriver_tests.py +++ b/test/unit/webdriver/webdriver_test.py @@ -15,7 +15,6 @@ import unittest import httpretty import json -import sys from appium import webdriver from test.unit.helper.test_helper import TestHelper @@ -86,20 +85,6 @@ def test_create_session_forceMjsonwp(self): self.assertEqual('session-id', driver.session_id) self.assertEqual(False, driver.w3c) - @httpretty.activate - def test_clipboard(self): - driver = TestHelper.mock_android_driver() - httpretty.register_uri( - httpretty.POST, - 'http://localhost:4723/wd/hub/session/1234567890/appium/device/set_clipboard', - body='{"value": ""}' - ) - driver.set_clipboard_text('hello') - - d = json.loads(httpretty.last_request().body) - self.assertEqual("aGVsbG8=", d["content"]) - self.assertEqual("plaintext", d["contentType"]) - if __name__ == "__main__": suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverWebDriverTests) From fea5fbc4020b7f3a25e6f722761c9da71868a98c Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Thu, 29 Nov 2018 18:01:00 +0900 Subject: [PATCH 11/17] tweak test case names --- ci.sh | 2 +- test/unit/webdriver/device/clipboard_test.py | 7 +------ test/unit/webdriver/multi_action_test.py | 7 +------ test/unit/webdriver/touch_action_test.py | 5 ----- test/unit/webdriver/webdriver_test.py | 7 +------ 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/ci.sh b/ci.sh index af4ed337..2e63a164 100755 --- a/ci.sh +++ b/ci.sh @@ -8,4 +8,4 @@ if [[ $result ]] ; then fi python -m pylint --rcfile .pylintrc appium test --py3k -python -m pytest test/ +python -m pytest test/unit/ diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index dfbb63fc..17272bcc 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -20,7 +20,7 @@ from test.unit.helper.test_helper import TestHelper -class WebDriverDeviceClipboardTests(unittest.TestCase): +class WebDriverDeviceClipboardTest(unittest.TestCase): @httpretty.activate def test_clipboard(self): @@ -35,8 +35,3 @@ def test_clipboard(self): d = json.loads(httpretty.last_request().body) self.assertEqual("aGVsbG8=", d["content"]) self.assertEqual("plaintext", d["contentType"]) - - -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverDeviceClipboardTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/webdriver/multi_action_test.py b/test/unit/webdriver/multi_action_test.py index d7a998f5..9b0d2a9e 100644 --- a/test/unit/webdriver/multi_action_test.py +++ b/test/unit/webdriver/multi_action_test.py @@ -17,7 +17,7 @@ from appium.webdriver.common.touch_action import TouchAction -class MultiActionTests(unittest.TestCase): +class MultiActionTest(unittest.TestCase): def setUp(self): self._multi_action = MultiAction(DriverStub()) @@ -55,8 +55,3 @@ def __init__(self, id): @property def id(self): return self._id - - -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(MultiActionTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/webdriver/touch_action_test.py b/test/unit/webdriver/touch_action_test.py index 06c2929c..60d08ee7 100644 --- a/test/unit/webdriver/touch_action_test.py +++ b/test/unit/webdriver/touch_action_test.py @@ -47,8 +47,3 @@ def __init__(self, id, x=None, y=None, count=None): @property def id(self): return self._id - - -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(TouchActionTests) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index 1fbe703d..a62080e6 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -20,7 +20,7 @@ from test.unit.helper.test_helper import TestHelper -class WebDriverWebDriverTests(unittest.TestCase): +class WebDriverWebDriverTest(unittest.TestCase): @httpretty.activate def test_create_session(self): @@ -84,8 +84,3 @@ def test_create_session_forceMjsonwp(self): self.assertEqual('session-id', driver.session_id) self.assertEqual(False, driver.w3c) - - -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(WebDriverWebDriverTests) - unittest.TextTestRunner(verbosity=2).run(suite) From 8be0e2f8a6d3f0e3d7b8507b79e9a36205e6eeef Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Thu, 29 Nov 2018 22:09:34 +0900 Subject: [PATCH 12/17] follow pytest way --- test/unit/webdriver/device/clipboard_test.py | 9 ++++--- test/unit/webdriver/multi_action_test.py | 15 ++++++----- test/unit/webdriver/touch_action_test.py | 23 +++++++++------- test/unit/webdriver/webdriver_test.py | 28 ++++++++++---------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index 17272bcc..b821aa39 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest import httpretty import json @@ -20,7 +20,8 @@ from test.unit.helper.test_helper import TestHelper -class WebDriverDeviceClipboardTest(unittest.TestCase): +class TestWebDriverDeviceClipboard(): + @httpretty.activate def test_clipboard(self): @@ -33,5 +34,5 @@ def test_clipboard(self): driver.set_clipboard_text('hello') d = json.loads(httpretty.last_request().body) - self.assertEqual("aGVsbG8=", d["content"]) - self.assertEqual("plaintext", d["contentType"]) + assert 'aGVsbG8=' == d['content'] + assert 'plaintext' == d['contentType'] diff --git a/test/unit/webdriver/multi_action_test.py b/test/unit/webdriver/multi_action_test.py index 9b0d2a9e..4a17c283 100644 --- a/test/unit/webdriver/multi_action_test.py +++ b/test/unit/webdriver/multi_action_test.py @@ -12,16 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest from appium.webdriver.common.multi_action import MultiAction from appium.webdriver.common.touch_action import TouchAction -class MultiActionTest(unittest.TestCase): - def setUp(self): - self._multi_action = MultiAction(DriverStub()) +class TestMultiAction(): + @pytest.fixture + def multi_action(self): + return MultiAction(DriverStub()) - def test_json(self): + def test_json(self, multi_action): self.maxDiff = None json = { 'actions': [ @@ -39,8 +40,8 @@ def test_json(self): } t1 = TouchAction(DriverStub()).press(ElementStub(1)).move_to(x=10, y=20).release() t2 = TouchAction(DriverStub()).press(ElementStub(5), 11, 30).move_to(x=12, y=-300).release() - self._multi_action.add(t1, t2) - self.assertEqual(json, self._multi_action.json_wire_gestures) + multi_action.add(t1, t2) + assert json == multi_action.json_wire_gestures class DriverStub(object): diff --git a/test/unit/webdriver/touch_action_test.py b/test/unit/webdriver/touch_action_test.py index 60d08ee7..e4f37d8c 100644 --- a/test/unit/webdriver/touch_action_test.py +++ b/test/unit/webdriver/touch_action_test.py @@ -12,27 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest from appium.webdriver.common.touch_action import TouchAction -class TouchActionTests(unittest.TestCase): - def setUp(self): - self._touch_action = TouchAction(DriverStub()) +import pytest +class TestTouchAction(): - def test_tap_json(self): + + @pytest.fixture + def touch_action(self): + return TouchAction(DriverStub()) + + def test_tap_json(self, touch_action): json = [ {'action': 'tap', 'options': {'count': 1, 'element': 1}} ] - self._touch_action.tap(ElementStub(1)) - self.assertEqual(json, self._touch_action.json_wire_gestures) + touch_action.tap(ElementStub(1)) + assert json == touch_action.json_wire_gestures - def test_tap_x_y_json(self): + def test_tap_x_y_json(self, touch_action): json = [ {'action': 'tap', 'options': {'x': 3, 'y': 4, 'count': 1, 'element': 2}} ] - self._touch_action.tap(ElementStub(2), 3, 4) - self.assertEqual(json, self._touch_action.json_wire_gestures) + touch_action.tap(ElementStub(2), 3, 4) + assert json == touch_action.json_wire_gestures class DriverStub(object): diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index a62080e6..c363b4d1 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest import httpretty import json @@ -20,7 +20,7 @@ from test.unit.helper.test_helper import TestHelper -class WebDriverWebDriverTest(unittest.TestCase): +class TestWebDriverWebDriver(): @httpretty.activate def test_create_session(self): @@ -41,17 +41,17 @@ def test_create_session(self): desired_caps ) - self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) + assert 1 == len(httpretty.HTTPretty.latest_requests) request = httpretty.HTTPretty.latest_requests[0] - self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) + assert 'application/json;charset=UTF-8' == request.headers['content-type'] request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) - self.assertTrue(request_json.get('capabilities') is not None) - self.assertTrue(request_json.get('desiredCapabilities') is not None) + assert request_json.get('capabilities') is not None + assert request_json.get('desiredCapabilities') is not None - self.assertEqual('session-id', driver.session_id) - self.assertEqual(True, driver.w3c) + assert 'session-id' == driver.session_id + assert True == driver.w3c @httpretty.activate def test_create_session_forceMjsonwp(self): @@ -73,14 +73,14 @@ def test_create_session_forceMjsonwp(self): desired_caps ) - self.assertEqual(1, len(httpretty.HTTPretty.latest_requests)) + assert 1 == len(httpretty.HTTPretty.latest_requests) request = httpretty.HTTPretty.latest_requests[0] - self.assertEqual('application/json;charset=UTF-8', request.headers['content-type']) + assert 'application/json;charset=UTF-8' == request.headers['content-type'] request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) - self.assertTrue(request_json.get('capabilities') is None) - self.assertTrue(request_json.get('desiredCapabilities') is not None) + assert request_json.get('capabilities') is None + assert request_json.get('desiredCapabilities') is not None - self.assertEqual('session-id', driver.session_id) - self.assertEqual(False, driver.w3c) + assert 'session-id' == driver.session_id + assert False == driver.w3c From b81fc6e96d5a10f20119aa1b8f04375eca87a6d6 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Fri, 30 Nov 2018 01:12:19 +0900 Subject: [PATCH 13/17] fix lint --- test/unit/webdriver/device/clipboard_test.py | 14 +++++-------- test/unit/webdriver/multi_action_test.py | 9 ++++---- test/unit/webdriver/touch_action_test.py | 13 ++++++------ test/unit/webdriver/webdriver_test.py | 22 +++++++++----------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index b821aa39..990ad3a7 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -12,16 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest -import httpretty -import json - -from appium import webdriver from test.unit.helper.test_helper import TestHelper +import json +import httpretty -class TestWebDriverDeviceClipboard(): - +class TestWebDriverDeviceClipboard(object): @httpretty.activate def test_clipboard(self): @@ -34,5 +30,5 @@ def test_clipboard(self): driver.set_clipboard_text('hello') d = json.loads(httpretty.last_request().body) - assert 'aGVsbG8=' == d['content'] - assert 'plaintext' == d['contentType'] + assert d['content'] == 'aGVsbG8=' + assert d['contentType'] == 'plaintext' diff --git a/test/unit/webdriver/multi_action_test.py b/test/unit/webdriver/multi_action_test.py index 4a17c283..ec8bd652 100644 --- a/test/unit/webdriver/multi_action_test.py +++ b/test/unit/webdriver/multi_action_test.py @@ -17,13 +17,12 @@ from appium.webdriver.common.touch_action import TouchAction -class TestMultiAction(): +class TestMultiAction(object): @pytest.fixture def multi_action(self): return MultiAction(DriverStub()) def test_json(self, multi_action): - self.maxDiff = None json = { 'actions': [ [ @@ -45,13 +44,13 @@ def test_json(self, multi_action): class DriverStub(object): - def execute(self, action, params): + def execute(self, _action, _params): print("driver.execute called") class ElementStub(object): - def __init__(self, id): - self._id = id + def __init__(self, e_id): + self._id = e_id @property def id(self): diff --git a/test/unit/webdriver/touch_action_test.py b/test/unit/webdriver/touch_action_test.py index e4f37d8c..200b6f70 100644 --- a/test/unit/webdriver/touch_action_test.py +++ b/test/unit/webdriver/touch_action_test.py @@ -12,12 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from appium.webdriver.common.touch_action import TouchAction - - import pytest -class TestTouchAction(): +from appium.webdriver.common.touch_action import TouchAction + +class TestTouchAction(object): @pytest.fixture def touch_action(self): @@ -39,13 +38,13 @@ def test_tap_x_y_json(self, touch_action): class DriverStub(object): - def execute(self, action, params): + def execute(self, _action, _params): print("driver.execute called") class ElementStub(object): - def __init__(self, id, x=None, y=None, count=None): - self._id = id + def __init__(self, e_id, _x=None, _y=None, _count=None): + self._id = e_id @property def id(self): diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index c363b4d1..5eb63e4f 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -12,15 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest -import httpretty import json +import httpretty from appium import webdriver -from test.unit.helper.test_helper import TestHelper -class TestWebDriverWebDriver(): +class TestWebDriverWebDriver(object): @httpretty.activate def test_create_session(self): @@ -41,17 +39,17 @@ def test_create_session(self): desired_caps ) - assert 1 == len(httpretty.HTTPretty.latest_requests) + assert len(httpretty.HTTPretty.latest_requests) == 1 request = httpretty.HTTPretty.latest_requests[0] - assert 'application/json;charset=UTF-8' == request.headers['content-type'] + assert request.headers['content-type'] == 'application/json;charset=UTF-8' request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) assert request_json.get('capabilities') is not None assert request_json.get('desiredCapabilities') is not None - assert 'session-id' == driver.session_id - assert True == driver.w3c + assert driver.session_id == 'session-id' + assert driver.w3c @httpretty.activate def test_create_session_forceMjsonwp(self): @@ -73,14 +71,14 @@ def test_create_session_forceMjsonwp(self): desired_caps ) - assert 1 == len(httpretty.HTTPretty.latest_requests) + assert len(httpretty.HTTPretty.latest_requests) == 1 request = httpretty.HTTPretty.latest_requests[0] - assert 'application/json;charset=UTF-8' == request.headers['content-type'] + assert request.headers['content-type'] == 'application/json;charset=UTF-8' request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) assert request_json.get('capabilities') is None assert request_json.get('desiredCapabilities') is not None - assert 'session-id' == driver.session_id - assert False == driver.w3c + assert driver.session_id == 'session-id' + assert driver.w3c is False From 261063c7e3d2bc5dcb8822884f0351049e2dab36 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Fri, 30 Nov 2018 09:19:16 +0900 Subject: [PATCH 14/17] apply autopep --- test/unit/webdriver/device/clipboard_test.py | 1 + test/unit/webdriver/touch_action_test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index 990ad3a7..384bca69 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -17,6 +17,7 @@ import json import httpretty + class TestWebDriverDeviceClipboard(object): @httpretty.activate diff --git a/test/unit/webdriver/touch_action_test.py b/test/unit/webdriver/touch_action_test.py index 200b6f70..0d752fd6 100644 --- a/test/unit/webdriver/touch_action_test.py +++ b/test/unit/webdriver/touch_action_test.py @@ -16,6 +16,7 @@ from appium.webdriver.common.touch_action import TouchAction + class TestTouchAction(object): @pytest.fixture From 7c38495f060b40fcf4d1f68824a126f1405aca23 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Fri, 30 Nov 2018 11:12:26 +0900 Subject: [PATCH 15/17] update readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 06a06222..d7e05053 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,20 @@ download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz). ## Run tests +### Unit + +``` +$ py.test test/unit +``` + +Run with `pytest-xdist` + +``` +$ py.test -n 2 test/unit +``` + +### Functional + ``` $ py.test test/functional/ios/find_by_ios_class_chain_tests.py ``` From 918ee510efbed640e7584ccae360ce629a712db4 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Fri, 30 Nov 2018 12:20:32 +0900 Subject: [PATCH 16/17] add python variation --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c1d5ce33..3f54bc88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ language: python python: - "2.7" + - "3.4" + - "3.5" - "3.6" + - "3.7" install: - pip install -r ci-requirements.txt From c69cc3aa5f6b5dc795c9eb8afca4fd64dd657774 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Fri, 30 Nov 2018 12:29:46 +0900 Subject: [PATCH 17/17] specify decode code --- .travis.yml | 2 ++ test/unit/webdriver/device/clipboard_test.py | 2 +- test/unit/webdriver/webdriver_test.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f54bc88..79a9ff1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +dist: xenial + python: - "2.7" - "3.4" diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index 384bca69..0c4656ad 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -30,6 +30,6 @@ def test_clipboard(self): ) driver.set_clipboard_text('hello') - d = json.loads(httpretty.last_request().body) + d = json.loads(httpretty.last_request().body.decode('utf-8')) assert d['content'] == 'aGVsbG8=' assert d['contentType'] == 'plaintext' diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index 5eb63e4f..9b293983 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -44,7 +44,7 @@ def test_create_session(self): request = httpretty.HTTPretty.latest_requests[0] assert request.headers['content-type'] == 'application/json;charset=UTF-8' - request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) + request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body.decode('utf-8')) assert request_json.get('capabilities') is not None assert request_json.get('desiredCapabilities') is not None @@ -76,7 +76,7 @@ def test_create_session_forceMjsonwp(self): request = httpretty.HTTPretty.latest_requests[0] assert request.headers['content-type'] == 'application/json;charset=UTF-8' - request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body) + request_json = json.loads(httpretty.HTTPretty.latest_requests[0].body.decode('utf-8')) assert request_json.get('capabilities') is None assert request_json.get('desiredCapabilities') is not None