IllegalArgumentException while starting Wildfly-Swarm [provided custom Main method] - wildfly-swarm

A weird exception is throwing while I'm attempting to run my wildfly-swarm instance. Following is the error that I'm getting;
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.Main.invoke(Main.java:78)
at org.wildfly.swarm.bootstrap.Main.run(Main.java:53)
at org.wildfly.swarm.bootstrap.Main.main(Main.java:44)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:80)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:95)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:72)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.access$000(JAXRSArchiveImpl.java:41)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl$ApplicationHandler.handle(JAXRSArchiveImpl.java:249)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.invokeHandlers(MemoryMapArchiveBase.java:238)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.addAsset(MemoryMapArchiveBase.java:185)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:126)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.add(ArchiveBase.java:376)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:151)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.add(ContainerBase.java:141)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1729)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1928)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1941)
at org.wildfly.swarm.spi.api.DependenciesContainer.addAllDependencies(DependenciesContainer.java:34)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.addPackageResources(FSIndexerBootStrap.java:78)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.bootUpApplication(FSIndexerBootStrap.java:94)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.main(FSIndexerBootStrap.java:109)
... 7 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.Main.invoke(Main.java:78)
at org.wildfly.swarm.bootstrap.Main.run(Main.java:53)
at org.wildfly.swarm.bootstrap.Main.main(Main.java:44)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:80)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:95)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.hasApplicationPathAnnotation(JAXRSArchiveImpl.java:72)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl.access$000(JAXRSArchiveImpl.java:41)
at org.wildfly.swarm.jaxrs.internal.JAXRSArchiveImpl$ApplicationHandler.handle(JAXRSArchiveImpl.java:249)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.invokeHandlers(MemoryMapArchiveBase.java:238)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.addAsset(MemoryMapArchiveBase.java:185)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:126)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.add(ArchiveBase.java:376)
at org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase.add(MemoryMapArchiveBase.java:151)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.add(ContainerBase.java:141)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1729)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1928)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1941)
at org.wildfly.swarm.spi.api.DependenciesContainer.addAllDependencies(DependenciesContainer.java:34)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.addPackageResources(FSIndexerBootStrap.java:78)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.bootUpApplication(FSIndexerBootStrap.java:94)
at com.research.fsindexer.bootstrap.FSIndexerBootStrap.main(FSIndexerBootStrap.java:109)
... 7 more
I had used a custom Main method. Following is the code for my Main method;
public final class FSIndexerBootStrap {
private void addDependencies ( JAXRSArchive archive ) {
/*
* Collection< String > suppliedDependencies =
* ResearchSuppliedDependenciesConfigurationReader
* .getSuppliedDependencies();
*
* if ( CollectionUtils.isNotEmpty( suppliedDependencies ) ) {
*
* suppliedDependencies.stream().forEach( suppliedDependency -> { try {
* archive.addDependency( ( String ) suppliedDependency ); } catch (
* Exception e ) { // TODO Auto-generated catch block
* e.printStackTrace(); } } ); }
*/
}
private void addSystemProperties () {
String logFileAbsoluteName = ResearchLoggingConfigurationReader.getLogFileAbsoluteName();
if ( StringUtils.isNotBlank( logFileAbsoluteName ) ) {
System.setProperty( "research.log", logFileAbsoluteName );
}
}
private void addPackageResources ( JAXRSArchive archive ) throws IllegalArgumentException, Exception {
if ( !Objects.equals( null, archive ) ) {
// archive.addPackages( true, "com/research/fsindexer" );
archive.addResource( FSIndexerRestApplication.class ).addResource( RESTTest.class )
.addResource( FileIndexerService.class )
.addAsWebInfResource(
new ClassLoaderAsset( "META-INF/beans.xml", FSIndexerBootStrap.class.getClassLoader() ),
"classes/META-INF/beans.xml" )
.addAllDependencies();
}
}
#ExceptionHandled
#Logged
public void bootUpApplication () throws Exception {
addSystemProperties();
final Swarm SWARM = new Swarm( true );
final JAXRSArchive DEPLOYMENT = ShrinkWrap.create( JAXRSArchive.class );
DEPLOYMENT.as( TopologyArchive.class );
addPackageResources( DEPLOYMENT );
addDependencies( DEPLOYMENT );
SWARM.start();
SWARM.deploy( DEPLOYMENT );
}
/**
* #param args
* #throws Exception
*/
public static void main ( String... args ) throws Exception {
FSIndexerBootStrap fsBootStrap = new FSIndexerBootStrap();
fsBootStrap.bootUpApplication();
}
}
The exception is throwing from the addAllDependencies() method call of the JAXRSArchive. I'd tried a debugging but can't figure out the real issue.

