Send parameter into send_keys?

Viewed 18

Want to use send_keys in Selenium 4.3. Using Behave + Python. To send a parameter into a build via Jenkins.

I have looked into step parameters with Behave and they seem like they are in the realm of what I want to do ( https://www.tutorialspoint.com/behave/behave_step_parameters.htm ). However, my goal is for the "user" to type in a parameter for lets say Printer ID#. They would do this in Jenkins by building with parameter. Then that parameter would be passed into the code to be used.

Something like this:

enter image description here

Sounds like it should be possible but what is the best practice to do this?

1 Answers

A workaround that was able to work as a solution:

In a new file createParams.py

arg1 = sys.argv[1]
arg2 = sys.argv[2] 
pathToFile = r'C:\filePathGoesHere'
newPath = Path(pathToFile)
newfile = newPath / "nameOfFile.txt"
#IF Statement needs to go here to make sure your not clearing contents when behave command is ran
if not newPath.is_file(): 
     with open(newfile, 'w') as makeTxtFile: 
           makeTxtFile.write(f'{arg1}\n{arg2}')

Once the configuration is done in Jenkins and the parameters have been added as strings. Call it with createParams.py {arg1} {arg2} before the behave command. The behave command will run it again so implement some logic to not wipe your new txt file.

Related