filename directory name volume label syntax is incorrect while taking a screenshot using webdriver

338 views
Skip to first unread message

Raghu veer

unread,
Nov 8, 2013, 1:47:36 AM11/8/13
to webd...@googlegroups.com
Hi

I am using the below function to take a screen shot and my framework is hybrid-driven + page factory

 public  void captureScreenShot(String obj) throws IOException {
  
   File screenshotFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     FileUtils.copyFile(screenshotFile,new File("Screenshots\\"+obj+""+GetTimeStampValue()+".png"));
}

when i use this function in some class and wanted to pass a string as a filename i am getting the error filename directory name volume label syntax is incorrect

EX: regprocess.captureScreenShot(validation);

validation is a string in which i am getting a validation message of the site , i wanted to save a snapshot with filename same as the validation message to identify.


Thanks 
Raghuveer


darrell

unread,
Nov 8, 2013, 12:44:26 PM11/8/13
to webd...@googlegroups.com
I would use:

    File screenshotFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    String file = String.format("Screenshots%s%s%s.png", System.getProperty("file.separator"), obj, GetTimeStampValue());
    // check to see if the directory Screenshots exists, if not, create it.
    FileUtils.copyFile(screenshotFile, new File(file));

Concatenating strings the way you are is not very efficient. It is better to use String.format to build a string from the other parts. Additionally, your code assumes a file separator is \ but this is only true for Windows. If you use the property file.separator this will work on non-Windows machines as well.

I put a comment in about creating the Screenshots directory if it doesn't already exist. As part of creating this directory you can also check for things like permissions and security. It is possible that the user you are running the tests under does not have write permission on the directory specified.

Also, I'm assuming GetTimeStampValue() returns a string. If it returns a int or long, change the last %s in the format string as necessary.

raghu veer

unread,
Nov 9, 2013, 11:19:28 AM11/9/13
to webd...@googlegroups.com
Thanks for your solution darrell i will work on it and let you know..
 

Thanks & Regards,
Raghu veer.
9490768280(Mobile)
Email:raghu03veer.@gmail.com 


--
You received this message because you are subscribed to a topic in the Google Groups "webdriver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/webdriver/WrSJTnFJTY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages