How to run two end to end test by closing driver instance every time

Hi All,

Below is my code, I am trying to execute two e2e scenarios with Appium, TestNG. When I run my suite my first e2e contains 5 classes executes perfectly but when the second test starts it throws session not found exception. could you kindly help me in fixing this issue.

public static void startingAppiumServer() throws IOException, InterruptedException {
CommandLine command = new CommandLine(“cmd”);
command.addArgument("/c");
command.addArgument(“C:\Program Files\nodejs\node.exe”);
command.addArgument(“C:\Users\sheniltonr\node_modules\appium\build\lib\appium.js”);
command.addArgument("–address", false);
command.addArgument(“127.0.0.1”);
command.addArgument("–port", false);
command.addArgument(“4723”);
command.addArgument("–full-reset", false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
}

public static void stopAppiumServer() throws IOException {
	CommandLine command = new CommandLine("cmd");
	command.addArgument("/c");
	command.addArgument("Taskkill /F /IM node.exe");
	DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
	DefaultExecutor executor = new DefaultExecutor();
	executor.setExitValue(1);
	executor.execute(command, resultHandler);
}

public static void settingDesiredCapabalaties() throws MalformedURLException {
	System.out.println("application has started...................");
	DesiredCapabilities caps = new DesiredCapabilities();
	caps.setCapability("deviceName", "emulator-5554");
	caps.setCapability("platformName", TestBase.propertyValueCall("platformName"));
	caps.setCapability("platformVersion", "9");
	caps.setCapability("skipUnlock", "true");
	caps.setCapability("appPackage", TestBase.propertyValueCall("appPackage"));
	caps.setCapability("appActivity", TestBase.propertyValueCall("appActivity"));
	caps.setCapability("fastReset", true);
	caps.setCapability("androidInstallTimeout", 150000);
	caps.setCapability("autoGrantPermissions", true);
	driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
	System.out.println("Appium SetUp for Android is successful and Appium Driver is launched successfully");
	System.out.println(driver);
}

@BeforeTest
public static void endTest() throws InterruptedException, IOException {
	startingAppiumServer();
	Thread.sleep(5000);
	settingDesiredCapabalaties();
	Thread.sleep(5000);
}

@Test(dataProvider = "fetchData")
public void test1(String un, String pwd) throws InterruptedException {
	Thread.sleep(5000);
	System.out.println(driver);
	preReqForTest(un, pwd);
}

@AfterTest
public static void startApplication1() throws Exception {
	Thread.sleep(5000);
	stopAppiumServer();
}

My TestNG xml File:

  <test name="TestPayLoansSameCurrency">	
	<classes>
		<class name="com.mobileAutomation.payLoans_130.Test_PayLoans_HL_130" /> 
		<class name="com.mobileAutomation.payLoans_210.Test_PayLoans_210" />
		<class name="com.mobileAutomation.payLoans_200.Test_PayLoans_200" />
		<class name="com.mobileAutomation.payLoans_600.Test_PayLoans_600" />
		<class name="com.mobileAutomation.payLoans_700.Test_PayLoans_700" />  
	</classes>
</test>       -->
   <!-- <test name="TestCrossCurrency">		
	<classes>
			<class name="com.citi.mobileAutomation.payLoans_200.Test_PayLoans_200_Cross_Currency" /> 
			<class name="com.mobileAutomation.payLoans_600.Test_PayLoans_600" />
			<class name="com.mobileAutomation.payLoans_700.Test_PayLoans_700" />
		</classes>
</test>