Related

unable to handle blank cells while reading blank cell from excel in selenium?

I am trying to read values for excel but my excel file contains some blank cells when I try to read values for those files using dataprovider then I get nullpointer
Please let me know how to deal with these blank cells in excel file??
Please find my excel file as below:-
Please find attached my Page object file code as :-
Please find attached my excelutility code as below:-
public class XLUtility {
public static FileInputStream fi;
public static XSSFWorkbook wb;
public static XSSFSheet ws;
public static XSSFRow row;
public static XSSFCell cell;
public XLUtility(String xlfile,String xlsheet) throws IOException{
try {
FileInputStream Excelfile=new FileInputStream(xlfile);
wb=new XSSFWorkbook(Excelfile);
ws=wb.getSheet(xlsheet);
} catch (Exception e) {
e.getMessage();
e.printStackTrace();
}
}
public static void setExcelFile(String xlfile,String xlsheet) throws Exception {
try {
FileInputStream ExcelFile = new FileInputStream(xlfile);
wb = new XSSFWorkbook(ExcelFile);
ws = wb.getSheet(xlsheet);
} catch (Exception e){
System.out.println("Exception occured is"+e);
}
}
public int getRowCount() throws IOException
{
int rowcount=ws.getLastRowNum();
return rowcount;
}
public int getCellCount(int rownum) {
row=ws.getRow(rownum);
int cellcount=row.getLastCellNum();
return cellcount;
}
public String getCelldata(int rownum,int colnum) {
row=ws.getRow(rownum);
cell=row.getCell(colnum);
String data;
try
{
DataFormatter formatter = new DataFormatter();
String cellData = formatter.formatCellValue(cell);
return cellData;
}
catch (Exception e)
{
data="";
}
return data;
}
}
Please find my test class code as below:-
Please find console output as below:-
[RemoteTestNG] detected TestNG version 6.14.3
FAILED: loginDDT("BlaBla", "")
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy8.sendKeys(Unknown Source)
at com.AutomationTest.PageObjects.PageoneObjects.login(PageoneObjects.java:20)
at com.AutomationTest.Testcases.TC_App_001.loginDDT(TC_App_001.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: loginDDT("", "BlaBla")
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy8.sendKeys(Unknown Source)
at com.AutomationTest.PageObjects.PageoneObjects.login(PageoneObjects.java:20)
at com.AutomationTest.Testcases.TC_App_001.loginDDT(TC_App_001.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: loginDDT("BlaBla", "BlaBla")
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy8.sendKeys(Unknown Source)
at com.AutomationTest.PageObjects.PageoneObjects.login(PageoneObjects.java:20)
at com.AutomationTest.Testcases.TC_App_001.loginDDT(TC_App_001.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
when reading for cell, need to cross check cell type. like below
public String getCellData(String sheetName,int colNum,int rowNum){
try{
if(rowNum <=0)
return "";
int index = workbook.getSheetIndex(sheetName);
if(index==-1)
return "";
sheet = workbook.getSheetAt(index);
row = sheet.getRow(rowNum-1);
if(row==null)
return "";
cell = row.getCell(colNum);
if(cell==null)
return "";
if(cell.getCellType()==Cell.CELL_TYPE_STRING)
return cell.getStringCellValue();
else if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC || cell.getCellType()==Cell.CELL_TYPE_FORMULA ){
String cellText = String.valueOf(cell.getNumericCellValue());
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// format in form of M/D/YY
double d = cell.getNumericCellValue();
Calendar cal =Calendar.getInstance();
cal.setTime(HSSFDateUtil.getJavaDate(d));
cellText =
(String.valueOf(cal.get(Calendar.YEAR))).substring(2);
cellText = cal.get(Calendar.MONTH)+1 + "/" +
cal.get(Calendar.DAY_OF_MONTH) + "/" +
cellText;
// System.out.println(cellText);
}
return cellText;
}else if(cell.getCellType()==Cell.CELL_TYPE_BLANK)
return "";
else
return String.valueOf(cell.getBooleanCellValue());
}
catch(Exception e){
e.printStackTrace();
return "row "+rowNum+" or column "+colNum +" does not exist in xls";
}
}

Dataprovider anotation - Testng Selenium Java

Query - The last set of values keep failing, the error that i am getting is that its unable to fine the xpath, but its working fine for other two cases. So a bit confused. I have pasted the error code as well. Would appreciate any help I can get. Thanks in advance.
Test Code -
#Test(priority = 4, dataProvider = "getData")
public void loginScenario(String Username, String Password) throws InterruptedException {
WebElement user = driver.findElement(By.xpath(".//*[#id='LoginForm_username']"));
if(null != user) {
user.clear();
}
WebElement pass = driver.findElement(By.xpath(".//*[#id='LoginForm_password']"));
if(null != pass) {
pass.clear();
}
// driver.findElement(By.xpath(".//*[#id='LoginForm_username']")).click();
// driver.findElement(By.xpath(".//*[#id='LoginForm_username']")).click();
driver.findElement(By.xpath(".//*[#id='LoginForm_username']")).sendKeys(Username);
driver.findElement(By.xpath(".//*[#id='LoginForm_password']")).sendKeys(Password);
driver.findElement(By.xpath(".//*[#id='login-form']/button")).click();
driver.findElement(By.xpath(".//*[#id='LoginForm_username']")).clear();
driver.findElement(By.xpath(".//*[#id='LoginForm_password']")).clear();
}
#DataProvider
public Object[][] getData() {
Object[][] data = new Object[3][2];
data[0][0] = "abcd";
data[0][1] = "xyz";
data[1][0] = "...";
data[1][1] = ".";
data[2][0] = "blah#blah.com";
data[2][1] = "kingkongkijai";
return data;
}
}
Error -
FAILED: loginScenario("blah#blah.com", "kingkongkijai")
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[#id='LoginForm_username']"}
Command duration or timeout: 51 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)
at pages.LoginPage.loginScenario(LoginPage.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[#id='LoginForm_username']"}
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
#Madis Kangro
I just added the below code after you inputs and you were bang on ! Thanks so much
WebElement user = driver.findElement(By.xpath(".//*[#id='LoginForm_username']"‌​)); if(null != user) { user.clear(); } WebElement pass = driver.findElement(By.xpath(".//*[#id='LoginForm_password']"‌​)); if(null != pass) { pass.clear(); }

cameltest case with bean

In my java class i have something like below:
from("direct:dcrm:input")
.routeId("dcrm-route"
.convertBodyTo(Message.class)
.setHeader(
"recipientListHeader",
simple("activemq:"+rdvrQueueName+ ".${body.controllerID}?jmsMessageType=Text&timeToLive="
+ rdvrMessageTimeToLive
+ "&deliveryPersistent=" + deliveryPersistent))
.choice()
.when(simple("${body.messageType} == 'rdvr'"))
.bean(new DcrmMessageHandler(), "process")
.marshal(requestMessage)
.recipientList(header("recipientListHeader"))
.onPrepare(new MesssageProcessor()).parallelProcessing()
.end()
.setBody(constant(StatusCode.SUCCESS))
.otherwise()
.endChoice();
while writing Junit i am doint like this :
#Test
public void testSendMatchingMessage() throws Exception {
String expectedBody = "<matched/>";
resultEndpoint.expectedBodiesReceived(expectedBody);
template.sendBodyAndHeader(expectedBody, "recipientListHeader", 0);
resultEndpoint.assertIsSatisfied();
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
//return new DcrmOutboundRoute();
return new RouteBuilder() {
#Override
public void configure() throws Exception {
// TODO Auto-generated method stub
from("direct:dcrm:input")
.filter(header("recipientListHeader").isEqualTo(constant(StatusCode.SUCCESS)))
.bean(new DcrmMessageHandler(), "process").to("mock:result");
}
};
}
But I am getting the bellow error:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/NoResultException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Check your classpath or your Maven dependencies, in particular the one referencing JPA (javax.persistence). You should have a dependency with groupId javax.persistence and probably artifactId persistence-api, replace it by org.hibernate.javax.persistence or org.eclipse.persistence dependency.

Why ' Exception in Application start method, java.lang.reflect.InvocationTargetException ' occurs? [duplicate]

I am attempting to read values from MySQL database and display it in a table in JavaFX. I use netbeans IDE. When I run my code I got the exception mentioned in the title. I will post code below:
public class ViewSubject extends Application {
private final TableView<Subject> table = new TableView<>();
private final ObservableList<Subject> data
= FXCollections.observableArrayList();
final HBox hb = new HBox();
private Connection connect = null;
private Statement statement = null;
private final PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws ClassNotFoundException, SQLException {
Scene scene = new Scene(new Group());
stage.setTitle("Add Subject");
stage.setWidth(650);
stage.setHeight(550);
stage.setResizable(false);
final Label label = new Label("Subject Details");
label.setFont(new Font("Calibri", 20));
TableColumn sub = new TableColumn("Subject Name");
sub.setMinWidth(350);
sub.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subName"));
sub.setCellFactory(TextFieldTableCell.forTableColumn());
sub.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubName(t.getNewValue());
}
}
);
TableColumn code = new TableColumn("Subject Code");
code.setMinWidth(130);
code.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subCode"));
code.setCellFactory(TextFieldTableCell.forTableColumn());
code.setCellFactory(TextFieldTableCell.forTableColumn());
code.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubCode(t.getNewValue());
}
}
);
TableColumn rev = new TableColumn("Revision");
rev.setMinWidth(130);
rev.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subRev"));
rev.setCellFactory(TextFieldTableCell.forTableColumn());
rev.setCellFactory(TextFieldTableCell.forTableColumn());
rev.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubCode(t.getNewValue());
}
}
);
table.setItems(data);
table.getColumns().addAll(sub, code, rev);
final VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.setPadding(new Insets(20, 20, 20, 20));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
resultSet = statement
.executeQuery("select * from subject");
writeResultSet(resultSet);
} catch (ClassNotFoundException | SQLException e) {
throw e;
} finally {
close();
}
}
private void writeResultSet(ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
String subname = resultSet.getString("subname");
String code = resultSet.getString("subcode");
String rev = resultSet.getString("subrev");
data.add(new Subject(subname, code, rev));
}
}
private void close() {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connect != null) {
connect.close();
}
} catch (SQLException e) {
}
}
}
There is one more class in the package -
public class Subject {
private final SimpleStringProperty sub;
private final SimpleStringProperty code;
private final SimpleStringProperty rev;
Subject(String subName, String subCode, String subRev) {
this.sub = new SimpleStringProperty(subName);
this.code = new SimpleStringProperty(subCode);
this.rev = new SimpleStringProperty(subRev);
}
public String getSubName() {
return sub.get();
}
public void setSubName(String subName) {
sub.set(subName);
}
public String getSubCode() {
return code.get();
}
public void setSubCode(String subCode) {
code.set(subCode);
}
public String getSubRev() {
return rev.get();
}
public void setSubRev(String subRev) {
rev.set(subRev);
}
}
This is the exception details:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.javafx.main.Main.launchApp(Main.java:698)
at com.javafx.main.Main.main(Main.java:871)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at viewsubject.ViewSubject.read(ViewSubject.java:119)
at viewsubject.ViewSubject.start(ViewSubject.java:113)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
... 1 more
When the code is ran, a window appears for a fraction of a second and then suddenly closes due to the occurrence of this exception. Why this exception occurs ? How can remove this exception?
You don't have the MySQL JDBC driver on your classpath.
Perform the Vogella tutorial on Java and JDBC with MySQL. Do the whole tutorial step by step, running code each step of the way. As part of the Vogella tutorial, it tells you how to setup 3rd party libraries (like the MySQL JDBC library) in Eclipse.
When posting code, try to post code which matches the stack trace. The StackTrace reports an error at viewsubject.ViewSubject.read(ViewSubject.java:119) but there is no such read function in your ViewSubject class.

