Re: [selenium-users] Rename file in Selenium IDE

779 views
Skip to first unread message
Message has been deleted

Lutfi Dughman

unread,
May 19, 2011, 2:47:40 PM5/19/11
to seleniu...@googlegroups.com
im not sure how can you use selenium to rename a file.

but if you use java.io.File, you will be able to find and rename the file.

or maybe a simple does batch would do. 

But not through selenium (as far as i know)

On Thu, May 19, 2011 at 2:35 PM, Rich <richard...@gmail.com> wrote:
I have a scenario where I click a link on a web site to download a
file from via Selenium IDE. The filename of the downloaded file has a
date/timestamp in it; hence, it's dynamic. Once it's downloaded to the
filesystem, I would like to rename it. This needs to work when running
Selenium on Linux and Windows. What is the best way to achieve this?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


DongXiang

unread,
Jul 4, 2012, 5:07:12 AM7/4/12
to seleniu...@googlegroups.com

 

Date: Wed, 4 Jul 2012 01:59:46 -0700
From: cosmi...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Rename file in Selenium IDE

If you use Java, you can use following codes to download your file, then, how to change the file name is not a problem.
 
It needs the JSESSIONID, you can get it from cookie, the URI means the whole link to download the file, you can get it from the WebElement.
 
  OutputStream os = null;
  HttpClient httpClient = null;
  try {
   HttpParams params = new BasicHttpParams();
   HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
   HttpProtocolParams.setContentCharset(params, "UTF-8");
   HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
   HttpProtocolParams.setUseExpectContinue(params, true);
   httpClient = new DefaultHttpClient(params);
   HttpGet httpGet = new HttpGet(uri);
   // set the sessionid to the cookie.
   if (!StringUtils.isEmpty(sessionId)) {
    httpGet.setHeader("Cookie", "JSESSIONID=" + sessionId);
   }
   HttpResponse response = httpClient.execute(httpGet);
   Header[] headers = response.getAllHeaders();
   String fileName = "";
   for (Header header : headers) {
    if (header.getName().equals(CONTENT_DISPOSITION)) {
     fileName = StringUtils.substringBetween(header.getValue(),
       "\"", "\"");
    }
   }
   if (!StringUtils.isEmpty(fileName)) {
    fileName = savePath + File.separator + fileName;
   } else {
    fileName = savePath + File.separator
      + System.currentTimeMillis() + ".download";
   }
   InputStream is = response.getEntity().getContent();
   File outFile = new File(fileName);
   if (!outFile.exists()) {
    outFile.createNewFile();
   }
   os = new FileOutputStream(outFile);
   byte[] buf = new byte[4096];
   int read;
   while ((read = is.read(buf)) != -1) {
    os.write(buf, 0, read);
   }
   return fileName;
  } finally {
   if (os != null)
    os.close();
   if (httpClient != null)
    httpClient.getConnectionManager().shutdown();
  }
 
 
with firefox you can use a combination of tow extensions to do this
1.  flashgot extension to automatically perform the download action
2.  downloadthemall to download to a specific folder and rename the file ( removing the timestamp)


On Thursday, May 19, 2011 8:47:40 PM UTC+2, lutfijd wrote:
im not sure how can you use selenium to rename a file.

but if you use java.io.File, you will be able to find and rename the file.

or maybe a simple does batch would do. 

But not through selenium (as far as i know)

On Thu, May 19, 2011 at 2:35 PM, Rich <richard...@gmail.com> wrote:
I have a scenario where I click a link on a web site to download a
file from via Selenium IDE. The filename of the downloaded file has a
date/timestamp in it; hence, it's dynamic. Once it's downloaded to the
filesystem, I would like to rename it. This needs to work when running
Selenium on Linux and Windows. What is the best way to achieve this?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/pxkhn8GhZokJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.
Reply all
Reply to author
Forward
0 new messages