jstestnode: added support for running tests with Selenium Remote and Appium
It uses Appium, which provides a Selenium WebDrivercompatible API to remotely control an iOS (or Android) simulator.This way we can run tests in both mobile OSes without big changesto the current test code and infrastructure. This allows user to customize in the test suite module on which systemthey want to run the tests (Firefox or iOS) through the slapos parameters.In iOS, for example, it's possible to change the iOS version and it's requiredthat the user give the SauceLabs credentials in form of user:apikey usingthe `appium_server_auth` parameter. An example of parameters to use in a this suite: ``` {"mariadb": { "relaxed-writes": true, "mariadb-relaxed-writes": true, "test-database-amount": 30}, "target": "ios", "target-version": "9.3", "appium-server-auth": "username:api_key "test-suite" : "jio" , "test-url": "jio-repository.git/test/tests.html" } ```
Showing
... | ... | @@ -31,9 +31,33 @@ def main(): |
parser.add_argument('--node_quantity', help='ignored', type=int) | ||
parser.add_argument('--master_url', | ||
help='The Url of Master controling many suites') | ||
parser.add_argument('--frontend_url', | ||
help='The url of frontend of the test suite') | ||
parser.add_argument('--target', | ||
help='Target OS to run tests on', | ||
type=str) | ||
parser.add_argument('--target_version', | ||
help='Target OS version to use', | ||
type=str,) | ||
parser.add_argument('--appium_server_auth', | ||
help='Combination of user and token to access SauceLabs service. (i.e. user:token)', | ||
type=str) | ||
args = parser.parse_args() | ||
import json | ||
parsed_parameters = json.loads('$${instance-parameters:configuration._}') | ||
if not getattr(args, 'target', None): | ||
args.target = parsed_parameters['target'] | ||
if not getattr(args, 'test_suite', None): | ||
args.test_suite = parsed_parameters['test-suite'] | ||
if not getattr(args, 'target_version', None): | ||
args.target_version = parsed_parameters['target-version'] | ||
if not getattr(args, 'appium_server_auth', None): | ||
args.appium_server_auth = parsed_parameters['appium-server-auth'] | ||
try: | ||
test_suite_title = args.test_suite_title or args.test_suite | ||
test_suite = args.test_suite | ||
... | ... | @@ -51,8 +75,27 @@ def main(): |
########################## | ||
# Run all tests | ||
########################## | ||
firefox_binary = webdriver.firefox.firefox_binary.FirefoxBinary(firefox_path=FIREFOX_EXECUTABLE) | ||
browser = webdriver.Firefox(firefox_binary=firefox_binary) | ||
if args.target == 'firefox': | ||
firefox_binary = webdriver.firefox.firefox_binary.FirefoxBinary(firefox_path=FIREFOX_EXECUTABLE) | ||
browser = webdriver.Firefox(firefox_binary=firefox_binary) | ||
elif args.target == 'ios': | ||
|
||
capabilities = { | ||
'platformName': 'iOS', | ||
'platformVersion': args.target_version, | ||
'deviceName': 'iPhone Simulator', | ||
'browserName': 'Safari' | ||
} | ||
if not args.appium_server_auth: | ||
raise RuntimeError('--appium_server_auth is required.') | ||
appium_url = "http://%s@ondemand.saucelabs.com/wd/hub" % (args.appium_server_auth) | ||
browser = webdriver.Remote(appium_url, capabilities) | ||
else: | ||
raise RuntimeError('Unknown target') | ||
full_path = '$${runTestSuite-instance:buildout-directory}/software_release/parts/%s' % parsed_parameters['test-url'] | ||
full_path = full_path.split('srv')[2] | ||
url = "%s%s" % (args.frontend_url, full_path) | ||
agent = browser.execute_script("return navigator.userAgent") | ||
print agent | ||
... | ... | @@ -67,7 +110,6 @@ def main(): |
body = etree.fromstring(browser.page_source.encode('UTF-8'), html_parser) | ||
browser.title.encode('UTF-8') | ||
browser.quit() | ||
print ' '.join(body.xpath('//*[@id="qunit-testresult"]//text()')) | ||
... | ... | @@ -99,7 +141,7 @@ def main(): |
node_title = args.test_node_title, | ||
test_title = test_suite_title, | ||
project_title = args.project_title) | ||
if test_result is None: | ||
if test_result is None or not hasattr(args, 'master_url'): | ||
return | ||
# report test results | ||
while 1: | ||
... | ... |