To check the order of list, must be in alpahbetical order.

3,884 views
Skip to first unread message

Utsav Sinha

unread,
Jun 18, 2012, 5:43:56 AM6/18/12
to seleniu...@googlegroups.com
Hi,

I am using selenium RC and my project requires to automate the following test case.

While the user logs in to the home page and selects option 'xyz' from categories tab then the list of 'xyz' should appear on the page in alphabetical order.
Like xyz - Australia, xyz - Bangladesh, xyz - India and so on.

Please suggest if there is any function in selenium that allows to test this ordering on the page.

--
Regards,
Utsav Sinha
Cell: 987334-0189

Smita Sinha

unread,
Jun 18, 2012, 7:21:58 AM6/18/12
to seleniu...@googlegroups.com
Ae you aware of the list that should be displayed on the page?
I mean is the list static?
 
Thanks,
Smita

--
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-US.

Utsav Sinha

unread,
Jun 18, 2012, 7:30:18 AM6/18/12
to seleniu...@googlegroups.com
No not exactly static. But in case it is do we have any thing to help.

Regards,
Utsav Sinha

Smita Sinha

unread,
Jun 18, 2012, 8:01:32 AM6/18/12
to seleniu...@googlegroups.com
As far as I know I do not think we have something in selenium to handle this.
 
But, If you are on JAVA may be you can use
String.compareTo(*String)
returns 0, -ve, +ve integer if the String  compared is equal, comes before in the dic, comes after in the dic respectively.
 
This easily does the Job.
 
-Smita

Utsav Sinha

unread,
Jun 18, 2012, 8:18:50 AM6/18/12
to seleniu...@googlegroups.com
Thanks Smita for your quick reply, I hope this helps.

Regards.
Utsav

praveen patil

unread,
Jun 18, 2012, 8:36:01 AM6/18/12
to seleniu...@googlegroups.com
U can try String.contains() as well in java....
             PRAVEEN PATIL
"No Man is worth ur tears and the one who is.... ... wont make u cry....."

Mike Riley

unread,
Jun 18, 2012, 1:11:51 PM6/18/12
to seleniu...@googlegroups.com
I am doing this by gathering all the elements into a List<String>, where the list is populated with the getText() for the WebElement that is displayed on the page, if the order they are displayed.  I then copy it to another List<String> and sort that list.  You can then compare them to see if they are equal.  If they are not then they are not displayed in sorted order.

The code looks like this:
try
{
    List<String> displayed = new ArrayList<String>();
    List<String> sorted = new ArrayList<String>();
    List<WebElement> invoices = helper.getTransactionLinkElements(); // driver.findElements()

    for (int i = 0; i < invoices.size(); i++)
    {   // Get all the customer names
        String str;

        str = helper.getInvoiceCustomerName(invoices.get(i)); // Does getText() for Customer Name column
        displayed.add(str); // Added as they are displayed
        sorted.add(str);
    }   // for

    Collections.sort(sorted); // Sort the list
    if (!displayed.equals(sorted))
    {
        final String failedMsg = "Customer Names are not in sorted order.";
        helper.logException(failedMsg, null);
        passed = false;
        assertTrue(passed, failedMsg);
    }   // if
}   // try
catch (Exception ex)
{
    final String failedMsg = "Failed trying to check order for Customer Names.";
    helper.logException(failedMsg, ex);
    passed = false;
    assertTrue(passed, failedMsg);
}   // catch

Mike

Utsav Sinha

unread,
Jun 19, 2012, 12:45:51 AM6/19/12
to seleniu...@googlegroups.com
Thanks everyone for your inputs, i will let you know which mechanism did i follow.

--
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/-/K_Ywt5qPlusJ.

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.

Ramesh

unread,
Nov 27, 2012, 12:19:14 AM11/27/12
to seleniu...@googlegroups.com

Hi Utsav,

Same problem I have now .please
let me know which mechanism are you followed.

regards
Ramesh kumar

Utsav Sinha

unread,
Nov 27, 2012, 12:31:56 AM11/27/12
to seleniu...@googlegroups.com
I followed the approach suggested by Mike and made some modifications according to my requirement. You can either proceed with Mike's suggestion or follow some other good advices made by Sai and Smita.

Regards,
Utsav Sinha
Cell: +91-987-397-6745



To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/9EXtw6Owp94J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Raj Lakhanpal

unread,
Dec 20, 2014, 9:26:11 PM12/20/14
to seleniu...@googlegroups.com, lvsk...@cox.net
Hi Mike, the list that I am working on seems sorted, but I also get an error that the list is not in alphabetical order, any suggestions? Thanks!
Reply all
Reply to author
Forward
0 new messages