Testing the cucumber pagination capabilities

I study and love cucumber, and now I have a function, I'm not sure about the best way to go through BDD: pagination. I have scripts (in my opinion) where there are zero pages, one page, several pages, etc., And where I want to make sure that certain entries are on certain pages, make sure that the “next” button is not is a link when to the last page, etc.

I will use will_paginate, so essentially I want to find out how BDD functions it for a specific list of items, like books.

I am sure I can confuse this, but I believe that this should be general and I would like to see what others did. Can someone recommend an article or point me to some code example or even take a snapshot using an example?

+3
source share
1 answer

You will probably be able to use scripting scripts to keep the repetition in your function file, but keep in mind that it will expand to a lot of actual scripts, so it will be slower than you expected. Perhaps something like this should work, assuming 5 books per page. I left the definitions of steps as an exercise, but they should be fairly simple.

, , .

Feature: Book Browsing Pagination

  Scenario: No results
    Given I have 0 books
    When I view all books
    Then I should see "No results" on the page

  Scenario: Some results
    Given I have 3 books
    When I view all books
    Then I should see "Book 1"
    And I should see "Book 2"
    And I should see "Book 3"

  Scenario: Page links
    Given I have <count> books
    When I view all books from page <page>
    Then I should see a link to page <target page>

    Examples:
      | count | page | target page |
      |   8   |   1  |       2     |
      |   8   |   2  |       1     |
      |  13   |   1  |       2     |
      |  13   |   1  |       3     |
      |  13   |   2  |       1     |
      |  13   |   2  |       3     |
      |  13   |   3  |       1     |
      |  13   |   3  |       2     |

  Scenario: Page links for current page
    Given I have <count> books
    When I view all books from page <page>
    Then I should see a disabled pagination link to page <page>

    Examples:
      | count | page |
      |   8   |  1   |
      |   8   |  2   |
      |  13   |  1   |
      |  13   |  2   |
      |  13   |  3   |

  Scenario: Next Page links
    Given I have <count> books
    When I view all books from page <page>
    Then I should see a link "Next Page"

    When I click "Next Page"
    Then I should be on page <next page> # assert against query params maybe?
    # alternately, to keep page requests down, one could use something like:
    # Then I should see a link "Next Page" going to "?p=<next page>"

    Examples:
      | count | page | next page |
      |   8   |   1  |      2    |
      |  13   |   1  |      2    |
      |  13   |   2  |      3    |

  Scenario: Next Page links on last page
    Given I have <count> books
    When I view all books from page <page>
    Then I should see a disabled pagination link "Next Page"

    Examples:
      | count | page |
      |   8   |   2  |
      |  13   |   3  |

//, Next, , , . , , 5, , , , 6 . , .

- , will_paginate, , , (, ).

, ;)

+18

Source: https://habr.com/ru/post/1719687/


All Articles