【发布时间】:2018-08-31 20:25:26
【问题描述】:
我的 Appium + JUnit 测试在本地运行良好,但在 aws 上找不到属性文件。我的测试放在src/test/java 下,测试中使用的属性文件放在src/test/resources/locale 下。
压缩依赖内容:
├── app-0.1-tests.jar
├── app-0.1.jar
└── dependency-jars
├── ...
app-0.1-tests.jar内容:
├── META-INF
│ ├── MANIFEST.MF
│ ├── maven
│ ├── ....
├── com
│ ├── ....
└── locale
├── en_EN.properties
不幸的是,当我尝试加载属性文件时,我遇到了 IOException - 在以下位置找不到文件:
file:/tmp/scratchcC4yMz.scratch/test-packagefQ2euI/app-0.1-tests.jar!/locale/en_EN.properties
我尝试以几种方式加载它们,每次都遇到同样的问题。在当地,一切都像魅力一样。代码示例:
File file = new File(ClassName.class.getResource("/locale/en_EN.properties").getPath());
try (InputStream inputStream = new FileInputStream(file.getPath());
InputStreamReader streamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"))) {
Properties properties = new Properties();
properties.load(streamReader);
return properties;
} catch (IOException e) {
System.err.println("Properties file not found: " + file.getPath());
}
或使用类加载器:
ClassLoader classLoader = getClass().getClassLoader();
URL resource = classLoader.getResource("/locale/en_EN.properties");
有人可以提出解决方案如何读取位于资源中的属性文件吗?
【问题讨论】:
-
我没有复制这个,但我认为问题出在语言环境前面的 / 上。你能把它改成:classLoader.getResource("locale/en_EN.properties");让我知道这有帮助吗?
-
您可以做一件事来确定它在哪里,将 /tmp/ 放在要提取哪些文件的主机输入中。您应该在“指定设备状态”页面上看到这一点。然后,您将在客户工件下载的 tmp 目录中获得所有内容的 zip
-
@jmp 前面没有额外的 /
getResource返回 null,因此它不起作用。你能扩展你的第二个想法吗?我不确定如何进入 aws 设备场中的指定设备 tmp 文件夹。
标签: amazon-web-services junit appium aws-device-farm