add ability for monkey farmer to launch browser with environment variables set

This commit is contained in:
Vincent Sanders 2020-03-19 20:57:37 +00:00
parent 4cbdcc4aae
commit 19dded8cfa
2 changed files with 22 additions and 2 deletions

View File

@ -22,6 +22,7 @@ runs tests in monkey as defined in a yaml file
# pylint: disable=locally-disabled, missing-docstring
import os
import sys
import getopt
import time
@ -232,18 +233,35 @@ def conds_met(ctx, conds):
def run_test_step_action_launch(ctx, step):
print(get_indent(ctx) + "Action: " + step["action"])
# ensure browser is not already launched
assert ctx.get('browser') is None
assert ctx.get('windows') is None
# build command line switches list
monkey_cmd = [ctx["monkey"]]
for option in step.get('launch-options', []):
monkey_cmd.append("--{}".format(option))
print(get_indent(ctx) + " " + "Command line: " + repr(monkey_cmd))
# build command environment
monkey_env = os.environ.copy()
for envkey, envvalue in step.get('environment', {}).items():
monkey_env[envkey] = envvalue
print(get_indent(ctx) + " " + envkey + "=" + envvalue)
if 'language' in step.keys():
monkey_env['LANGUAGE'] = step['language']
# create browser object
ctx['browser'] = DriverBrowser(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
quiet=True,
wrapper=ctx.get("wrapper"))
assert_browser(ctx)
ctx['windows'] = dict()
# set user options
for option in step.get('options', []):
print(get_indent(ctx) + " " + option)
ctx['browser'].pass_options(option)

View File

@ -75,7 +75,7 @@ class MonkeyFarmer(asyncore.dispatcher):
# pylint: disable=locally-disabled, too-many-instance-attributes
def __init__(self, monkey_cmd, online, quiet=False, *, wrapper=None):
def __init__(self, monkey_cmd, monkey_env, online, quiet=False, *, wrapper=None):
(mine, monkeys) = socket.socketpair()
asyncore.dispatcher.__init__(self, sock=mine)
@ -91,6 +91,7 @@ class MonkeyFarmer(asyncore.dispatcher):
self.monkey = subprocess.Popen(
monkey_cmd,
env=monkey_env,
stdin=monkeys,
stdout=monkeys,
stderr=monkeyserr,
@ -206,9 +207,10 @@ class Browser:
# pylint: disable=locally-disabled, too-many-instance-attributes, dangerous-default-value, invalid-name
def __init__(self, monkey_cmd=["./nsmonkey"], quiet=False, *, wrapper=None):
def __init__(self, monkey_cmd=["./nsmonkey"], monkey_env=None, quiet=False, *, wrapper=None):
self.farmer = MonkeyFarmer(
monkey_cmd=monkey_cmd,
monkey_env=monkey_env,
online=self.on_monkey_line,
quiet=quiet,
wrapper=wrapper)