Selenium Cucumber Java 项目教程
selenium-cucumber-javaBehavior driven development (BDD) approach to write automation test scripts to test web applications.项目地址:https://gitcode.com/gh_mirrors/se/selenium-cucumber-java
1. 项目的目录结构及介绍
selenium-cucumber-java/
├── src/
│ ├── test/
│ │ ├── java/
│ │ │ ├── com/
│ │ │ │ ├── example/
│ │ │ │ │ ├── RunCucumberTest.java
│ │ │ │ │ ├── StepDefinitions.java
│ │ │ │ │ └── ...
│ │ │ └── ...
│ │ └── resources/
│ │ ├── features/
│ │ │ ├── example.feature
│ │ │ └── ...
│ │ └── ...
│ └── main/
│ ├── java/
│ │ └── ...
│ └── resources/
│ └── ...
├── pom.xml
└── README.md
- src/test/java/: 包含测试相关的Java代码,如步骤定义、测试运行器等。
- src/test/resources/: 包含测试资源文件,如Cucumber的
.feature
文件。 - src/main/: 包含项目的主要代码和资源文件。
- pom.xml: Maven项目的配置文件。
- README.md: 项目说明文档。
2. 项目的启动文件介绍
RunCucumberTest.java
package com.example;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "com.example"
)
public class RunCucumberTest {
}
- @RunWith(Cucumber.class): 指定使用Cucumber运行测试。
- @CucumberOptions: 配置Cucumber的选项,如特征文件路径和步骤定义的包路径。
3. 项目的配置文件介绍
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>selenium-cucumber-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.10.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
- dependencies: 定义项目依赖的库,如Cucumber、Selenium和JUnit。
- build: 配置Maven构建
selenium-cucumber-javaBehavior driven development (BDD) approach to write automation test scripts to test web applications.项目地址:https://gitcode.com/gh_mirrors/se/selenium-cucumber-java