• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException in Junit

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am working with junit 4 and selenium while i am running the testsuite i am getting ClassCastException could you please tell me how to fix the problem the exception and the code is below


Exception

java.lang.ClassCastException: class gdsp.plmn.test.Plmn
at java.lang.Class.asSubclass(Unknown Source)
at junit.framework.TestSuite.<init>(TestSuite.java:175)
at gdsp.plmn.test.AllTests.suite(AllTests.java:95)
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.junit.internal.runners.SuiteMethod.testFromSuiteMethod(SuiteMethod.java:34)
at org.junit.internal.runners.SuiteMethod.<init>(SuiteMethod.java:23)
at org.junit.internal.builders.SuiteMethodBuilder.runnerForClass(SuiteMethodBuilder.java:14)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



AllTests.java


package gdsp.plmn.test;

import java.io.BufferedWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
import java.io.IOException;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;

import junit.framework.*;


public class AllTests extends TestSuite{

public static BufferedWriter loggingWriter;
public static final String RESULT_FILE_ENCODING = "UTF-8";
public static final String DEFAULT_TIMEOUT = "70000";
public static final String SCREENSHOT_PATH = "gdspScreenshots";
public final static String RESULTS_BASE_PATH = "target" + File.separator + "loggingResults";
public static LoggingCommandProcessor myProcessor = null;
public static String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath();
public static String screenshotsResultsPath = new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath();
public static Properties props = null;
public static LoggingSelenium selenium;
private static String resultHtmlFileName = null;
public static junit.framework.TestSuite isdsuite;




static{

try
{
props = new Properties();
System.out.println("yes");
props.load(new FileInputStream("C://Documents and Settings//vedhagirikuppuswamys//workspace//SeleniumTestSuite/src/selenium.properties"));
if (!new File(screenshotsResultsPath).exists()) {
new File(screenshotsResultsPath).mkdirs();
}
}catch (FileNotFoundException fe)
{

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
isdsuite = new junit.framework.TestSuite();
resultHtmlFileName = resultsPath + File.separator + "sampleResultJunitAssertionFailed.html";
loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, AllTests.RESULT_FILE_ENCODING, true);
LoggingResultsFormatter htmlFormatter = new HtmlResultFormatter(loggingWriter, AllTests.RESULT_FILE_ENCODING);
htmlFormatter.setScreenShotBaseUri(AllTests.SCREENSHOT_PATH + "/");
htmlFormatter.setAutomaticScreenshotPath(AllTests.screenshotsResultsPath);
myProcessor = new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*iexplore", AllTests.props.getProperty("url")), htmlFormatter);
myProcessor.setExcludedCommands(new String[] {});

AllTests.selenium = new LoggingDefaultSelenium(AllTests.myProcessor);
AllTests.selenium.start();
AllTests.selenium.setContext("AllTest");
AllTests.selenium.open(AllTests.props.getProperty("url"));
AllTests.selenium.type("id=login.userId", AllTests.props.getProperty("user.name"));
AllTests.selenium.type("id=login.password", AllTests.props.getProperty("user.password"));
AllTests.selenium.click("id=submit");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);

}



public static Test suite() throws IOException{

try
{


isdsuite.addTest(new junit.framework.TestSuite(gdsp.plmn.test.Plmn.class));

AllTests.selenium.stop();

try {

if (null != loggingWriter) {
loggingWriter.close();
}
} catch (IOException e) {
// do nothing
}


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

public static void main(String args[]) throws IOException
{
junit.textui.TestRunner.run(suite());
}

}




Plmn.java


package gdsp.plmn.test;


import java.text.ParseException;
import org.junit.Test;
import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertFalse;

public class Plmn {


@Test(expected=AssertionError.class)
public void testPlmn() throws InterruptedException, ParseException {


AllTests.selenium.click("link=Manage PLMN List");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);
AllTests.selenium.click("id=submit");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);
AllTests.selenium.type("id=plmn.plmnListName", AllTests.props.getProperty("plmnListName"));
AllTests.selenium.type("id=plmn.plmnListDesc", AllTests.props.getProperty("plmnListDesc"));
AllTests.selenium.type("id=plmn.plmnListReference", AllTests.props.getProperty("plmnListReference"));
AllTests.selenium.click("id=submit");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);
assertFalse("Expected text 'There has been an error (200/5822) PLMN List Name must be unique' found", AllTests.selenium.isTextPresent("There has been an error (200/5822) PLMN List Name must be unique"), AllTests.selenium);

//assertEquals("There has been an error (200/5822) PLMN List Name must be unique", "There has been an error (200/5822) PLMN List Name must be unique");
AllTests.selenium.click("link=Manage OpCos");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);
AllTests.selenium.click("link=Edit");
AllTests.selenium.waitForPageToLoad(AllTests.DEFAULT_TIMEOUT);


}




}



 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be a lot easier for us if you put some effort into formatting the code (read UseCodeTags for more details). But in this line:

The documentation suggests Plmn might be supposed to extend TestCase in that constructor, but it doesn't in your code. It's something to do with that, anyway.
 
santhosh kumar vk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks now it is working fine
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic