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â}