' Exception in Application start method, java.lang.reflect.InvocationTargetException ' while reading and displaying from database

I am attempting to read values from MySQL database and display it in a table in JavaFX. I use netbeans IDE. When I run my code I got the exception mentioned in the title. I will post code below:
public class ViewSubject extends Application {
private final TableView<Subject> table = new TableView<>();
private final ObservableList<Subject> data
= FXCollections.observableArrayList();
final HBox hb = new HBox();
private Connection connect = null;
private Statement statement = null;
private final PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws ClassNotFoundException, SQLException {
Scene scene = new Scene(new Group());
stage.setTitle("Add Subject");
stage.setWidth(650);
stage.setHeight(550);
stage.setResizable(false);
final Label label = new Label("Subject Details");
label.setFont(new Font("Calibri", 20));
TableColumn sub = new TableColumn("Subject Name");
sub.setMinWidth(350);
sub.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subName"));
sub.setCellFactory(TextFieldTableCell.forTableColumn());
sub.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubName(t.getNewValue());
}
}
);
TableColumn code = new TableColumn("Subject Code");
code.setMinWidth(130);
code.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subCode"));
code.setCellFactory(TextFieldTableCell.forTableColumn());
code.setCellFactory(TextFieldTableCell.forTableColumn());
code.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubCode(t.getNewValue());
}
}
);
TableColumn rev = new TableColumn("Revision");
rev.setMinWidth(130);
rev.setCellValueFactory(
new PropertyValueFactory<Subject, String>("subRev"));
rev.setCellFactory(TextFieldTableCell.forTableColumn());
rev.setCellFactory(TextFieldTableCell.forTableColumn());
rev.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Subject, String>>() {
#Override
public void handle(TableColumn.CellEditEvent<Subject, String> t) {
((Subject) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setSubCode(t.getNewValue());
}
}
);
table.setItems(data);
table.getColumns().addAll(sub, code, rev);
final VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.setPadding(new Insets(20, 20, 20, 20));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
resultSet = statement
.executeQuery("select * from subject");
writeResultSet(resultSet);
} catch (ClassNotFoundException | SQLException e) {
throw e;
} finally {
close();
}
}
private void writeResultSet(ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
String subname = resultSet.getString("subname");
String code = resultSet.getString("subcode");
String rev = resultSet.getString("subrev");
data.add(new Subject(subname, code, rev));
}
}
private void close() {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connect != null) {
connect.close();
}
} catch (SQLException e) {
}
}
}
There is one more class in the package -
public class Subject {
private final SimpleStringProperty sub;
private final SimpleStringProperty code;
private final SimpleStringProperty rev;
Subject(String subName, String subCode, String subRev) {
this.sub = new SimpleStringProperty(subName);
this.code = new SimpleStringProperty(subCode);
this.rev = new SimpleStringProperty(subRev);
}
public String getSubName() {
return sub.get();
}
public void setSubName(String subName) {
sub.set(subName);
}
public String getSubCode() {
return code.get();
}
public void setSubCode(String subCode) {
code.set(subCode);
}
public String getSubRev() {
return rev.get();
}
public void setSubRev(String subRev) {
rev.set(subRev);
}
}
This is the exception details:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.javafx.main.Main.launchApp(Main.java:698)
at com.javafx.main.Main.main(Main.java:871)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at viewsubject.ViewSubject.read(ViewSubject.java:119)
at viewsubject.ViewSubject.start(ViewSubject.java:113)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
... 1 more
When the code is ran, a window appears for a fraction of a second and then suddenly closes due to the occurrence of this exception. Why this exception occurs ? How can remove this exception?
You don't have the MySQL JDBC driver on your classpath.
Perform the Vogella tutorial on Java and JDBC with MySQL. Do the whole tutorial step by step, running code each step of the way. As part of the Vogella tutorial, it tells you how to setup 3rd party libraries (like the MySQL JDBC library) in Eclipse.
When posting code, try to post code which matches the stack trace. The StackTrace reports an error at viewsubject.ViewSubject.read(ViewSubject.java:119) but there is no such read function in your ViewSubject class.

Resources