0

Currently working on Selenium WebDriver and using Java. I have asked a question earlier to create the Task scheduler and i created as mentioned in the How to create scheduler to run my script every night at 12.00- Selenium WebDriver But the Problem it is opening the eclipse at the time i have scheduled but the problem Once it open the eclipse it need to run all test one by one

I tried in cmd prompt, and getting error Error: Could not find or load main class org.testng.TestNG

Anyone please suggest me to fix the issue.

I have a run.bat as follows:

set ProjectPath=C:\Documents and Settings\amth\workspace\OneReports\src\
echo %ProjectPath%
set classpath=%ProjectPath%bin;%ProjectPath%lib*
echo %classpath%
java org.testng.TestNG %ProjectPath%Test.xml

While checking in the Command Prompt it is appearing as follows:

C:\Documents and Settings\amth>cd desktop

C:\Documents and Settings\amth\Desktop>run.bat
C:\Documents and Settings\amth\workspace\OneReports\src\
C:\Documents and Settings\amth\workspace\OneReports\src\bin;C:\Documents and Settings\amth\workspace\OneReports\src\lib*C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files (x86)\Java\jdk1.7.0_51\bin;

 Press any key to continue . . .

java org.testng.eclipse C:\Documents and Settings\amth\workspace\OneReports\src\Test.xml

C:\Documents and Settings\amth\Desktop>

Is Jenkins and some other scheduler will work for windowsxp

Currently using TestNG framework, Selenium webdriver, Java code

Community
  • 1
  • 1
testing
  • 1,736
  • 15
  • 46
  • 75
  • Is there any compelling reason for you to use the windows scheduler? Are you ok to use a CI build tool like hudon/jenkins? Jenkins has an option to run a bat file – A.J Feb 26 '14 at 04:43
  • Please help me immediately to fix the windows task schedular – testing Feb 26 '14 at 04:56
  • Follow the given link to schedule a task in windows machine. http://windows.microsoft.com/en-in/windows/schedule-task#1TC=windows-7 – Santoshsarma Feb 26 '14 at 05:16
  • Please check the above command lines when i check run.bat there is nothing happening. how can i execute the Test.xml file inside the eclipse – testing Feb 26 '14 at 05:19
  • i have created the Task scheduler and eclipse as a schedule in Scheduled Task page. i tried with giving some time also at that particular time it start and it is opening the eclipse as well.. But the problem is once it opened it need to run the Test.xml as well. Please help me to fix the problem – testing Feb 26 '14 at 05:23
  • please help me to figure out the problem i struck ed nearly 3 days – testing Feb 26 '14 at 05:28

1 Answers1

3

Launching eclipse for running tests one by one is a bad idea.

You just create a testsuite & launch that testsuite using batch file.

Without using testng.xml

import org.testng.TestListenerAdapter;
import org.testng.TestNG;

public class TestngTestSuite {
    public static void main(String[] args) {
        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { ExampleTest.class,ExampleTest2.class });
        testng.addListener(tla);
        testng.run();
    }
}

Using testng.xml

import java.util.ArrayList;
import java.util.List;
import org.testng.TestNG;
import org.testng.xml.XmlSuite;

    public class TestngTestSuiteUsingXML {

        public static void main(String[] args) {

            List<String> files=new ArrayList<String>();
            files.add("/Users/test/testng/testng.xml");
            XmlSuite suite = new XmlSuite();
            suite.setSuiteFiles(files);
            List<XmlSuite> suites = new ArrayList<XmlSuite>();
            suites.add(suite);
            TestNG tng = new TestNG();
            tng.setXmlSuites(suites);
            tng.run();
        }

    }

Create testsuite using any of the above method and try to run testsuite from batch file by putting all required jars in classpath.

After that schedule a task in windows to run batch file

http://windows.microsoft.com/en-in/windows/schedule-task#1TC=windows-7

Edit-1

Example:

Your jars & xml is in
C:\JARs> yoursource.jar, testng.jsr, testng.xml

Your testsuite must contain proper path to testng.xml
List<String> files=new ArrayList<String>();
files.add("C:\\JARs\\testng.xml");

Now try to execute testsuite 
c:\JARs> java -cp "yoursource.jar":"testng.jar" test.TestngTestSuiteUsingXML
Santoshsarma
  • 5,627
  • 1
  • 24
  • 39
  • @santosharma Please Can i use the above model for Testng.. where i need to place exactly the testng.xml – testing Feb 26 '14 at 06:16
  • Could you please help me to create exactly. – testing Feb 26 '14 at 06:18
  • 1). You can place testng.xml anywhere. Just give that path in java file. 2). Create one jsr file using all your source files and put it in classpath. 3). Don't forgot to put testng.jar in classpath. Put all required jars and execute it. – Santoshsarma Feb 26 '14 at 06:38
  • i'm not getting what you are telling exactly. Please check the image ![enter image description here][1] [1]: http://i.stack.imgur.com/I2vPt.jpg and explain me – testing Feb 26 '14 at 06:56
  • @santosharma could you please explain me in detail how to do the above steps – testing Feb 26 '14 at 07:32
  • Edited my answer. Just go through it. – Santoshsarma Feb 26 '14 at 07:48
  • I'm getting error as follows: C:\Jars>java -cp "OneReoprts.jar":"testng-6.8.6beta" test.TestngTestSuiteUsingXM L Error: Could not find or load main class test.TestngTestSuiteUsingXML C:\Jars> – testing Feb 26 '14 at 09:18
  • Could you please check the above image there one Test.xml is there and i have xml code inside that. I'm not getting what exactly are you telling.. whatever you have mentioned i added but its not working – testing Feb 26 '14 at 09:21
  • I will explain you in detail. I have a project called OneReports in the path C:\Documents and Settings\amth\workspace\OneReports. – testing Feb 26 '14 at 09:23
  • The entire project contains these many files which is shown in the image as follows ![enter image description here][1] [1]: http://i.stack.imgur.com/I2vPt.jpg – testing Feb 26 '14 at 09:24
  • There i have a Test.xml in that having code as follows that even in the project itself – testing Feb 26 '14 at 09:25
  • Now let me know what i need to do?? – testing Feb 26 '14 at 09:26
  • i want to know what you will give in the testng.xml – testing Feb 26 '14 at 09:32
  • You there.. if possible come in chat – testing Feb 26 '14 at 09:35
  • C:\Jars>dir Volume in drive C has no label. Volume Serial Number is 00A3-0759 Directory of C:\Jars 02/26/2014 03:15 PM . 02/26/2014 03:15 PM .. 02/26/2014 02:20 PM 101,242 OneReports.jar 02/26/2014 03:04 PM 384 testing.java 05/25/2013 10:07 AM 1,429,503 testng-6.8.6beta.jar 3 File(s) 1,531,129 bytes 2 Dir(s) 73,268,150,272 bytes free C:\Jars>java -jar OneReports.jar no main manifest attribute, in OneReports.jar C:\Jars> – testing Feb 26 '14 at 09:49
  • give me your gmail id. – Santoshsarma Feb 26 '14 at 09:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48453/discussion-between-amir-and-santoshsarma) – testing Feb 26 '14 at 09:50