damies13 / rfswarm

Robot Framework Swarm
GNU General Public License v3.0
112 stars 22 forks source link

Support for Environment Variable Substitution in Resources for rfswarm-manager #165

Closed Anker101 closed 2 months ago

Anker101 commented 1 year ago

Is your feature request related to a problem? Please describe. The current issue pertains to the inability of rfswarm-manager to support environment variable substitution in resources, causing constraints in my robot framework test automation workflow.

Describe the problem In my robot framework script (.robot), I utilize a Resource path, for instance, "../main.resource." Within the main.resource file, there is a resource defined as follows:

Resource %{RF_DIRECTORY}${/}folder${/}file.resource

Despite my attempts to set the value of the RF_DIRECTORY variable before running rfswarm-manager, it seems that the manager does not recognize or use this variable during test execution. I have also explored the use of robotoptions with -v RF_DIRECTORY=/path/to/RF/directory/, but it did not resolve the issue.

Describe the solution you'd like I am proposing an enhancement to rfswarm-manager to include support for environment variable substitution. Specifically, I would like rfswarm-manager to recognize and properly resolve variables like %{RF_DIRECTORY} when referenced within robot framework scripts.

Describe alternatives you've considered While grappling with this issue, I contemplated an alternative : Manually replacing environment variables in resource paths before running tests. This approach is error-prone and not scalable.

Additional context Add any other context or screenshots about the feature request here.

From Discord channel

damies13 commented 1 year ago

Hi @Anker101,

I have some questions about this: 1) If I understand correctly environment variables always start with %{ in robot framework, so I can use that to identify them? 2) I can make the manager evaluate the environment variable on the machine that the manager is running on, which will be fine for evaluating the robot file and identifying which files need to be transferred to the agent, the question is how to make sure the agent will have an appropriate value for this environment variable or if this environment variable even exists on the agent?

I'm leaning towards just evaluating the value when assessing the files to be transferred to the agent but not attempting to ensure the agents have this environment variable set, but would be interested in your feed back.

Something to remember the manager never runs robot framework, in fact there is no requirement to even have robot framework installed on the manager machine only on the agent machine. as such the manager needs to be updated to know how to evaluate variables, In this case the operating system environment variables should be easy enough to implement but I don't expect to be able to implement all possible variables in robot framework. I'm happy to implement this feature request as long as it's limited to just environment variables.

Anker101 commented 1 year ago

Hi @damies13 1 ) Yes, in Robot Framework, environment variables typically start with %{, so using this pattern to identify them should work effective 2) With an export RF_DIRECTORY done before executing the manager 3) I think it is more stable to make the manager tell the agents to create this variable

Hope it helps

Regards

damies13 commented 1 year ago

3) I think it is more stable to make the manager tell the agents to create this variable

Maybe I tell the agent to create it if it doesn't exist, that way we don't override it if it does exist, that would resolve the concern.

Another option might be add an option in the manager UI to tell the agent whether to create the variable or not.

damies13 commented 2 months ago

Hmmm maybe this is part of the solution:

import re

#Return a list containing every occurrence of "ai":

txt = "%{RF_DIRECTORY}${/}folder${/}file.resource"
x = re.findall("%{([^}]+)}", txt)
print(x)
damies13 commented 2 months ago

Fixed linter issues and merged into v1.4.0 branch