Setup Menus in Admin Panel

ITeLearn.com

Getting the java.io.FileNotFoundException error (Any help is appreciated ) | Selenium Automation | Discussions | ITeLearn.com

Forum usage guidelines

  1. Search First.: If you don’t find a similar post, start a new topic. If you find a similar thread and still have a question, reply to that topic. Duplicate threads will be ignored/deleted without warning.
  2. Proper Subject: Ensure you choose a very appropriate topic name. Else it will be tough to get support from other members.
  3. Patience, please: Our Tech team or other members will usually try to respond within 24 hours on weekdays and max within 48 hours on weekends. Sometimes sooner.
  4. Share opinions: Please feel free to reply, add or comment on any ongoing topics. Collective learning will be of great benefit to all.

 
ITeLearn reviews from participants.

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Getting the java.io.FileNotFoundException error (Any help is appreciated )
April 19, 2017
3:06 pm
Sridevi Minchala
New Member
Forum Posts: 1
Member Since:
January 27, 2017
Offline

If you see the exception below, error points to the “FileInputStream myStream = new FileInputStream(myxl); ” line in DDf2.readXL method
The path looks correct when I printed the fpath variable value.

Exception Details:
java.io.FileNotFoundException: ‪C:\Selenium\sws\Ddf2\DataD.xls (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at DDf2.readXL(DDf2.java:107)
at DDf2.beforeTest(DDf2.java:35)

Here is the code:
import java.io.FileInputStream;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.FileOutputStream;

public class DDf2
{
WebDriver driver;
String vBrowserName, vURL, vEmailID , vExpMessage, vActualMsg,vResult;
static int xRows, xCols;
String [][] xData;
static String xlpath;
String xlsheet;
static int i;
@Before
public void beforeTest() throws Exception
{
System.setProperty(“webdriver.firefox.marionette”,”C:\\Selenium\\lib\\geckodriver.exe”);
driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Initialize the variables
//Read the test data from excel
xlpath= “‪C:\\Selenium\\sws\\Ddf2\\DataD.xls”;
xlsheet=”TestData”;
xData=readXL(xlpath, xlsheet);
}

@Test
public void myTest()
{
//Read the excel
//We get each set in to variables
//run the testcase
// Repeat till the end of excelfile

for(i=1;i<xRows;i++)
{
vBrowserName=xData[i][1];
vURL=xData[i][2];
vEmailID=xData[i][3];
vExpMessage=xData[i][4];
//Go to AUT
driver.get(vURL);
recoverPassword(vEmailID);
verifyalertMessage(vExpMessage);
//Close Browser*/
}
}

@After
public void afterTest()
{

}
public void verifyalertMessage(String vExpMessage)
{
//Purpose:verify alert
//Input:Expectedmessage
//Output:none
String vActualMsg=driver.findElement(By.id("hideMe")).getText();
System.out.println("Actual msg is " + vActualMsg);
System.out.println("Expected msg is " + vExpMessage);
if(vActualMsg.equals(vExpMessage))
{
vResult= "Pass";
}else
{
vResult= "Fail";
}
System.out.println("Test Case is " + vResult);
}
public void recoverPassword(String vEmailID )
{
//Purpose:verify recoverpassword
//Input:EmailID
//Output:none
driver.findElement(By.xpath(".//*[@id=’forgot_password_link’]")).click();
//Enter EmailID
driver.findElement(By.id("forgot_email")).clear();
driver.findElement(By.id("forgot_email")).sendKeys(vEmailID);
//Click on Recover button
driver.findElement(By.name("submit")).click();
//Verify the message
}

public String[][] readXL(String fpath, String fsheet) throws Exception
{
// Purpose : Read an Excel file into a 2D array
// Inputs : XL Path and XL Sheet name
// Output : 2D Array
String[][] fData;
File myxl = new File(fpath);
FileInputStream myStream = new FileInputStream(myxl);
// @SuppressWarnings("resource")
HSSFWorkbook myWB = new HSSFWorkbook(myStream);
HSSFSheet mySheet = myWB.getSheet(fsheet);
xRows = mySheet.getLastRowNum()+1;
xCols = mySheet.getRow(0).getLastCellNum();
System.out.println("Total Rows in Excel are " + xRows);
System.out.println("Total Cols in Excel are " + xCols);
fData = new String[xRows][xCols];
for (int i = 0; i < xRows; i++)
{
HSSFRow row = mySheet.getRow(i);
for (int j = 0; j < xCols; j++)
{
HSSFCell cell = row.getCell(j);
String value = "-";
if (cell!=null)
{
value = cellToString(cell);
}
fData[i][j] = value;
System.out.print(value);
System.out.print("—-");
}
System.out.println("");
}
myWB.close();
myxl = null; // Memory gets released
return fData;
}
@SuppressWarnings("deprecation")
public static String cellToString(HSSFCell cell)
{
// This function will convert an object of type excel cell to a string value
int type = cell.getCellType();
Object result;
switch (type)
{
case HSSFCell.CELL_TYPE_NUMERIC: //0
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING: //1
result = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA: //2
throw new RuntimeException("We can’t evaluate formulas in Java");
case HSSFCell.CELL_TYPE_BLANK: //3
result = "%";
break;
case HSSFCell.CELL_TYPE_BOOLEAN: //4
result = cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_ERROR: //5
throw new RuntimeException ("This cell has an error");
default:
throw new RuntimeException("We don’t support this cell type: " + type);
}
return result.toString();
}
/*
public static void writeXL(String fPath, String fSheet, String[][] xData) throws Exception
{
File outFile = new File(fPath);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet osheet = wb.createSheet(fSheet);
int xR_TS = xData.length;
int xC_TS = xData[0].length;
for (int myrow = 0; myrow < xR_TS; myrow++)
{
HSSFRow row = osheet.createRow(myrow);
for (int mycol = 0; mycol < xC_TS; mycol++)
{
HSSFCell cell = row.createCell(mycol);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(xData[myrow][mycol]);
}
FileOutputStream fOut = new FileOutputStream(outFile);
wb.write(fOut);
fOut.flush();
fOut.close();
}
}*/
}

April 26, 2017
9:20 am
Techhelp
Member
Forum Posts: 1940
Member Since:
October 26, 2012
Offline

I would suggest to put excel some where else in other directory cause windows restrict users to edit any files inside it.

Forum Timezone: UTC -8

Most Users Ever Online: 70

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Techhelp: 1940

Manu: 114

Shan Nathan: 80

Palanki sai charan: 67

Userone: 59

Vishal Anand: 53

Archana Sapre: 51

Geetha Reddy: 44

useL: 38

Kavya Vangala: 37

Member Stats:

Guest Posters: 19

Members: 8069

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 22

Topics: 2124

Posts: 5829

Newest Members: Drashti Patel, Anirudh Kumar Vandhanapu, Jyothika Vuppunuthula, Enterprise HoldingsInc, Devasish kar, Anupama Sood, Thrilok Thrilok, HARISH PUTTA, Immanuel Michealraj, Sarvani Uppati

Administrators: Karthik eLearn (Admin): 49

0 Responses on Discussions"

Main Menu