简体   繁体   English

如何在maven项目的Cucumber测试中运行GlassFish和Selenium?

[英]How can I run GlassFish and Selenium under the Cucumber test in maven project?

如何在POM文件中一起映射所有内容?

pom: pom:

 <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>pl.cucumber.test</groupId>
            <artifactId>cucumber-with-glassfish</artifactId>
            <version>1.0.0</version>

            <properties>
                <jdk.version>1.7</jdk.version>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <cucumber.version>1.1.3</cucumber.version>
                <junit.version>4.11</junit.version>
                <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
                <maven-surefire-plugin.version>2.14.1</maven-surefire-plugin.version>
                <cargo-maven2-plugin.version>1.4.0</cargo-maven2-plugin.version>
                <glasfish.port>8080</glasfish.port>
                <glasfish.home>${project.build.directory}/glasfish</glasfish.home>
                <selenium.version>2.32.0</selenium.version>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>info.cukes</groupId>
                    <artifactId>cucumber-java</artifactId>
                    <version>${cucumber.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>info.cukes</groupId>
                    <artifactId>cucumber-junit</artifactId>
                    <version>${cucumber.version}</version>
                    <scope>test</scope>
                </dependency>

                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>${junit.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                    <scope>test</scope>
                    <version>${selenium.version}</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>${maven-compiler-plugin.version}</version>
                        <configuration>
                            <source>${jdk.version}</source>
                            <target>${jdk.version}</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${maven-surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>integration-test</id>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <version>${cargo-maven2-plugin.version}</version>
                        <configuration>
                            <container>
                                <containerId>glassfish3x</containerId>
                                <zipUrlInstaller>
                                    <url>http://dlc.sun.com.edgesuite.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2.zip</url>
                                    <downloadDir>${basedir}/downloads</downloadDir>
                                </zipUrlInstaller>
                                <output>${project.build.directory}/container.log</output>
                                <append>false</append>
                                <log>${project.build.directory}/cargo.log</log>
                                <systemProperties>
                                    <mySystemProperty>value</mySystemProperty>
                                </systemProperties>
                            </container>
                            <configuration>
                                <home>${glasfish.home}</home>
                                <properties>
                                    <cargo.servlet.port>${glasfish.port}</cargo.servlet.port>
                                    <cargo.logging>medium</cargo.logging>
                                </properties>
                            </configuration>
                            <!--
                            <deployables>
                                 <deployable>
                                                      <groupId>pl.cucumber.warproject</groupId>
                                                      <artifactId>warproject</artifactId>
                                                      <version>1.0</version>
                          <type>war</type>
                                   <properties>
                                     <context>mycontext</context>
                                  </properties>
                                </deployable>
                            </deployables>
                             -->
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-container</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </project>

RunIT: 运行:

@RunWith(Cucumber.class)
public class RunIT {
    //
}

TestTitlePages: TestTitlePages:

public class TestTitlePages {

    private WebDriver driver;

    @Given("^Connect to the given address$")
    public void a_User_has_no_money_in_their_current_account() {
        // Create a new instance of the html unit driver
        driver = new HtmlUnitDriver();

    }

    @When("^Address is (.*)$")
    public void connectTo(String address) {
        //Navigate to desired web page
        driver.get(address);
    }

    @Then("^Title is (.*)$")
    public void titleIs(String expectedTitle) {
        //get the title of the page
        String actualTitle = driver.getTitle();
        // verify title
        Assert.assertEquals(actualTitle,expectedTitle);
    }

}

test.feature: 测试功能:

Feature: Check the title

Scenario: Connect to the given address and check the title
Given Connect to the given address
When Address is http://www.google.com
Then Title is Google

Project structure: 项目结构:

src/test/
    java/
        pl/cucumber/test/
            RunIT.java
            TestTitlePages.java
    resources
        pl/cucumber/test
            test.feature

Call mvn verify 致电mvn verify

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用显式Maven目标运行Cucumber测试? - How can I run Cucumber test using explicit Maven goal? Maven项目(Cucumber + TestNG + Selenium-Java)测试无法使用mvn clean install在命令行上运行测试 - Maven Project(Cucumber+TestNG+Selenium-Java] Test Can't Run test on command line with mvn clean install 如何在Junit项目中并行运行Cucumber Selenium Maven - How to run Cucumber Selenium Maven with Junit project in Parallel Maven项目测试无法找到黄瓜测试在命令行上运行功能测试(Works on Cucumber) - Maven Project Test Can't Find Cucumber Tests to run feature test on command line (Works on Cucumber) SRC &amp; TEST文件夹下Cucumber + Maven + POM项目的目录结构 - Directory Structure for Cucumber + Maven + POM project under SRC & TEST folder Selenium Test类如何在Maven项目中运行 - How does Selenium Test class run in Maven project Jenkins和Maven可以安全地运行多少硒测试脚本 - How many selenium test scripts can be safely run with Jenkins and Maven 我如何运行Maven测试用例 - how can I run maven test case Selenium:如何使用带有Maven的黄瓜并行执行测试用例 - Selenium : How to execute test cases at parallely using cucumber with maven 如何将黄瓜整合到android-maven测试项目中? - How to integrate cucumber into android-maven test project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM