运行 在 Python 中对 SeleniumBase 进行 pytest 时如何从其他函数获取输入变量?
How to get input variable from other function while running pytest for SeleniumBase in Python?
我上传到网站的文件随着每个 运行 的变化而变化,我想要一种在测试方法中改变它的方法。目前,我是这样设置的:
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)`
我想知道根据 functions.py 中某些函数的输出更改 file_path
变量的最佳方法。例如,它有时会生成一个名为 file1 的文件进行上传,或者有时会生成一个名为 file1 的文件 filet2.txt。将两个脚本和 运行 test_now() 与每个 运行 的更新文件路径连接起来的最佳方式是什么?还是应该以不同的方式设置它们?
在此先致谢。
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.)
来源:Docs
我上传到网站的文件随着每个 运行 的变化而变化,我想要一种在测试方法中改变它的方法。目前,我是这样设置的:
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)`
我想知道根据 functions.py 中某些函数的输出更改 file_path
变量的最佳方法。例如,它有时会生成一个名为 file1 的文件进行上传,或者有时会生成一个名为 file1 的文件 filet2.txt。将两个脚本和 运行 test_now() 与每个 运行 的更新文件路径连接起来的最佳方式是什么?还是应该以不同的方式设置它们?
在此先致谢。
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.)
来源:Docs