【问题标题】:File not reading in selenium - maven framewaork文件未在 selenium 中读取 - maven 框架
【发布时间】:2017-03-31 19:33:34
【问题描述】:

我尝试创建一个快速框架。因为我创建了下面提到的类:

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

现在它没有读取 config.properties 文件中提到的路径。

我已提供所有正确路径并附上截图:

【问题讨论】:

  • 发布文本。图片难以阅读或无法阅读,无法搜索。
  • @megha 你的问题解决了吗?

标签: java maven selenium


【解决方案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 执行的测试。

框架的核心可能如下所示:

【讨论】:

    【解决方案2】:

    我注意到的两件事:

    1. 不要在"" 内的属性路径中提供路径
    2. 所有路径分隔符应替换为双反斜杠\\或单正斜杠/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-05
      • 2013-01-20
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 2013-12-12
      • 2013-01-20
      • 1970-01-01
      相关资源
      最近更新 更多