java - 我们应该在 java 测试文件夹还是主文件夹中编写 testng selenium 代码?
问题描述
我正在编写一组硒测试,我想构建一个 jar 并在 docker 上运行,我正在做一个基于 maven 的项目。
在大多数视频教程中,我看到这些测试都写在 test 文件夹中。但在这种情况下,它会构建到 jar 文件中,我是否能够执行这些文件?
测试 selenium 项目的合适文件夹结构是什么?
解决方案
是的,它将基于您的 pom.xml 构建配置。
<build>
<finalName>testProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
最后一节特别告诉 maven 包含测试类[您在哪里编写测试脚本]并构建测试 jar。
你可以通过写来执行它,
java -cp testProject.jar:testProject-tests.jar:libs/*<other parameters like testNG suite or host etc>
当我使用页面对象框架时,我更喜欢将Page类src->main
和Test类分开编写src-test
推荐阅读
- java - Java,如何通过 1 个大类合并较小的类?
- python - specify a first column when exporting csv using pandas
- haskell - groupBy 功能有问题
- android - Google 提供的 asn1 定义是否有效?
- html - html表重置所有默认css
- android - 尝试在 RecyclerView 中使用 onClick 并不起作用
- terraform - 在 Terragrunt 中应该如何声明全局资源?
- python - 用于有条件地提取重复项的 Python 代码
- asp.net-core - 使用 Auth0 进行身份验证的 Blazor SPA 在回调时失败
- python - 比较两个不同格式的列表