The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> Selenium

Pages: 1
JalpaKotecha
Newbie


Reged: 07/09/12
Posts: 7
Script to check sorting order of dates
      #713664 - 08/02/12 11:43 PM

Hi,

Can anyone let me know that how could we check that dates in the table are in ascending order or not using java in selenium webdriver??

Dates are in mm/dd/yyyy format.

Thanks,
Jalpa


Post Extras: Print Post   Remind Me!   Notify Moderator  
voks
Member


Reged: 09/12/06
Posts: 199
Re: Script to check sorting order of dates [Re: JalpaKotecha]
      #713788 - 08/05/12 04:06 PM

import java.text.SimpleDateFormat;
import java.util.*;
public class CompareDate {
public static void main(String args[])throws Exception{
String date = "08/05/2012";
String date1 = "08/04/2012";
SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
Date utilDate1 = dateFormat.parse(date);
Date utilDate2 = dateFormat.parse(date1);
ArrayList list = new ArrayList();
list.add(utilDate1);
list.add(utilDate2);
System.out.println("The unsorted date "+list);
Collections.sort(list);
System.out.println("The sorted date is "+list);
}

}


Post Extras: Print Post   Remind Me!   Notify Moderator  
MilesToGoBeforeISleep
Super Member


Reged: 09/15/10
Posts: 1887
Re: Script to check sorting order of dates [Re: voks]
      #713998 - 08/08/12 01:00 AM

Jalpa,

One way is to save all the etrieved dates in an array.

Iterate through the same and use the After, before and Equals method of Java.Util.Date Class.

One way to do so is iterate through the array, take the first element and the second element and check if

first date is before the second date or if these both are equal.

If yes then u can move with 2nd date and third date and so on..

Not sure, if this is a good way of doing, will wait and check for much better solutions.

--------------------
Thanks,
Ganns!!!
<< Why are you so obsessed at finding bugs >>


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 4 anonymous users are browsing this forum.

Moderator:  LNB, AJ, michaeljf 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 2538

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5