我试图创建一个快速框架。在我创建后述的类:在硒中读取文件 - maven framewaork
- 配置文件(所有浏览器路径)
- configDataProvider java类(读取上述文件)
- BrowserFactory类(具有火狐浏览器对象)
- configDataProviderTest类(从dconfigDataProvider类访问数据)
现在它不是读config.properties文件中提到的路径。
我试图创建一个快速框架。在我创建后述的类:在硒中读取文件 - maven framewaork
现在它不是读config.properties文件中提到的路径。
看起来像一个问题,就是在你ConfigDataProvider
类。
首先,您使用Maven构建您的项目。 Maven的定义项目结构代码源和资源:
/src/main/java
/src/main/resorces
因此,更好的把你的.properties
文件存在。
第二个,你不需要设置你的配置文件的完整路径。
相对路径就够了。类似下面:
public class PropertiesFileHandler {
private static Logger log = Logger.getLogger(PropertiesFileHandler.class);
public static final String CONFIG_PROPERTIES = "src/main/resources/config.properties";
public static final String KEY = "browser.type";
public static BrowserType readBrowserType() {
BrowserType browserType = null;
Properties properties = new Properties();
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(CONFIG_PROPERTIES))) {
properties.load(inputStream);
browserType = Enum.valueOf(BrowserType.class, properties.getProperty(KEY));
} catch (FileNotFoundException e) {
log.error("Properties file wasn't found - " + e);
} catch (IOException e) {
log.error("Problem with reading properties file - " + e);
}
return browserType;
}
}
最后,如果你正在建设框架,你不需要把一切src/main/test
下。该路径规定了将来可能性的测试使用maven default lifecycle - mvn test
执行。
您框架的核心可以是这样的:我注意到
两件事情:
""
\\
或单斜杠/
Post * text *。图像很难或无法阅读,无法搜索。 – chrylis