JBehave Serenity:如何管理基本URL和相对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

绒球.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

更重要的是,我认为您可以在页面对象中使用别名,如下所示:

@DefaultUrl("/wiki/Wiktionary")
@NamedUrls({
@NamedUrl(name = "glossary", url = "/wiki/Appendix:Glossary"),
@NamedUrl(name = "community_portal", url = "/wiki/Wiktionary:Community_Portal")
})
public class DictionaryPage extends PageObject {}

并在您的步骤中使用它们:

public class EndUserSteps {
DictionaryPage dictionaryPage;
@Step
public void navigatesUsingDeepLink() {
dictionaryPage.open("productId_1");
}
}

最新更新