栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用IntelliJ从Selenium / TestNG Java文件制作可执行jar文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用IntelliJ从Selenium / TestNG Java文件制作可执行jar文件?

我终于找到了碰巧遇到这个问题的其他人的方法,这就是我如何创建jar文件并成功运行它的方法。

我必须将pom.xml文件更改为以下内容:

<groupId>TestAutomation</groupId><artifactId>TestAutomation</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><url>http://maven.apache.org</url><build>    <plugins>        <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>        </plugin>        <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration>     <archive>         <manifest>  <addClasspath>true</addClasspath>  <mainClass>com.test.automation.Executable</mainClass>         </manifest>     </archive> </configuration>        </plugin>        <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId>        </plugin>    </plugins></build><dependencies>    <dependency>        <groupId>org.seleniumhq.selenium</groupId>        <artifactId>selenium-java</artifactId>        <version>2.40.0</version>    </dependency>    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.11</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.testng</groupId>        <artifactId>testng</artifactId>        <version>6.1.1</version>        <scope>test</scope>    </dependency></dependencies>

然后,我不得不调整我的主要方法,以不使用任何与TestNG相关的调用。例如,我不能将以下内容用于我的主要方法:

    TestListenerAdapter tla = new TestListenerAdapter();    TestNG testng = new TestNG();    testng.setTestClasses(new Class[] {WordProfFonts2Set0.class});    testng.addListener(tla);    testng.run();

最后,以下是创建适当的jar文件的步骤:

  1. 从顶部菜单中选择文件>项目结构…
  2. 在左侧菜单上选择“工件”,然后单击“ +”
  3. 选择Jar>来自具有依赖性的模块…
  4. 使用浏览按钮选择您的主要班级
  5. 单击“提取到目标jar”旁边的单选按钮,然后单击“确定”。
  6. 单击“ +”,然后选择“模块测试输出”
  7. 在右侧的“可用元素”窗格中,展开项目名称并选择所有Maven文件,然后将它们移动到在左窗格中创建的jar目录中。
  8. 点击“确定”
  9. 从顶部菜单中选择Build> Build Artifacts …
  10. 将鼠标悬停在创建的jar上,然后在“操作”下单击“构建”

笔记:

  1. 确保将IE或Chrome驱动程序添加到您的项目资源文件夹中,并通过代码文件夹而不是计算机的硬盘驱动器进行调用。例如,执行以下操作:

文件文件=新文件(“ src test resources binaries IEDriverServer.exe”);

不是这个:

File file = new File("C:\Users\<Username>\<Proj Name>\src\test\java\src\  test\resources\binaries\IEDriverServer.exe");

然后在将jar保存到计算机的同一文件夹中,创建具有驱动程序的相同目录:

srcTestAutomation.jar

2。如果使用IE,请确保为所有区域或全部区域都未设置保护模式(在IE中,转到“ Internet选项…”>“安全性”(选项卡)>“启用保护模式”复选框)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570574.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号