自动化框架在本地跑都正常,文件也都读取得到,但部署到Jenkins时却报了以下错误:
Jenkins错误2.jpg
分析原因:
代码中是通过以下方式获取路径:
protected static String projectPath = System.getProperty("user.dir");
protected static String filePath = projectPath + "//files//UI自动化初始数据.xls";
解决方法:
将maven配置中的workingDirectory内容由target/改为.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<workingDirectory>.</workingDirectory>
<forkMode>always</forkMode>
</configuration>
</plugin>