Reputation: 85
(Hello world level automation tester here)
I am trying to download a file and rename it so it can be easy to find. I am getting an error.... this is the code
@Test
public void allDownload() throws Exception {
PiDownloadScreen();
WebElement oK = driver.findElement(By.xpath
("/html/body/div[4]/div[11]/div/button"));
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());
oK.click();
System.out.println(timeStamp);
File fileName = new File("C:/Users/HIQMD017/Downloads/" + timeStamp + (".csv"));
File newName = new File("C:/Users/HIQMD017/Downloads/allPI.csv");
if (fileName.renameTo(newName)) {
System.out.println("AllPI was renamed");
}
else
{
int timeStampInt = Integer.parseInt(timeStamp);
int completeStamp = timeStampInt - 1;
String completeString = Integer.toString(completeStamp);
File fileNameNew = new File("C:/Users/HIQMD017/Downloads/" + completeString + (".csv"));
fileNameNew.renameTo(newName);
System.out.println("All pi was renamed after conversion");
}
System.out.println(completeString);
}
I'm not sure why I'm getting these errors and what they mean, I'm also not too good with the debugger, could someone give some insight, I've looked over my code and it seems okay, har dto say where I'm going wrong. I'm happy to add other code if needed, of course I will need to modify for confidentiality.
java.lang.NumberFormatException: For input string: "20160908132027"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at TestingPIs.piTest.allDownload(piTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Kind Regards,
M
Upvotes: 0
Views: 57
Reputation: 7315
The string (timestamp) you are using is outside the range of integer. That's why it is throwing NumberFormatException. You can replace below code:
int timeStampInt = Integer.parseInt(timeStamp);
int completeStamp = timeStampInt - 1;
String completeString = Integer.toString(completeStamp);
By :
long timeStampLong = Long.parseLong(timeStamp);
long completeStamp = timeStampLong - 1;
String completeString = Long.toString(completeStamp);
I think that will work.
Upvotes: 1