Cannot intrgrate extent reports with TestNG test with Appium using page object model

I tried integrating the extent report library in TestNG test with Appium. But i cannot run the test by pushing an error in @BeforeTest . I need some help in this matter.

I use Page Object Model for the TestNG test. And I use two classes such as Abstract class to be inherent by test class. Following code snippets will display them.

public class AbstractTest {
public static AppiumDriver driver;
protected static ExtentReports report;
protected ExtentTest logger;

@BeforeTest
public void setUp() throws Exception {

	AppiumDriverSetup.LoadResources();
	
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, AppiumDriverSetup.DeviceName());
	cap.setCapability(MobileCapabilityType.APP_PACKAGE, AppiumDriverSetup.AppPackage());
	cap.setCapability(MobileCapabilityType.APP_ACTIVITY, AppiumDriverSetup.AppActivity());
	cap.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + AppiumDriverSetup.apkFile());
	cap.setCapability("newCommandTimeout",300);
	cap.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, "true");
	driver = new AndroidDriver<WebElement>(new URL(AppiumDriverSetup.androidDriverURL()), cap);
	
	PathStore.LoadResources();
	  Date date= new Date();

	  report = new ExtentReports("C://Users//hansiniej//workspace//CompelloInvoiceHybridPOM//Reports//ResultDashboard.html",false);
	  WebDriverWait wait;
	  wait = new WebDriverWait(driver,120);
	  
	  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for web view");
	  wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("android.webkit.WebView")));
	  System.out.println(new Timestamp(new Date().getTime()) + ": Wait ended");
	  
	  System.out.println(new Timestamp(new Date().getTime()) + ": Searching contexts");
	  
	  java.util.Set<String> contextNames = driver.getContextHandles();
	  for (String contextName : contextNames) {
		  System.out.println("Context Found: [" + contextName + "]");
	    if (contextName.contains("WEBVIEW")){
	    	System.out.println(new Timestamp(date.getTime()) + ": Switching context - " + contextName);
	    	driver.context(contextName);
	    	System.out.println(new Timestamp(date.getTime()) + ": Switched to web context - " + contextName);
	    	break;
	    }
	  }

	  try {
		  System.out.println(new Timestamp(date.getTime()) + ": Starting thread sleep");
		  Thread.sleep(10000);
	} catch (InterruptedException e) {
		
		e.printStackTrace();
	}

	  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for log in area to be visible");
	  wait.until(ExpectedConditions.visibilityOf(driver.findElementById("login-page")));
	  System.out.println(new Timestamp(new Date().getTime()) + ": Login logo is visible");
	  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for username textbox");
	  wait.until(ExpectedConditions.visibilityOf(driver.findElementByName("login")));
	  System.out.println(new Timestamp(new Date().getTime()) + ": Login textbox found");
	
}

@AfterMethod
public void tearDown(ITestResult result) throws Exception {
	if (result.getStatus() == ITestResult.FAILURE)
	{
		
		String screenshot_path = Utilities.CaptureScreenshot(result.getName());
		String image = logger.addScreenCapture(screenshot_path);
		String video = logger.addScreencast("");
		logger.log(LogStatus.FAIL,"Snapshot below:", image);
		logger.log(LogStatus.FAIL,"Screencast below:", video);
	}
	logger.log(LogStatus.PASS, "Successful");
	report.endTest(logger);


}
@AfterTest
public void TestClassEnd() throws Exception {
	
	report.flush();
	driver.quit();
	driver.get("./Reports//ResultDashboard.html");
}

}

This is Test class

