JBehave Serenity: Как управлять baseURL и относительными URL-адресами? - PullRequest
0 голосов
/ 15 октября 2018

Я новичок в 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>

Ответы [ 2 ]

0 голосов
/ 06 августа 2019

Более того, я думаю, вы можете использовать псевдонимы в объекте страницы следующим образом:

@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");
    }
}
0 голосов
/ 10 января 2019

Введите следующее свойство в файле serenity.properties

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

В объекте вашей страницы определите DefaultUrl следующим образом

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


}

Serenity создаст полный URL-адрес при вызове DefaultUrl.

Для получения дополнительной информации по всем свойствам, доступным в serenity.properties, перейдите по ссылке ниже https://github.com/serenity-bdd/serenity-documentation/blob/master/src/asciidoc/system-props.adoc

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...