0

BaseTest.java

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

public class BaseTest {
    public WebDriver driver=null;
    public Properties prop;

    public void openBrowser(String bType) {
        if(prop==null){
            prop=new Properties();
            //"user.dir"+"src\test\java\resources\projectconfig.properties"

            try {
                FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\test\\java\\resources\\projectconfig.properties");
                prop.load(fs);
                System.out.println("This is the AppURL-->"+prop.getProperty("appurl"));

            } catch (Exception e) {
                e.printStackTrace();
            }

            System.out.println(System.getProperty("user.dir")+"\\src\\test\\java\\resources\\projectconfig.properties");
            if(bType.equals("chrome")){
                System.setProperty("webdriver.chrome.driver",prop.getProperty("chromedriver_exe") );
                driver=new ChromeDriver();
            }
            if(bType.equals("firefox")){
                System.setProperty("webDriver.gecko.driver",prop.getProperty("firefox_exe"));
                driver=new FirefoxDriver();
            }
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.manage().window().maximize();
        }
    }
    public void navigate(String appurl){
        driver.navigate().to(appurl);
    }

    public void type(String email_xpath, String content){
        getElement(email_xpath).sendKeys(prop.getProperty(content));
        //driver.findElement(By.xpath(prop.getProperty("email_xpath"))).sendKeys(prop.get("content"));
    }
    public void click(String locatorKey){
        //driver.findElement(By.xpath(prop.getProperty("button_xpath"))).click();
        getElement(locatorKey).click();
    }

    //finding element and returning it
    public WebElement getElement(String locatorKey){
        WebElement e=null;
        try{
            if (locatorKey.endsWith("_xpath")){
                e=driver.findElement(By.xpath(prop.getProperty(locatorKey)));
            }else if(locatorKey.endsWith("_id")){
                e=driver.findElement(By.id(prop.getProperty(locatorKey)));
            }else if(locatorKey.endsWith("_name")){
                e=driver.findElement(By.name(prop.getProperty(locatorKey)));
            }else{
                reportFailture("Locator NOT found/incorrect locator-->"+locatorKey);
            }

        }catch(Exception ex){
            ex.printStackTrace();
            reportFailture(ex.getMessage());
        }
        return e;

    }
}

ExtentManager.java

package com.qtpselenium.core.ddf.util;

import java.io.File;
import java.util.Date;

import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;


public class ExtentManager {
    public static ExtentReports extent;

    public static ExtentReports getInstance() {
        if (extent == null) {
            Date d=new Date();
            String newD=d.toString().replace(":", "_").replace(" ", "_")+".html";
            //extent
            System.out.println("D:\\selenium_files\\ExtentReports\\"+newD);
            extent = new ExtentReports("D:\\selenium_files\\ExtentReports\\"+newD, true, DisplayOrder.OLDEST_FIRST);
            extent.loadConfig(new File(System.getProperty("user.dir")+"//suite//ReportsConfig.xml"));

            // optional
            extent.addSystemInfo("Selenium Version", "2.53.0").addSystemInfo("Environment", "QA");
        }
        return extent;
    }
}

The Error is:

