Running protractor tests as part of the Maven buil

2019-02-11 00:28发布

问题:

I have a Maven project and I wan't to change the POM so that when I build the project (Clean + Install), after the compilation part, a set of protractor tests will start (opening selenium and doing several things), and only if the tests pass, the build itself passes.

I can't seem to find something that gives me this kind of functionality. Is is possible? and if so, How do I use it? We are currently using the 'com.github.eirslett' maven plugin for building and I was wondering if it is possible to add the protractor tests as a stage in this plugin. I can see that it supports unit testing with 'Karma' but not anything related to protractor.

Any help will be much appreciated!! Thanks :)

回答1:

You can use following maven plugin https://github.com/greengerong/maven-ng-protractor

and you can use it like this

<plugin>
  <groupId>com.github.greengerong</groupId>
  <artifactId>maven-ng-protractor</artifactId>
  <version>0.0.2</version>
  <configuration>
    <protractor>protractor</protractor>
    <configFile>yourconfig.js</configFile>
  </configuration>
  <executions>
    <execution>
    <id>ng-protractor</id>
    <phase>integration-test</phase>
    <goals>
       <goal>run</goal>
    </goals>
    </execution>
  </executions>
</plugin>


回答2:

I am using grunt to execute these test like below :-

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>Run Protractor Tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>grunt${script.extension}</executable>
                        <arguments>
                            <argument>int-test</argument>
                        </arguments>
                        <workingDirectory>${basedir}/modules</workingDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>