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

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";
}
}

Related

NullPointer Exception while running a test in TestNG and Selenium

I have 4 methods which invokes my browser, logs in to the page and does some actions. When I run the code as a Java application, the browser opens up and the actions are performed, but when I run as a TestNG test, the console shows all 4 test passed, but it also shows Null Pointer Exception. Also, when running as testng test, it's not invoking my browser and performing the actions.
Code:
package pulse.tpr;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.*;
public class LoginInterface {
public WebDriver driver;
public Actions actions;
public void launchApplication() {
System.setProperty("webdriver.chrome.driver",
"C:\\MyChromeDriver\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("myURL");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
actions = new Actions(driver);
}
public void closeApplication() {
driver.close();
}
#Test(priority = 0)
public void adminLogin() {
try {
actions.moveToElement(driver.findElement(By.name("userId")));
actions.click();
actions.sendKeys("sysadmin");
actions.build().perform();
actions.pause(java.time.Duration.ofSeconds(1));
actions.moveToElement(driver.findElement(By.name("password")));
actions.click();
actions.sendKeys("MMNext13#");
actions.build().perform();
actions.pause(java.time.Duration.ofSeconds(1));
actions.moveToElement(driver.findElement(By.name("dcNumber")));
actions.click();
actions.sendKeys("7036");
actions.build().perform();
} catch (Exception e) {
e.printStackTrace();
}
}
#Test(priority = 1)
public void tprPage() {
try {
actions.moveToElement(driver.findElement(By
.cssSelector("body > ion-app > ng-component > ion-nav > page-login > ion-content > div.scroll-content > ion-card > ion-grid > form > ion-list > div.login-button > button > span")));
actions.click();
actions.build().perform();
actions.moveToElement(driver.findElement(By.id("tab-t0-2")));
actions.click();
actions.build().perform();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
#Test(priority = 2)
public void createMove() {
try {
actions.moveToElement(driver.findElement(By
.className("send-associates-button")));
actions.click();
actions.build().perform();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
actions.moveToElement(driver.findElement(By
.cssSelector("#tabpanel-t0-2 > send-associate-page > ion-content > div.scroll-content > div > ion-list > ion-item:nth-child(4)")));
actions.click();
actions.build().perform();
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='footers']/ion-toolbar/div[2]/ion-row/ion-col[2]/button")));
actions.click();
actions.build().perform();
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-col[2]")));
actions.click();
actions.build().perform();
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-col[2]/ion-row[2]")));
actions.click();
actions.build().perform();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// Select to area
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-col[2]")));
actions.click();
actions.build().perform();
// Select to area
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-col[2]/ion-row[2]")));
actions.click();
actions.build().perform();
// Next button in to area page
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-footer/button")));
actions.click();
actions.build().perform();
} catch (Exception e) {
e.printStackTrace();
}
}
#Test(priority = 3)
public void rightNowToClockout() {
try {
// Right Now Time
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-row[4]")));
actions.click();
actions.build().perform();
// Next Button
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-footer/button")));
actions.click();
actions.build().perform();
// Clockout time
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-content/div[2]/div/div/ion-row[2]/ion-col")));
actions.click();
actions.build().perform();
// Next button
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-footer/button")));
actions.click();
actions.build().perform();
// Send Button
actions.moveToElement(driver.findElement(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-send-associates-page/ion-footer/ion-row/ion-row")));
actions.click();
actions.build().perform();
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath("//*[#id='tabpanel-t0-2']/tpr-summary-page/ion-content/div[2]/div/div[2]/div/ion-card/ion-row[1]/ion-col/ion-row[2]")));
String element = driver
.findElement(
By.xpath("//*[#id='tabpanel-t0-2']/tpr-summary-page/ion-content/div[2]/div/div[2]/div[1]/ion-card/ion-row[1]/ion-col/ion-row[2]/div[1]/label[1]"))
.getText();
Assert.assertTrue(element.contains("1:35"));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
LoginInterface obj = new LoginInterface();
obj.launchApplication();
obj.adminLogin();
obj.tprPage();
obj.createMove();
obj.rightNowToClockout();
}
}
And below is the testNG error:
java.lang.NullPointerException
at pulse.tpr.LoginInterface.adminLogin(LoginInterface.java:38)
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.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:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
java.lang.NullPointerException
at pulse.tpr.LoginInterface.tprPage(LoginInterface.java:67)
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.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)
Instead of running the script in the main method, you should run the script as a "TestNG Test" and to do the initial setup before running the tests you can use, BeforeSuite and AfterSuite.
So, you need to make two changes in your script:
Insert a tag #BeforeSuite before the method launchApplication() and insert a tag #AfterSuite before the method closeApplication() which would perform the setup and the closing of the driver before and after executing the script.
Remove the whole main method that you have written and then run the script as "TestNG Test", your tests should run as expected.

RemoteTestNG.java : 76 error while running TestNG test set

Below is the code which I am trying to run. As I run the below code, the website of Mercury tour opens and the execution stops there throwing a list of errors that are mentioned below after this code. I tried uninstalling and re-installing TestNG framework but in vain.
package testNG1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MercuryTours
{
public WebDriver driver;
public WebDriverWait wait;
#BeforeClass
public void openBrowser()
{
System.setProperty("webdriver.gecko.driver", "C:\\\\Users\\Diganta\\Desktop\\Workspace\\Library\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
wait = new WebDriverWait(driver, 10);
driver.get("http://newtours.demoaut.com/");
}
#AfterMethod
public void goBackToHomePage()
{
driver.findElement(By.linkText("Home")).click();
wait.until(ExpectedConditions.titleContains("Welcome"));
}
#Test(priority=1)
public void verifySigninPage()
{
driver.findElement(By.linkText("SIGN-ON")).click();
wait.until(ExpectedConditions.titleContains("Sign-on"));
String actual = driver.getTitle();
String expected = "Sign-on: Mercury Tours";
Assert.assertEquals(actual, expected);
}
#Test(priority=2)
public void verifyRegisterPage()
{
driver.findElement(By.linkText("REGISTER")).click();
wait.until(ExpectedConditions.titleContains("Register"));
String actual = driver.getTitle();
String expected = "Register: Mercury Tours";
Assert.assertEquals(actual, expected);
}
#Test(priority=3)
public void verifySupportPage(){
driver.findElement(By.linkText("SUPPORT")).click();
wait.until(ExpectedConditions.titleContains("Support"));
String actual = driver.getTitle();
String expected = "Support: Mercury Tours";
Assert.assertEquals(actual, expected);
}
#Test(priority=4)
public void verifyContactPage()
{
driver.findElement(By.linkText("CONTACT")).click();
wait.until(ExpectedConditions.titleContains("Contact"));
String actual = driver.getTitle();
String expected = "Contact: Mercury Tours";
Assert.assertEquals(actual, expected);
}
#AfterClass
public void closeBrowser()
{
driver.close();
}
}
I am getting the below error in the Eclipse output console
FAILED CONFIGURATION: #AfterMethod goBackToHomePage
java.lang.NullPointerException
at testNG1.MercuryTours.goBackToHomePage(MercuryTours.java:36)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:723)
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)
SKIPPED CONFIGURATION: #AfterClass closeBrowser
FAILED: verifySigninPage
java.lang.NullPointerException
at testNG1.MercuryTours.verifySigninPage(MercuryTours.java:43)
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.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)
SKIPPED: verifyRegisterPage
java.lang.NullPointerException
at testNG1.MercuryTours.goBackToHomePage(MercuryTours.java:36)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:723)
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)
SKIPPED: verifySupportPage
java.lang.NullPointerException
at testNG1.MercuryTours.goBackToHomePage(MercuryTours.java:36)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:723)
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)
SKIPPED: verifyContactPage
java.lang.NullPointerException
at testNG1.MercuryTours.goBackToHomePage(MercuryTours.java:36)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:723)
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)
===============================================
Default test
Tests run: 4, Failures: 1, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 4, Failures: 1, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================
The error #AfterMethod goBackToHomePage and java.lang.NullPointerException says it all.
You have declared an instance of WebDriver as in public WebDriver driver; as a global variable within the Class scope.
Moving forward in openBrowser() method under #BeforeClass annotation you have initiated another instance of WebDriver as in WebDriver driver=new FirefoxDriver();.
So, once the execution comes out of executing the very first method, goBackToHomePage() method within #AfterMethod annotation is called where the dangling driver instance comes into play and causes you a java.lang.NullPointerException.
Solution:
Here the immediate solution will be to use a single instance of WebDriver across your program which you have declared globally at the Class level and change WebDriver driver=new FirefoxDriver(); to driver=new FirefoxDriver();

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(); }

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

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.

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.

Resources