TestNGException while executing mavenized selenium project from Command prompt

211 views
Skip to first unread message

Rishi Khanna

unread,
Oct 27, 2014, 10:59:59 PM10/27/14
to testng...@googlegroups.com

I am running mavenized TestNG Webdriver project from command prompt using 'mvn clean install' but I get the following exception in the cmd prompt

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
17:test (default-test) on project WebdriverWithTestNG: Execution default-test of
goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was
an error in the forked process
[ERROR] org.testng.TestNGException:
[ERROR] An error occurred while instantiating class com.generic.validateorders.W
ebAppTest: null
[ERROR] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:398)

On the other hand whenever I run it from the eclipse it executes perfectly fine without any issues. Is there any issue with my project classpath? If yes then how do I fix it. I have attached the complete stack trace of the exception.

Exception.txt

Krishnan Mahadevan

unread,
Oct 28, 2014, 12:47:21 AM10/28/14
to testng...@googlegroups.com
I would start looking from here :

[ERROR] Caused by: java.lang.RuntimeException: Exception in static method of Logger Class. [ERROR] at com.generic.utilities.Logg.<clinit>(Logg.java:40) [ERROR] ... 29 more [ERROR] Caused by: java.io.IOException: The system cannot find the path specified [ERROR] at java.io.WinNTFileSystem.createFileExclusively(Native Method) [ERROR] at java.io.File.createNewFile(File.java:947) [ERROR] at com.generic.utilities.Logg.<clinit>(Logg.java:29) [ERROR] ... 29 more [ERROR] -> [Help 1]

your com.generic.utilities.Logg initializer (either a constructor a static block) is facing some issues with some path.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Rishi Khanna

unread,
Oct 28, 2014, 2:33:11 AM10/28/14
to testng...@googlegroups.com
hey Krishnan, my concern is that everything work perfectly when running through eclipse but as soon as I execute the project from cmd prompt it throws exception. I want to run it from the cmd prompt so that I can use CI tool to execute it.

Krishnan Mahadevan

unread,
Oct 28, 2014, 2:46:15 AM10/28/14
to testng...@googlegroups.com
Please remember that when you run from within eclipse, I dont think Maven is involved. The TestNG plugin relies on using the embedded TestNG jar to run your tests, which isnt the case when you trigger a mvn clean install.

So have you tried finding out what is going on in the section that I highlighted ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Tue, Oct 28, 2014 at 12:03 PM, Rishi Khanna <rishi.k...@gmail.com> wrote:
hey Krishnan, my concern is that everything work perfectly when running through eclipse but as soon as I execute the project from cmd prompt it throws exception. I want to run it from the cmd prompt so that I can use CI tool to execute it.

--

Rishi Khanna

unread,
Oct 28, 2014, 3:30:47 AM10/28/14
to testng...@googlegroups.com
I am trying to create a file using file.createNewFile() and this function is throwing IOException as mentioned by you. Caused by: java.io.IOException: The system cannot find the path specified 
The system is not able to find the path: logs/" + FileName when I run it from the cmd prompt. The logs folder exists in my project, do I need to make it a source folder?

 static {
        /**
         * This is the static block which appends the log file name with the
         * timestamp to make it unique
         */
        try {
            String dateTime = DateAndTime.getFormattedCurrentDateAndTime(DATEANDTIMEFORMAT);
            String FileName = FILENAME + "-" + dateTime + ".log";
            File file = new File("logs/" + FileName);
            if (file.createNewFile()) {
                Properties props = new Properties();
                props.load(new FileInputStream(LOGPROPERTTFILEPATH));
                props.setProperty("log4j.appender.File.File", "logs/" + FileName);
                LogManager.resetConfiguration();
                PropertyConfigurator.configure(props);
                System.out.println("Property log4j.appender.File.File = logs/" + FileName);
            } else {
                System.out.println("File aready exists");
            }
        } catch (Exception ex) {
            throw new RuntimeException("Exception in static method of Logger Class. ", ex);
        }

    } 

Krishnan Mahadevan

unread,
Oct 28, 2014, 3:36:01 AM10/28/14
to testng...@googlegroups.com
Since I dont have an insight into what your project is doing with this folder, I dont think I would be able to help beyond this.

One thing you can do is try the following :

new File("logs/").mkdirs();


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--

Rishi Khanna

unread,
Oct 28, 2014, 6:37:27 AM10/28/14
to testng...@googlegroups.com
Thanks Krishnan.. I will try to figure out what the issue

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Oct 28, 2014, 10:37:31 AM10/28/14
to testng-users
Hi RIshi,

  Just curious why you are trying to create log files. I guess you can use log4j which would create log files and has lot of advantages.

log4j.rootLogger=INFO
log4j.logger.com.yahoo=DEBUG,file
log4j.logger.httpclient.wire=OFF

log4j.appender.screen=org.apache.log4j.ConsoleAppender
log4j.appender.screen.Threshold=DEBUG
log4j.appender.screen.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.ss} %-5p (%F:%L) [%t]: %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.File=logs/${groups}.debug.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=20
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.ss} %-5p (%F:%L) [%t]: %m%n

This will create all the log files in logs directory which is created by log4j itself.




On Tue, Oct 28, 2014 at 3:37 AM, Rishi Khanna <rishi.k...@gmail.com> wrote:
Thanks Krishnan.. I will try to figure out what the issue

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

Rishi Khanna

unread,
Oct 28, 2014, 12:41:13 PM10/28/14
to testng...@googlegroups.com
Hey SUBRAMANYESWARA ,

I already have the log4j code in my project and it runs perfectly fine from the eclipse but the mavenized project throws exception when I execute it from the cmd prompt using 
mvn clean install

My log4j code creates all the log files inside a log folder, which is created manually. The problem is that the log folder is not visible to the command prompt and it throws exception but from the eclipse there is no such issue 
Reply all
Reply to author
Forward
0 new messages