Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4592044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:28:54+00:00 2026-05-21T22:28:54+00:00

I need to write a cucumber scenario to test that a list of projects

  • 0

I need to write a cucumber scenario to test that a list of projects are sorted (by name). I have something like:

Scenario: Sort projects by name
   Given there is a project called "Project B"
   And there is a project called "Project A"
   And there is a project called "Project C"
   Given I am on the projects page
   When I follow "Sort by name"
   Then I should see in this order ["Project A", "Project B", "Project C"]

I have added a step, that looks like:

Given /^I should see in this order (\[.*\])$/ do |array|

end

What’s the best way to test if the projects that are listed on the page appear with the right order? I tried to get all the project names through jQuery:

$(function() {
    var arrjs = new Array();
    $("div.project-main-info").find("a:first").each(function(){
        arrjs.push($(this).text());
    })
  });

and put them inside an array to do a comparison with the array passed as a parameter to this step, but I don’t know how to integrate that jQuery code inside this step!

Thanks!

EDIT

As suggested by McStretch, I tried to get the anchors using XPath by doing:

all('a').each do |a|
    if(/\/projects\/\d*/).match("#{a[:href]}")
        arr_page << "...." # Need to retrieve the value out of <a href="..">VALUE</a> but don't know how..any idea?
    end
  end

Is this the right way to proceed? I just tested, and unfortunately arr_page doesn’t get filled with anything (I replaced the “…” part with a[:href] just to test)! Actually I tried to check the value of a[:href] (by raising it) and it’s blank! How would I better check my anchors (given there href all match the regex mentionned above)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:28:55+00:00Added an answer on May 21, 2026 at 10:28 pm

    Firstly, it would be better to write your final step as:

    Then I should see the projects in this order:
      | Project A |
      | Project B |
      | Project C |
    

    Now you can easily access the list as an array, e.g.

    expected_order = table.raw
    

    You then need to collect together the projects in the page into an array, as @McStretch suggests:

    actual_order = page.all('a.project').collect(&:text)
    

    (This assumes that each of your project links has a “project” CSS class to make testing easier).

    You can then use RSpec to compare the two arrays.

    expected_order.should == actual_order
    

    This will show a failure if the order is incorrect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need write a set of clauses that take a list of integer lists
I need to write a cucumber test to test datetime select behavior. here is
I need to write a C++ code coverage program that takes in another C++
I need to write a program that prints 0.(03) for input 1 and 33.
I need to write to a text file using JavaScript. I have a machine
I need to write the output of the code I have to a file
I need write a console application like as hiren boot screen: alt text http://xahoithongtin.com.vn/Images/diembao/2006_10/Hiren2.jpg
Need to write a post build event in VS 2010 project that copy just
I'm using Delphi 2007. I need write a FormatDateTime function that always return 01/01/
Need to write a function that will convert a string to a double without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.