Commit 90be6120 authored by Jérome Perrin's avatar Jérome Perrin

software/jstestnode: move selenium configuration in test-runner key

Also fix JSON schema, that was just invalid.

Now we have a schema that renders properly on
https://lab.nexedi.com/bk/rjs_json_form and is similar to the one from
erp5, so maybe one day we can have a convention on erp5 testnode to push
the URL of a selenium server as test-runner.server-url . In any case,
it's good for now to have consistency.

Most of this work comes from Boris Kocherov from https://www.raskon.org/
Thanks !
parent f1ffe8f0
...@@ -27,4 +27,4 @@ md5sum = 9f22db89a2679534aa8fd37dbca86782 ...@@ -27,4 +27,4 @@ md5sum = 9f22db89a2679534aa8fd37dbca86782
[template-runTestSuite] [template-runTestSuite]
filename = runTestSuite.in filename = runTestSuite.in
md5sum = bd9ff3543f0dfaf2702624e3ed74d334 md5sum = b44268d46a41042a879f47babb66c922
{ {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"description": "Parameters to instantiate JSTestNode", "description": "Parameters to instantiate JSTestNode",
"additionalProperties": false, "additionalProperties": false,
"required": [
"test-suite",
"test-runner"
],
"properties": { "properties": {
"test-suite": { "test-suite": {
"description": "The test suite to run", "description": "The test suite to run",
...@@ -18,68 +22,86 @@ ...@@ -18,68 +22,86 @@
"default": "(the web server started by this instance)", "default": "(the web server started by this instance)",
"example": "https://softinst1234.host.vifib.net/" "example": "https://softinst1234.host.vifib.net/"
}, },
"oneOf": [ "test-runner": {
{ "oneOf": [
"title": "selenium server", {
"description": "Configuration for running tests on selenium server", "type": "object",
"properties": { "title": "Selenium Server",
"target": { "description": "Configuration for Selenium server",
"description": "Target system", "additionalProperties": false,
"const": "selenium-server" "required": [
}, "desired-capabilities",
"server-url": { "server-url",
"description": "URL of the selenium server", "target"
"type": "string" ],
}, "properties": {
"verify-server-certificate": { "target": {
"description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS", "description": "Target system",
"type": "boolean", "type": "string",
"default": true "const": "selenium-server"
}, },
"server-ca-certificate": { "server-url": {
"description": "PEM encoded bundle of CA Certificates to verify the SSL/TLS Certificate of the selenium server when using HTTPS", "description": "URL of the selenium server",
"type": "string", "type": "string",
"default": "root certificates from http://certifi.io/en/latest/" "format": "uri"
}, },
"desired-capabilities": { "verify-server-certificate": {
"description": "Desired browser capabilities", "description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS",
"type": "object", "type": "boolean",
"properties": { "default": true
"browserName": { },
"description": "Name of the browser being used, for example firefox, chrome", "server-ca-certificate": {
"type": "string", "description": "PEM encoded bundle of CA Certificates to verify the SSL/TLS Certificate of the selenium server when using HTTPS",
"required": true "type": "string",
}, "default": "root certificates from http://certifi.io/en/latest/"
"version": {
"description": "The browser version",
"type": "string"
}
}, },
"additionalProperties": true "desired-capabilities": {
"description": "Desired browser capabilities",
"required": [
"browserName"
],
"type": "object",
"properties": {
"browserName": {
"description": "Name of the browser being used, for example firefox, chrome",
"type": "string"
},
"version": {
"description": "The browser version",
"type": "string"
}
}
}
} }
} },
}, {
{ "type": "object",
"title": "firefox", "title": "Firefox",
"description": "Configuration for running tests on local firefox process", "description": "Configuration for Firefox",
"properties": { "additionalProperties": false,
"target": { "properties": {
"description": "Target system", "target": {
"const": "firefox", "description": "Target system",
"default": "firefox" "const": "firefox",
"type": "string",
"default": "firefox"
}
} }
} },
}, {
{ "type": "object",
"title": "node", "title": "NodeJS",
"description": "Configuration for running tests on local nodejs", "description": "Configuration for NodeJS",
"properties": { "additionalProperties": false,
"target": { "properties": {
"description": "Target system", "target": {
"const": "node" "description": "Target system",
"const": "node",
"type": "string"
}
} }
} }
} ]
] }
} }
} }
...@@ -25,8 +25,14 @@ BASE_URL = 'http://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/' ...@@ -25,8 +25,14 @@ BASE_URL = 'http://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/'
ETC_DIRECTORY = '$${directory:etc}' ETC_DIRECTORY = '$${directory:etc}'
def main(): def main():
parsed_parameters = json.load(
open('$${runTestSuite-config-file:rendered}', 'rb'))
test_runner = parsed_parameters.get('test-runner', {})
parser = argparse.ArgumentParser(description='Run a test suite.') parser = argparse.ArgumentParser(description='Run a test suite.')
parser.add_argument('--test_suite', help='The test suite name') parser.add_argument('--test_suite', help='The test suite name',
default=parsed_parameters.get('test-suite', ''),
required=not parsed_parameters.has_key('test-suite'))
parser.add_argument('--test_suite_title', help='The test suite title') parser.add_argument('--test_suite_title', help='The test suite title')
parser.add_argument('--test_node_title', help='The test node title') parser.add_argument('--test_node_title', help='The test node title')
parser.add_argument('--project_title', help='The project title') parser.add_argument('--project_title', help='The project title')
...@@ -40,9 +46,6 @@ def main(): ...@@ -40,9 +46,6 @@ def main():
args = parser.parse_args() args = parser.parse_args()
parsed_parameters = json.load(
open('$${runTestSuite-config-file:rendered}', 'rb'))
is_browser_running = False is_browser_running = False
try: try:
test_suite_title = args.test_suite_title or args.test_suite test_suite_title = args.test_suite_title or args.test_suite
...@@ -62,7 +65,7 @@ def main(): ...@@ -62,7 +65,7 @@ def main():
########################## ##########################
# Run all tests # Run all tests
########################## ##########################
target = parsed_parameters.get('target', 'firefox') target = test_runner.get('target', 'firefox')
if target == 'node': if target == 'node':
# Execute NodeJS tests # Execute NodeJS tests
result_string = check_output(['${nodejs-output:node}', '${jio-repository.git:location}/test/node.js'], result_string = check_output(['${nodejs-output:node}', '${jio-repository.git:location}/test/node.js'],
...@@ -92,24 +95,24 @@ def main(): ...@@ -92,24 +95,24 @@ def main():
firefox_binary='${firefox-wrapper:location}', firefox_binary='${firefox-wrapper:location}',
executable_path='${geckodriver:location}') executable_path='${geckodriver:location}')
else: else:
assert target == 'selenium-server', "Unsupported target {}".format(parsed_parameters['target']) assert target == 'selenium-server', "Unsupported target {}".format(test_runner['target'])
# use a remote connection which verifies TLS certificate # use a remote connection which verifies TLS certificate
# workaround for https://github.com/SeleniumHQ/selenium/issues/6534 # workaround for https://github.com/SeleniumHQ/selenium/issues/6534
executor = RemoteConnection(parsed_parameters['server-url'], keep_alive=True) executor = RemoteConnection(test_runner['server-url'], keep_alive=True)
cert_reqs = 'CERT_REQUIRED' cert_reqs = 'CERT_REQUIRED'
ca_certs = certifi.where() ca_certs = certifi.where()
if not parsed_parameters.get('verify-server-certificate', True): if not test_runner.get('verify-server-certificate', True):
cert_reqs = 'CERT_NONE' cert_reqs = 'CERT_NONE'
ca_certs = None ca_certs = None
if parsed_parameters.get('server-ca-certificate'): if test_runner.get('server-ca-certificate'):
ca_certs = os.path.join(ETC_DIRECTORY, "cacerts.pem") ca_certs = os.path.join(ETC_DIRECTORY, "cacerts.pem")
with open(ca_certs, 'w') as f: with open(ca_certs, 'w') as f:
f.write(parsed_parameters.get('server-ca-certificate')) f.write(test_runner.get('server-ca-certificate'))
executor._conn = urllib3.PoolManager(cert_reqs=cert_reqs, ca_certs=ca_certs) executor._conn = urllib3.PoolManager(cert_reqs=cert_reqs, ca_certs=ca_certs)
browser = webdriver.Remote( browser = webdriver.Remote(
command_executor=executor, command_executor=executor,
desired_capabilities=parsed_parameters['desired-capabilities'], desired_capabilities=test_runner['desired-capabilities'],
) )
# adjust path for remote test url # adjust path for remote test url
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment