Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Getting Null Pointer Exception on running Test Runner Class. Unable to run the testcase #112

Open
nkroy30 opened this issue Sep 6, 2019 · 0 comments

Comments

@nkroy30
Copy link

nkroy30 commented Sep 6, 2019

Test Runner Class:

package runner;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@RunWith(Cucumber.class)
@test(groups = "cucumber")
@CucumberOptions(

	features = {
			"src/test/resources/features/WebServices/CreateDraft.feature",
			"src/test/resources/features/WebServices/DeleteDraft.feature",
			"src/test/resources/features/WebServices/GetAllDraft.feature",
			"src/test/resources/features/WebServices/GetDraft.feature",
			"src/test/resources/features/WebServices/UndoDraft.feature",
			"src/test/resources/features/WebServices/GetTemplate.feature"
			   }
	, glue = { 
			"step_definations.API" 
			 }
	,tags={" @NewEtag"}
    ,plugin = {"com.sitture.ExtentFormatter:C:/Intuition/IntuitionRewrite_API/src/test/resources/reports/APIreport.html" }
	,monochrome =true

)
public class TestRunnerIntuitionAPI {

public static ExtentReports extent;

@SuppressWarnings("null")
@BeforeClass
public static void setup1() throws Throwable {
	
	ExtentReports extent = null;
	
	//String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
	//String FileLocation = "C:\\CSF-Development\\Intuition\\Main\\Testing\\Automation\\IntuitionRewrite_API\\src\\test\\resources\\" + "extentreports.html";
	//extent = new ExtentReports ();
	//ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(FileLocation);
	//extent.attachReporter(htmlReporter);

	String browserType="chrome";
	System.out.println(new File(System.getProperty("user.dir")+"//config//extent-config.xml"));
	extent.loadConfig(new File(System.getProperty("user.dir")+"//config//extent-config.xml"));
   
    

}





@AfterClass
public static void setup() throws Exception {
	ExtentReports extent = null;
	    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
        extent = new ExtentReports ("C:\\Intuition\\IntuitionRewrite_API\\Emailable-Reports\\Report\\Report.html"+timeStamp, true);
      
    
    
    
  
   // String FileLocation = "C:\\CSF-Development\\Intuition\\Main\\Testing\\Automation\\IntuitionRewrite_API\\src\\test\\resources\\" + timeStamp;
}

}

Error Message:
java.lang.NullPointerException
at runner.TestRunnerIntuitionAPI.setup1(TestRunnerIntuitionAPI.java:62)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

java.lang.NullPointerException
at runner.TestRunnerIntuitionAPI.setup1(TestRunnerIntuitionAPI.java:62)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

POM.XML:


4.0.0
IntuitionRewrite_API
IntuitionRewrite_API
0.0.1-SNAPSHOT

<dependencies>
	<dependency>
		<groupId>io.rest-assured</groupId>
		<artifactId>rest-assured</artifactId>
		<version>3.3.0</version>
		<scope>test</scope>
	</dependency>
	<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
	<dependency>
		<groupId>info.cukes</groupId>
		<artifactId>cucumber-testng</artifactId>
		<version>1.2.5</version>
	</dependency>
	<dependency>
		<groupId>com.googlecode.json-simple</groupId>
		<artifactId>json-simple</artifactId>
		<version>1.1</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.testng/testng -->
	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>6.14.3</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>1.2.17</version>
	</dependency>
	<dependency>
		<groupId>com.sitture</groupId>
		<artifactId>cucumber-jvm-extentreport</artifactId>
		<version>2.0.1</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/junit/junit -->
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.11</version>
		<scope>test</scope>
	</dependency>
	
	<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.1</version>
	<!-- https://mvnrepository.com/artifact/com.vimalselvam/cucumber-extentsreport -->
com.vimalselvam cucumber-extentsreport 2.0.0
	<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
  <dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
   </dependency>
	<dependency>
		<groupId>info.cukes</groupId>
		<artifactId>cucumber-junit</artifactId>
		<version>1.2.4</version>
		<scope>test</scope>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.json/json -->
	<dependency>
		<groupId>org.json</groupId>
		<artifactId>json</artifactId>
		<version>20090211</version>
	</dependency>
	<dependency>
		<groupId>info.cukes</groupId>
		<artifactId>cucumber-java</artifactId>
		<version>1.2.5</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
		<version>2.9.5</version>
	</dependency>


</dependencies>
<build>

	<resources>
		<resource>
			<directory>src/main/resources</directory>
			<filtering>true</filtering>
		</resource>
	</resources>
	<testResources>
		<testResource>
			<directory>src/test/resources</directory>
			<filtering>true</filtering>
		</testResource>
	</testResources>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugin</groupId>
			<artifactId>maven-resources-plugin</artifactId>
			<version>2.7</version>
			<dependencies>
				<dependency>
					<groupId>org.apache.maven.shared</groupId>
					<artifactId>maven-filtering</artifactId>
					<version>1.3</version>
				</dependency>
			</dependencies>
		</plugin>

		<plugin>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.18.1</version>
			<configuration>
				<suiteXmlFiles>
					<suiteXmlFile>testng.xml</suiteXmlFile>
				</suiteXmlFiles>
			</configuration>
		</plugin>
		<plugin>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.2</version>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>


	</plugins>
</build>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant