java - JBehave Serenity:如何管理 baseURL 和相对 URL?
问题描述
我是 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
推荐阅读
- python - 从其他模型(不是模型实例)返回外键模型
- java - 当我的文件确实存在时获取文件未找到异常
- c# - 如何在 Android 中停止 UnityWebRequest 下载?
- kubernetes - 使用 Kubernetes Engine 进行 Vault 身份验证的 Kubernetes 主机 IP
- mysql - Laravel 选择 Raw 进入 Moloquent 查询
- google-sheets - 如何在过滤函数中使用单元格变量
- javascript - 如何使用 JQuery 删除动态表的特定行
- php - 使用应用程序登录保护上传的公共文件
- datepicker - 如何在 SwiftUI 中更改 DatePicker 的文本颜色?
- python - 如何将列表转换为具有数组中元素特定顺序的数组