java - JBehave Restful : How to manage baseURL and relative URLs?

标签 java maven-3 jbehave serenity-bdd

我是 Serenity 的新手,我了解到我们可以从命令行更改默认 URL。

这就是我声明默认 URL 的方式

@DefaultUrl("http://en.wiktionary.org/wiki/Wiktionary")
public class DictionaryPage extends PageObject {


}

但是对于每个页面,如果我继续像这样声明 URL,我最终会失去声明默认 URL 的概念。

我正在寻找的是我只是在某处指定默认 URL 并提供如下的相对页面 URL:

@DefaultUrl($baseURL+"/wiki/Wiktionary")
public class DictionaryPage extends PageObject {


}

我怎样才能实现这个目标?

serenity.properties 如下所示:

# Define the default driver
#webdriver.driver=phantomjs
# Appears at the top of the reports
serenity.project.name = Demo Project using Serenity and JBehave
serenity.restart.browser.for.each = NEVER
# Root package for any JUnit acceptance tests
#serenity.test.root=net.thucydides.showcase.junit.features
# Customise your requirements hierarchy
#serenity.requirement.types=feature, story
# Run the tests without calling webdriver - useful to check your JBehave wireing
#serenity.dry.run=true
# Customise browser size
#serenity.browser.height = 1200
#serenity.browser.width = 1200

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.testing.browser</groupId>
    <artifactId>browser-tests</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Sample Serenity project using JBehave and WebDriver</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>1.8.3</serenity.version>
        <serenity.jbehave.version>1.34.0</serenity.jbehave.version>
        <webdriver.driver>firefox</webdriver.driver>
    </properties>

    <repositories>
      <repository>
        <snapshots>
        <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <snapshots>
        <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>bintray-plugins</name>
        <url>http://jcenter.bintray.com</url>
      </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-jbehave</artifactId>
            <version>${serenity.jbehave.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/*TestSuite.java</include>
                        <include>**/Test*.java</include>
                        <include>**/When*.java</include>
                    </includes>
                    <argLine>-Xmx512m</argLine>
                    <systemPropertyVariables>
                        <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    </systemPropertyVariables>
                </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.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

最佳答案

在 serenity.properties 文件中输入以下属性

webdriver.base.url = http://en.wiktionary.org

在页面对象中定义 DefaultUrl,如下所示

@DefaultUrl("/wiki/Wiktionary")
public class DictionaryPage extends PageObject {


}

Serenity 将在调用 DefaultUrl 时构建完整的 URL。

有关 serenity.properties 中所有可用属性的更多引用,请参阅下面的链接 https://github.com/serenity-bdd/serenity-documentation/blob/master/src/asciidoc/system-props.adoc

关于java - JBehave Restful : How to manage baseURL and relative URLs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52810885/

相关文章:

java - 无法启动 Java ME 设备选择器

java - Android Studio 在运行时不提示设备

java - 从 Maven 构建中排除测试

Jbehave 在@BeforeStory 中获取故事名称

java - 如何在android中的同一 Activity 上对4个不同端点进行4个不同的调用并将累积结果传递给适配器

java - 在 assembly-plugin 构建(具有依赖性)jar 中包含 Maven 配置文件名称

java - Maven 找不到本地安装的 Artifact ,该 Artifact 仅存在于本地安装

java - JBehave Maven RunningStoriesFailed 异常

JBehave - 示例表正在执行注释

java - 另一个属性键中使用的 Spring-boot 属性值