11import subprocess
2+ from copy import deepcopy
23import random
34import time
45import sys
1819from .tools import abort
1920from .tools import __assure_gitignore
2021from .tools import _get_available_robottests
22+ from .tools import _yamldump
2123from pathlib import Path
2224
2325ROBOT_UTILS_GIT = "marcwimmer/odoo-robot_utils"
@@ -428,6 +430,10 @@ def params():
428430
429431 return params
430432
433+ unique_robotname = f"robot_{ uuid .uuid4 ()} "
434+ # copy robot and seleniumdriver template to have an instance
435+ selenium_service_name = _clone_seleniumdriver_template (ctx , config , unique_robotname )
436+
431437 token = arrow .get ().strftime ("%Y-%m-%d_%H%M%S_" ) + str (uuid .uuid4 ())
432438 data = json .dumps (
433439 {
@@ -436,6 +442,7 @@ def params():
436442 "results_file" : results_file or "" ,
437443 "debug" : debug ,
438444 "params" : params (),
445+ "SELENIUM_SERVICE_NAME" : selenium_service_name ,
439446 }
440447 )
441448 data = base64 .b64encode (data .encode ("utf-8" )).decode ("utf8" )
@@ -458,14 +465,22 @@ def params():
458465 env = os .environ ,
459466 )
460467 else :
461- __dcrun (config , params , pass_stdin = data , interactive = True )
468+ try :
469+ Commands .invoke (ctx , "up" , daemon = True , machines = [selenium_service_name ])
470+ __dcrun (config , params , pass_stdin = data , interactive = True )
471+ finally :
472+ # ensure that the seleniumdriver is stopped
473+ Commands .invoke (ctx , "kill" , machines = [selenium_service_name ])
474+ Commands .invoke (ctx , "remove" , machines = [selenium_service_name ])
475+ click .secho (
476+ f"Stopped seleniumdriver { selenium_service_name } container" ,
477+ fg = "yellow" ,
478+ )
462479 del data
463480
464481 output_path = config .HOST_RUN_DIR / "odoo_outdir" / "robot_output"
465482 from .robo_helpers import _eval_robot_output
466483
467- Commands .invoke (ctx , "restart" , machines = ["seleniumdriver" ])
468-
469484 res = _eval_robot_output (
470485 config ,
471486 output_path ,
@@ -477,6 +492,16 @@ def params():
477492 )
478493 return res
479494
495+ def _clone_seleniumdriver_template (ctx , config , appendix ):
496+ import yaml
497+ yml = yaml .safe_load (open (config .files ['docker_compose' ], "r" ))
498+
499+ service_name = f"seleniumdriver_{ appendix } "
500+ yml ['services' ][service_name ] = deepcopy (yml ['services' ]['seleniumdriver_template' ])
501+ yml ['services' ][service_name ]['container_name' ] = service_name
502+ config .files ['docker_compose' ].write_text (_yamldump (yml ))
503+ return service_name
504+
480505
481506def _prepare_fresh_robotest (ctx ):
482507 click .secho ("Preparing fresh robo test." , fg = "yellow" )
0 commit comments