2017-03-31 61 views
-1

我试图创建一个快速框架。在我创建后述的类:在硒中读取文件 - maven framewaork

  • 配置文件(所有浏览器路径)
  • configDataProvider java类(读取上述文件)
  • BrowserFactory类(具有火狐浏览器对象)
  • configDataProviderTest类(从dconfigDataProvider类访问数据)

现在它不是读config.properties文件中提到的路径。

我已经提供了所有正确的路径和附截图:Config fileconfigDataProviderBrowserFactoryconfigDataProviderTest

+3

Post * text *。图像很难或无法阅读,无法搜索。 – chrylis

回答

1

看起来像一个问题,就是在你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执行。

您框架的核心可以是这样的:我注意到

enter image description here

0

两件事情:

  1. 没有在""
  2. 全部给路径在属性路径路径分离器应替换为双向反斜杠\\或单斜杠/