定义一个类,用来 获取到 各种路径:工程路径、截图保存的路径、测试报告存放的路径、测试用例所在的路径
时间: 2023-08-19 08:03:58 浏览: 38
好的,以下是一个示例类,可以获取工程路径、截图保存路径、测试报告存放路径和测试用例所在路径:
```python
import os
class PathUtil:
@staticmethod
def get_project_path():
"""
获取工程路径
:return: 返回工程路径
"""
return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
@staticmethod
def get_screenshot_path():
"""
获取截图保存路径
:return: 返回截图保存路径
"""
path = os.path.join(PathUtil.get_project_path(), "screenshots")
if not os.path.exists(path):
os.makedirs(path)
return path
@staticmethod
def get_report_path():
"""
获取测试报告存放路径
:return: 返回测试报告存放路径
"""
path = os.path.join(PathUtil.get_project_path(), "reports")
if not os.path.exists(path):
os.makedirs(path)
return path
@staticmethod
def get_case_path():
"""
获取测试用例所在路径
:return: 返回测试用例所在路径
"""
return os.path.join(PathUtil.get_project_path(), "testcases")
```
你可以使用 `PathUtil.get_project_path()` 来获取工程路径,使用 `PathUtil.get_screenshot_path()` 来获取截图保存路径,使用 `PathUtil.get_report_path()` 来获取测试报告存放路径,使用 `PathUtil.get_case_path()` 来获取测试用例所在路径。当然,你可以根据实际情况修改类中的目录结构。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)