1

Cloned the project from github at location :

C:\Automation\CC_Regression_Automation\CC_Regression

Folder structre

When trying to run testng.xml using eclipse all goes well.

Getting Cannot instantiate class testCases.LoginPage when trying to run the code using command line.

**Loginpage.java**

 package testCases;

 import java.io.IOException;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 import com.relevantcodes.extentreports.ExtentTest;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 import utils.DriverUtil;
 import utils.Loggers;
 import utils.ReportGenerator;
 import utils.WebPageUtils;

public class LoginPage extends Base{

    /*Members of the current Test Class. The number varies from script
    to script depending on the variables and verifications required*/
    public WebDriver driver;
    private String currentSitePath;
    private String testCaseName=getClass().getName().substring(10); 
    ExtentTest parentTest =ReortGenerator.initializeParentTest(getClass().getName().substring(10),"Testing Login Page");

    //Function to Navigate to a particular URL inside CC
    public void navigateToURL(WebDriver driver){
        siteURL="";
        this.driver.navigate().to(baseurl+siteURL);
        }


    @Test // Main Test Flow for the Script
    public void executeScript() throws IOException{

        System.out.println("*******************");
        System.out.println("launching chrome browser");

        //Test Case Author assignment in Reports 
        ReportGenerator.assignAuthor(parentTest,"Garima");

        //Setting up Browser Instance
        this.driver=driverIns();


        //Navigating to the required page in CC
        navigateToURL(this.driver);


        Sleep(5000);

        String strPageTitle = this.driver.getTitle();
        System.out.println(strPageTitle);
        //Start Logs
        Loggers.startCurrentTestCaseExecution(this.driver);

        try{
        ReportGenerator.verifyNavigation(this.driver, "Control Center", parentTest,testCaseName,"Yes");

Code snippent of Base.java

//Function to instantiate the WebDriver instance based on the Browser 
 selected for Windows
 public WebDriver driverInsWindows(){
        isExtensionEnabled();
        setbaseURL();   

    try {
        switch(getBrowser()+isExtensionEnabled.toString()){
            case "Chromefalse":
                System.setProperty("webdriver.chrome.driver", "./Win/Drivers/chromedriver.exe");

                driver=new ChromeDriver();
                driver.get(baseurl);
                break;

            case "Chrometrue":

                System.setProperty("webdriver.chrome.driver", "./Win/Drivers/chromedriver.exe");
                driver=invokeChromeBrowserwithExtension();

                driver.get("https://www.google.com");
                break;

            case "Internet Explorer":
                System.setProperty("webdriver.internetexplorer.driver", 
 "./Win/Drivers/internetexplorerdriver.exe");
                driver=new InternetExplorerDriver();
                driver.get(baseurl);
            break;
            case "Firefox":
                driver=new FirefoxDriver();
                driver.get(baseurl);
                break;
                default:
                    //new PascalBaseClass();
        }
    } catch (IOException e) {
   }

Executing below command via cmd:-

java -cp C:\Automation\CC_Regression_Automation\CC_Regression\bin;C:\Automation\CC_Regression_Automation\CC_Regression\lib\* org.testng.TestNG testng.xml

enter image description here

Blockquote

Dadep
  • 2,796
  • 5
  • 27
  • 40
  • Hey Garima, welcome to stackoverflow. Looking at your project, due the fact you have to manage a few dependencies and build environments, I suggest you start working with build tool such as Maven or Gradle. Using these tools, debugging a case like the one you reported would be much easier. – AutomatedOwl Jul 05 '18 at 12:06
  • This link can help you "https://stackoverflow.com/questions/11896791/how-to-run-testng-from-command-line" – Monika Jul 05 '18 at 15:18

1 Answers1

0

Your problem might be this line:

ExtentTest parentTest =ReortGenerator.initializeParentTest(getClass().getName().substring(10),"Testing Login Page")

Since I'm seeing other references to ReportGenerator

I doubt you typed all that code, and it's a copy/paste so I'm not sure why your IDE doesn't flag it, or is there somehow another object called ReortGenerator

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
  • Hey Bill, Based on your comments I comment out all the code related to Report Generation in LoginPage.java ... and after that my code worked from command line. – garima garg Jul 05 '18 at 16:37
  • But since for the Report generation, i will need that code back. Can you please help me that. – garima garg Jul 05 '18 at 16:37
  • I suggest that you refer to the on-line documentation for Extent Reports. It's not all that complicated, I use them myself, but you should be able to work out any issues if you read their examples. If you have any specific questions regarding Extent Reports I recommend that you make another post with just those specific problems and tag one or both the extent reports tags available to get quicker help. – Bill Hileman Jul 05 '18 at 17:10