The file I upload to a website changes with each run, and I'd like a way to change it in the test method. Currently, I have it set up like this:
functions.py
def get_file():
...
file = file_ex1.doc
return file
def run_test1():
cmd = "pytest -v webtests.py::EF --browser=chrome"
subprocess.run(split(cmd)) # run command line
...
webtests.py
file_path = file # changes with each run, should come from get_file()
class EF(BaseCase):
def test_now(self):
self.open('https://www...')
self.find_element('input[name="Query"]').send_keys(file_path)`
I was wondering about the best way to change the file_path
variable based on the output of certain functions in functions.py. For example, it could sometimes produce a file called file1 to upload, or another time filet2.txt. What's the best way to connect the two scripts and run test_now() with the updated file path for each run? Or should they be set up in a different way?
Thanks so much in advance.
You can use the pytest args that come with SeleniumBase.
--data=DATA # (Extra test data. Access with "self.data" in tests.)
--var1=DATA # (Extra test data. Access with "self.var1" in tests.)
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
Source: Docs