使用maven

问题描述 投票:0回答:1

java seleniumtestngtestmyxmlfile.xml

是否可以避免上面写的不同设置?我们可以使用Java调用JAR的测试测试吗? Firefox可以从罐子文件中运行吗?

Edit1:评论中的一个很好的建议是将我的来源迁移到一个Maven项目。但是仍然存在同样的问题。 Maven能够管理需要我的测试项目的设置吗? (这是硒罐,Java 8库,Testng Jar并运行Firefox浏览器)

最终我没有使用Maven,我只是在项目中创建了一个主。主要将调用testng套件,该套件在XML文件中所传递的XML文件中指定。此方法将使我可以从罐子中执行测试而不关心外部库(库testng和selenium已经在内部)。

如果可以帮助任何人,则主要代码:

public class Runner { public static void main(String[] args) throws IOException { if(args.length != 2) { System.out.println("Usage : <xmlFile> <OutputFileName>"); System.exit(-1); } Path path = Paths.get(args[0]);//Path to the xml new PrintWriter(args[1]).close(); Charset charset = StandardCharsets.UTF_8; String content = new String(Files.readAllBytes(path), charset); content = content.replaceAll("theOutputFileNamePattern", args[1]); Files.write(path, content.getBytes(charset)); //We create a testNG object to run the test specified in the xml file TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = new TestNG(); List<String> suites = Lists.newArrayList(); suites.add(args[0]); testng.setTestSuites(suites); testng.run(); } }

java eclipse maven selenium testng
1个回答
1
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.