构建pom

时间:2016-04-01 11:38:46

标签: maven maven-3 serenity-bdd

我试图运行该项目的示例但未成功(编译项目的问题)。以下是此项目的链接https://github.com/serenity-bdd/serenity-demos/tree/master/jbehave-webtests 现在我正在尝试创建一个简单的项目来学习如何将Serenity与Jbehave一起使用,但是我有创建pom.xml的问题。我的pom是根据这个项目https://github.com/serenity-bdd/serenity-demos/tree/master/junit-webtests(我知道它不是最好的解决方案)。我在Maven不是很好。这是我的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>serenity-maven-jbehave</groupId>
  <artifactId>imdb</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <serenity.version>1.1.25-rc.3</serenity.version>
    <serenity.maven.version>1.1.25-rc.3</serenity.maven.version>
          <serenity.jbehave.version>1.8.0</serenity.jbehave.version>
    <webdriver.driver>firefox</webdriver.driver>
</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>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.3</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>3.1.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>core</artifactId>
        <version>1.0.47</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jbehave</artifactId>
        <version>1.8.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <parallel>classes</parallel>
                <threadCount>5</threadCount>
            </configuration>
        </plugin>
         <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18</version>
            <configuration>
                <includes>
                    <include>src/main/java/*.java</include>
                </includes>
            </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.maven.version}</version>
            <dependencies>
                <dependency>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-core</artifactId>
                    <version>1.1.25-rc.3</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是HomePage。

package pages;

import org.openqa.selenium.WebElement;

import net.serenitybdd.core.annotations.findby.By;
import net.serenitybdd.core.annotations.findby.FindBy;
import net.serenitybdd.core.pages.PageObject;
import net.thucydides.core.annotations.DefaultUrl;

@DefaultUrl("https://www.imdb.com")
public class HomePage extends PageObject {

    @FindBy(xpath="#navUserMenu.css_nav_menu.js_nav_item")
    WebElement downArrowButton;

    @FindBy(css="#first_name.reg_thick")
    WebElement firstNameInput;

    @FindBy(css="#last_name.reg_thick")
    WebElement lastNameInput;

    @FindBy(css="#year.reg_thick")
    WebElement yearOfBirthInput;

    @FindBy(css="#gender_m.reg_radio")
    WebElement genderMaleRadioButton;

    @FindBy(css="#postal.reg_thick")
    WebElement zipPostalCodeInput;

    @FindBy(css="#email.reg_thick")
    WebElement emailInput;

    @FindBy(css="#password1.reg_thick")
    WebElement passwordInput;

    @FindBy(css="#password2.reg_thick")
    WebElement passwordConfirmInput;

    @FindBy(css="div.reg_right input.btn2.large.primary")
    WebElement RegisterButton;

    public static String userName;  

    public void showMoreOptions(){
        WebElement downArrow = getDriver().findElement(By.cssSelector("div[id='nb_personal'] span[class='downArrow']"));
        downArrow.click();
    }

    public void clickRegisterButton() {
        WebElement register = getDriver().findElement(By.linkText("Register"));
        register.click();
    }

    public void fillRequiredFields(String firstName, String lastName, String email, String password) throws InterruptedException {
        firstNameInput.sendKeys(firstName);
        lastNameInput.sendKeys(lastName);
        String yearOfBirth= String.valueOf(randomWithRange(1950, 1999));
        yearOfBirthInput.sendKeys(yearOfBirth);
        genderMaleRadioButton.click();
        String zipPostalCode = String.valueOf(randomWithRange(10000, 99999));
        zipPostalCodeInput.sendKeys(zipPostalCode);
        userName= "usermail" + System.currentTimeMillis();
        email = userName + "@mailinator.com";
        emailInput.sendKeys(email);
        passwordInput.sendKeys(password);
        passwordConfirmInput.sendKeys(password);
        RegisterButton.click();
        Thread.sleep(5000);
    }

    public int randomWithRange(int min, int max) {
        int range= (max-min) +1; 
        return (int) ((Math.random() * range) + min);
    }
}

这是ImdbSteps

package steps;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

import net.thucydides.core.annotations.Steps;
import net.thucydides.core.steps.ScenarioSteps;
import pages.HomePage;

public class ImdbSteps extends ScenarioSteps {

    private static final long serialVersionUID = 1L;

    @Steps
    HomePage homePage;

    @Given("I am on the imdb site")
    public void userWantsVisitSite() {
        homePage.open();
    }

    @When ("I am cliking on register button")
    public void userIsClickingRegisterButton() {
        homePage.showMoreOptions();
        homePage.clickRegisterButton();
    }

    @Then ("I am filling required fields")
    public void userIsFillingRequiredFields(String firstName, String lastName, String email, String password) throws InterruptedException {
        homePage.fillRequiredFields(firstName, lastName, email, password);
    }
}

编辑: 我应该如何基于上面的代码构建pom.xml?我尝试使用链接belove中的指令构建此pom.xml http://thucydides.info/docs/serenity-staging/#introduction 但我没有成功。

有人可以给我一个使用Serenity,Jbehave和Maven的可行项目的链接吗?或者任何线索如何解决这个问题。提前谢谢。

0 个答案:

没有答案