D:\selenium_files\ExtentReports\Sun_Apr_02_12_50_36_IST_2017.html
org.testng.TestNGException:
    Cannot instantiate class com.qtpselenium.core.ddf.testcases.DummyTestA
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:373)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:285)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
    at org.testng.TestClass.getInstances(TestClass.java:104)
    at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:90)
    at org.testng.TestClass.init(TestClass.java:82)
    at org.testng.TestClass.<init>(TestClass.java:45)
    at org.testng.TestRunner.initMethods(TestRunner.java:422)
    at org.testng.TestRunner.init(TestRunner.java:252)
    at org.testng.TestRunner.init(TestRunner.java:222)
    at org.testng.TestRunner.<init>(TestRunner.java:171)
    at org.testng.remote.support.RemoteTestNG6_9_10$1.newTestRunner(RemoteTestNG6_9_10.java:28)
    at org.testng.remote.support.RemoteTestNG6_9_10$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_9_10.java:61)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:604)
    at org.testng.SuiteRunner.init(SuiteRunner.java:170)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:117)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1359)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1346)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1349)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
    at org.testng.TestNG.runSuites(TestNG.java:1124)
    at org.testng.TestNG.run(TestNG.java:1096)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
    ... 26 more
    Caused by: java.lang.NoClassDefFoundError: freemarker/ext/beans/BeansWrapperBuilder
    at com.relevantcodes.extentreports.HTMLReporter.start(HTMLReporter.java:75)
    at com.relevantcodes.extentreports.Report.attach(Report.java:302)
    at com.relevantcodes.extentreports.ExtentReports.<init>(ExtentReports.java:78)
    at com.relevantcodes.extentreports.ExtentReports.<init>(ExtentReports.java:195)
    at com.qtpselenium.core.ddf.util.ExtentManager.getInstance(ExtentManager.java:42)
at com.qtpselenium.core.ddf.testcases.DummyTestA.<init>(DummyTestA.java:19)
    ... 31 more
    Caused by: java.lang.ClassNotFoundException: freemarker.ext.beans.BeansWrapperBuilder
    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)
    ... 37 more

DummyTestA 

package com.qtpselenium.core.ddf.testcases;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.openqa.selenium.support.ui.Sleeper;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.qtpselenium.core.ddf.base.BaseTest;
import com.qtpselenium.core.ddf.util.ExtentManager;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

The class generating the error (DummyTestA)

public class DummyTestA extends BaseTest {
    /*-->Extent report related
     * public ExtentReports rep=ExtentManager.getInstance();
    public ExtentTest test;*/
    @Test(priority=1)
    public void testA1()  { 

         /*-->Extent report related
          * test=rep.startTest("DummyTestA");
        // -->Extent report related    test.log(LogStatus.INFO,"Starting the test");*/
        openBrowser("firefox");
    //  test.log(LogStatus.INFO, "Opened the Browser");
        navigate(prop.getProperty("appurl"));
        //test.log(LogStatus.INFO, "navigated to the URL");
        if(!verifyText("signintext_xpath", "signinText")){
            /*IF we do not want the rest case to stop and want to execute the test case further we can use softAssert
             *After we declare the softassert we need to AssertAll in the @AfterMethod
             *softAssert.assertTrue(verifyText("signintext_xpath", "signinText"), "Text did NOT Matched");
             */
            reportFailture("Text did NOT matched");
        }

        if(!isElementPresent("email_xpath")){
            reportFailture("Email ID field is NOT present");
        }
        type("email_xpath","EmailId");
        takeScreenShot();

        click("button_xpath");
        //driver.quit();
        Assert.assertFalse(false);

    }

    @Test(priority=2,dependsOnMethods={"testA1"})
    public void testA2(){
        System.out.println("testA2 method");

    }
    @Test(priority=3,dependsOnMethods={"testA1","testA2"})
    public void testA3(){
        System.out.println("TestA3 method");

    }
    @AfterMethod
    public void quit(){

    /*-->Extent report related
     * rep.endTest(test);
     * rep.flush();
     */

        /*Below line of code is to assert All the softAsserions
        softAssert.assertAll();
         */
     }
}
1
  • in the error there is Cannot instantiate class com.qtpselenium.core.ddf.testcases.DummyTestA where is DummyTestA?
    – Ammar
    Commented Apr 2, 2017 at 11:38

1 Answer 1

1

The real problem was with freemarker.

The line in the error Caused by: java.lang.ClassNotFoundException: freemarker.ext.beans.BeansWrapperBuilder - I had an old version of freemarker that did not have the BeansWrapperBuilder class.

This issue has been resolved by adding the jar file for freemarker 2.3.23,

1
  • We don't know; what exactly he (user3777770) wants to conclude with that, as the same user posted 3 times different answers even though it was not matched with the post. No more answer plz; Instead, edit your question with the latest update.
    – Bharat Mane
    Commented Apr 17, 2017 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.