public class LoginTest extends AbstractTest{

@Test(dataProvider = "FetchData", dataProviderClass = core.TestNGDataProvider.class)
public void testSuccessfulLogin(String urlname, String cciname, String user, String pass) throws IOException {
	
	logger = report.startTest("Login test");
	logger.log(LogStatus.PASS,"Step details");
	
	LoginPageFlow pageFlow = new LoginPageFlow(this.driver);
	InvoicePageFlow invoicePageflow = pageFlow.LogIn(urlname, cciname, user, pass);
	invoicePageflow.verifyTitle();
	
}


@Test(dataProvider = "FetchData", dataProviderClass = core.TestNGDataProvider.class)
public void RejectInvoice(String urlname, String cciname, String user, String pass) throws IOException {
	
	logger = report.startTest("reject invoice test");
	
	LoginPageFlow pageFlow = new LoginPageFlow(this.driver);
	InvoicePageFlow invoiceListFlow = pageFlow.LogIn(urlname, cciname, user, pass);
	System.out.println("Starting SelectInvoice Test");
	InvoiceActionPageFlow newInvoiceAction = invoiceListFlow.SelectInvoice();
	
	newInvoiceAction.verifyActionsButton();
	
	InvoiceApprovalPromptPageFlow prompt =  newInvoiceAction.selectRejectInvoice();
	
	
	System.out.println("Pick reject");
	prompt.verifyPromptTitle();
	System.out.println("verified title");
	
	prompt.verifyYesDisabled();
	prompt.typeReason();
	prompt.verifyYesEnabled();
	prompt.verifyRejectSuccess();
	System.out.println("success");
			
	
	
}

}

When i run the above code i get the error in the TestNG console as follows.

TestNG] Running:
C:\Users\hansiniej\AppData\Local\Temp\testng-eclipse–1694575149\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeTest setUp
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:78)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:362)
at testCases.AbstractTest.setUp(AbstractTest.java:73)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:647)
at org.testng.TestRunner.run(TestRunner.java:615)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateModelException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 25 more

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED CONFIGURATION: @AfterTest TestClassEnd
SKIPPED: RejectInvoice(“invoiceapproval-test.compello.com”, “cctest”, “auth1”, “auth1”)
SKIPPED: testSuccessfulLogin(“invoiceapproval-test.compello.com”, “cctest”, “auth1”, “auth1”)

===============================================
Default test
Tests run: 2, Failures: 0, Skips: 2
Configuration Failures: 1, Skips: 3

===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 2
Configuration Failures: 1, Skips: 3

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@3830f1c0: 11 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1eb44e46: 106 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1ee0005: 119 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@76ccd017: 7 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 60 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4926097b: 5 ms

The appium log is as follows.

info: [debug] Responding to client with success: {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“4.4.4”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“appPackage”:“com.compello.touch”,“appActivity”:“com.compello.touch.MainActivity”,“app”:“C:\Users\hansiniej\workspace\CompelloInvoiceHybridPOM/apk/android-debug1.apk”,“newCommandTimeout”:300,“takesScreenshot”:true,“platformName”:“Android”,“deviceName”:“169.254.138.177:5555”},“appPackage”:“com.compello.touch”,“appActivity”:“com.compello.touch.MainActivity”,“app”:“C:\Users\hansiniej\workspace\CompelloInvoiceHybridPOM/apk/android-debug1.apk”,“newCommandTimeout”:300,“platformName”:“Android”,“deviceName”:“169.254.138.177:5555”},“sessionId”:“3275731d-ba45-4ebf-ac38-b566001c6168”}
info: ← GET /wd/hub/session/3275731d-ba45-4ebf-ac38-b566001c6168 200 2.362 ms - 864 {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“4.4.4”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“appPackage”:“com.compello.touch”,“appActivity”:“com.compello.touch.MainActivity”,“app”:“C:\Users\hansiniej\workspace\CompelloInvoiceHybridPOM/apk/android-debug1.apk”,“newCommandTimeout”:300,“takesScreenshot”:true,“platformName”:“Android”,“deviceName”:“169.254.138.177:5555”},“appPackage”:“com.compello.touch”,“appActivity”:“com.compello.touch.MainActivity”,“app”:“C:\Users\hansiniej\workspace\CompelloInvoiceHybridPOM/apk/android-debug1.apk”,“newCommandTimeout”:300,“platformName”:“Android”,“deviceName”:“169.254.138.177:5555”},“sessionId”:“3275731d-ba45-4ebf-ac38-b566001c6168”}

You should post the code you have. Logs would probably help too if you’ve got them.

I edited my question with the code and test results. Thanks in advance. I will really appreciate if you could provide any solution for this.

So your error indicates that you are trying to load a library class that is not in your classpath. I’m not familiar with this class and am not sure what it’s used for. You could either get it onto the classpath or remove the dependency.

1 Like

Thanks for your clue… I will look into the configuration of the library.