元素匹配引起的宁静错误

时间:2018-04-13 06:42:00

标签: java pom.xml serenity-bdd

我正在使用宁静进行我放心的测试,我在测试中遇到以下错误:

ERROR net.serenitybdd.core.Serenity - net/bytebuddy/matcher/ElementMatcher

现在,如果我在班上使用以下代码,它就可以了:

@Test
    public void getAllStudents(){
        RestAssured.given()
        .when()
        .get("/list")
        .then()
        .log()
        .all()
        .statusCode(200);
    }

但是,当我将RestAssured.given()更改为SerenityRest.given()并重新运行测试时,我收到了错误消息。如何解决这个错误?

以下是我班级的完整代码:

@RunWith(SerenityRunner.class)
public class FirstSerenityTest {

    @BeforeClass
    public static void init() {
        RestAssured.baseURI="http://localhost:8080/student";
    }


    @Test
    public void getAllStudents(){
        SerenityRest.given()
        .when()
        .get("/list")
        .then()
        .log()
        .all()
        .statusCode(200);
    }

}

下面是我的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>StudentApp</groupId>
  <artifactId>StudentApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<name>StudentApp Serenity BDD</name>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>1.4.1-rc.6</serenity.version> <!-- https://bintray.com/serenity/maven/serenity-core/ -->
        <serenity.maven.version>1.4.1-rc.6</serenity.maven.version>
        <serenity.cucumber.version>1.1.6</serenity.cucumber.version> <!-- https://bintray.com/serenity/maven/serenity-cucumber/ -->
    </properties>

    <!-- Define the Bintray repos for convenience -->
    <repositories>
        <repository>
            <id>serenity</id>
            <name>bintray</name>
            <url>http://dl.bintray.com/serenity/maven</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>serenity</id>
            <name>bintray-plugins</name>
            <url>http://dl.bintray.com/serenity/maven</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-rest-assured</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>${serenity.cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.8.6</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.lambdaj</groupId>
            <artifactId>lambdaj</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>1.7.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>enforce</id>
                        <configuration>
                            <rules>
                                <requireUpperBoundDeps />
                            </rules>
                        </configuration>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                    <includes>
                        <include>**/studentapp/**/*.java</include>
                    </includes>
                    <forkCount>4</forkCount>
                    <reuseForks>true</reuseForks>
                    <!-- <parallel>methods</parallel>  -->
                    <!-- <threadCount>10</threadCount>   --> 
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
         <source>1.8</source>
        <target>1.8</target>
          <verbose>true</verbose>
          <fork>true</fork>
          <compilerVersion>1.3</compilerVersion>
        </configuration>
      </plugin> 
      -->           
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.maven.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-core</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build> 
</project>

谢谢,

2 个答案:

答案 0 :(得分:0)

尝试使用更新版本的Serenity(最新版本为1.9.7)。

答案 1 :(得分:0)

通过在选择更新我的maven项目时更新快照/版本来解决此问题