Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ isort==4.3.4
pylint==1.9.3
autopep8==1.4.3
httpretty==0.9.6
pytest-cov==2.6.0
2 changes: 2 additions & 0 deletions test/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = -ra -q --cov=appium
154 changes: 103 additions & 51 deletions test/unit/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,118 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import httpretty
import json
import httpretty

from appium import webdriver

# :return: A string of test URL
SERVER_URL_BASE = 'http://localhost:4723/wd/hub'


def appium_command(command):
"""
Return a command of Appium

:return: A string of command URL
"rtype: string
"""
return '{}{}'.format(SERVER_URL_BASE, command)


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',
},
def android_w3c_driver():
"""
Return a W3C driver which is generated by a mock response for Android

: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': 'emulator-5554',
'deviceName': 'Android Emulator',
'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'
}
},
'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=response_body_json
)

desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',
'app': 'path/to/app',
'automationName': 'UIAutomator2'
}
driver = webdriver.Remote(
'http://localhost:4723/wd/hub',
desired_caps
)
return driver
)

httpretty.register_uri(
httpretty.POST,
appium_command('/session'),
body=response_body_json
)

desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',
'app': 'path/to/app',
'automationName': 'UIAutomator2'
}

driver = webdriver.Remote(
SERVER_URL_BASE,
desired_caps
)
return driver


def ios_w3c_driver():
"""
Return a W3C driver which is generated by a mock response for iOS

:return: An instance of WebDriver
:rtype: WebDriver
"""

response_body_json = json.dumps(
{
'value': {
'sessionId': '1234567890',
'capabilities': {
'device': 'iphone',
'browserName': 'UICatalog',
'sdkVersion': '11.4',
'CFBundleIdentifier': 'com.example.apple-samplecode.UICatalog'
}
}
}
)

httpretty.register_uri(
httpretty.POST,
appium_command('/session'),
body=response_body_json
)

desired_caps = {
'platformName': 'iOS',
'deviceName': 'iPhone Simulator',
'app': 'path/to/app',
'automationName': 'XCUITest'
}

driver = webdriver.Remote(
SERVER_URL_BASE,
desired_caps
)
return driver
10 changes: 5 additions & 5 deletions test/unit/webdriver/device/clipboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from test.unit.helper.test_helper import TestHelper
from test.unit.helper.test_helper import appium_command, android_w3c_driver, ios_w3c_driver

import json
import httpretty
Expand All @@ -25,10 +25,10 @@ class TestWebDriverDeviceClipboard(object):

@httpretty.activate
def test_set_clipboard_with_url(self):
driver = TestHelper.mock_android_driver()
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
'http://localhost:4723/wd/hub/session/1234567890/appium/device/set_clipboard',
appium_command('/session/1234567890/appium/device/set_clipboard'),
body='{"value": ""}'
)
driver.set_clipboard(appium_bytes(str('http://appium.io/'), 'UTF-8'),
Expand All @@ -41,10 +41,10 @@ def test_set_clipboard_with_url(self):

@httpretty.activate
def test_set_clipboard_text(self):
driver = TestHelper.mock_android_driver()
driver = ios_w3c_driver()
httpretty.register_uri(
httpretty.POST,
'http://localhost:4723/wd/hub/session/1234567890/appium/device/set_clipboard',
appium_command('/session/1234567890/appium/device/set_clipboard'),
body='{"value": ""}'
)
driver.set_clipboard_text('hello')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/webdriver/webdriver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import json
import httpretty

from test.unit.helper.test_helper import android_w3c_driver, ios_w3c_driver
from appium import webdriver


Expand Down