Monday, 29 January 2018

Maven POM Configuration For TestNG Execution

http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

Inclusions and Exclusions of Tests

Inclusions

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
  • "**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
  • "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
  • "**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
  • "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
If the test classes do not follow any of these naming conventions, then configure Surefire Plugin and specify the tests you want to include.
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <includes>
            <include>Sample.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Exclusions

There are certain times when some tests are causing the build to fail. Excluding them is one of the best workarounds to continue the build. Exclusions can be done by configuring the excludes property of the plugin.
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <excludes>
            <exclude>**/TestCircle.java</exclude>
            <exclude>**/TestSquare.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Using Suite XML Files

Another alternative is to use TestNG suite XML files. This allows flexible configuration of the tests to be run. These files are created in the normal way, and then added to the Surefire Plugin configuration:
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    [...]
</plugins>

Thursday, 21 September 2017

IDE - Most Used Shortcut In Eclipse/VisualStudio

Eclipse -
1. Going Back To Last Cursor Position - Alt + Left/Alt + Right
2. Ctrl+Q - moves the cursor to the last edit location




Visual Studio
1. Going Back To Last Cursor Position - CTRL + "-"

Maven: How To Add Local Dependency In Maven POM.XML

<dependencies>
  <dependency>
 <groupId>reporter</groupId>
 <artifactId>reporter</artifactId>
 <version>1.0.0</version>
 <scope>system</scope>
 <systemPath>${project.basedir}\lib\CignitiReporter-1.0.jar</systemPath>
     </dependency>
</dependencies>

Monday, 5 June 2017

Adding Ranorex.PDF plugin Using NuGet/Package Management Console

About - Ranorex.PDF plugin - It converts Ranorex Default Report To PDF format.
http://www.ranorex.com/blog/ranorex-report-to-pdf-conversion/ 

Editors/IDEs such as Visual Studio/Ranorex may not show up Ranorex.PDF package using Manage Package interface of Editors.

Ranorex.PDF can be installed from Package Management Console.

Type - Install-Package Ranorex.PDF by selecting the project you wish to be installed on.

Project can be selected using Install-Package switch parameter or selecting Project from Package Management Console.


Friday, 21 October 2016

MSTest Jenkins Integration


Plugins Required :
1. Active Choice Parameter
2. Html Report Publisher
3. File System SCM
4. To publish Extent report, you have do some setting in jenkins. The setting details have been covered as other topic.







Monday, 17 October 2016

Where Jenkins Login Password is saved

Jenkins places admin login password in file - ${Home Path}\.jenkins\secrets\initialAdminPassword file.
It's different than where Jenkins is installed.
Normally, Home location = C:\Users\{User}


Friday, 23 September 2016

Maven Error When Executed Using Eclipse - No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

One may see following error for the first time when maven project is tried to be run using POM -

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Json: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Problems is about setting JRE version in eclipse/setting javac in POM.

To fix the eclipse to run Maven test -

1. Go to Installed JREs in following way through Eclipse Menu options
Menu ->Windows->Preferences->Installed JREs.

2. Select/Add Installed JRE

Another Approach -
To fix the POM - Set Maven-compiler-plugin

Reference -
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <version>3.5.1</version>
  7. <configuration>
  8. <verbose>true</verbose>
  9. <fork>true</fork>
  10. <executable><!-- path-to-javac --></executable>
  11. <compilerVersion>1.3</compilerVersion>
  12. </configuration>
  13. </plugin>
  14. </plugins>
  15. </build>

Some times, in-appropriate testng version causes issue.
For example I got following issue with 6.9.13.6 -

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project Json: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]

The complete stack trace was - 
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.apache.maven.surefire.testset.TestSetFailedException: Unknown TestNG version 6.9.13.6
at org.apache.maven.surefire.testng.TestNGExecutor.getConfigurator(TestNGExecutor.java:207)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:72)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:110)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
... 9 more

Solution - 
TestNG version 6.9.9 worked well for me.