Search code examples
cucumber-jvmcucumber-javaserenity-bddcucumber-serenityserenity-js

A feature file having two individual scenarios having weird web locator problems


I have a feature file with having two scenarios: one for login to website, another one doing some actions on the logged in page. If I arrange the feature file with just one scenario, it is working fine, especially line highlighted in the first feature file given below. But if the same feature file arranged as having two scenarios, it gives a web locator problem, even though in the page object code, I give the same line of code to locate the web element.

The first scenario (with Outline) is just doing the login to the website. No objects stored, or any thing.

The second scenario is trying to verify some data on the page like whether row with userid and date being populated.

The problem is with the second feature file where I introduced the second scenario keyword, because it is rightfully another separate scenario.

NOTE:- The code used to locate the web element in the two places (maintained as SEPARATE PROJECTS) is SAME.

Please help me identify the problem. Driving me insane.

#########------This feature file runs FINE.-----
Feature: Data Extract List Page

    In order to test DataHub UI, 

     I want to specify the features of Extract History Page



  **Scenario Outline:** Navigate to Extract History page from the List page 

    Given the User opens the PRAMA Datahub website

     When the User types in userId "<uId>" and pacman passcode " 
      <pacman_passcode>"

      And the User clicks on submit button

     Then the User lands on page "<title>"  



     When status column-cell has status "Ready" value

     And last run column-cell has userid and date populated (NOTE:working 
     fine)

     And the User clicks on last run column cell of first extract record

      Then the User is navigated to the Execution History 
       "execution_history" page



     When the execution history page shows "completed" status

     And the User clicks on extract record header

     Then verify number of records greater than zero

     And file name is a valid string



    Examples: 

      | uId | pacman_passcode .  | title   | 

      | xxx | kT7&)cP^jhK&xze    | Datahub |  

###---This feature file CAN'T find a web element (the first after login)-#

**Feature:** Data Extract List Page

      In order to test DataHub UI, 

  I want to specify the features of Extract History Page



**Scenario:** User logs in to prama datahub website 

   Given the User opens the PRAMA Datahub website

   When the User types in userId "xxxxx" and pacman passcode 
    "kT7&)cP^jhK&"

    And the User clicks submit button

   Then the User lands on page "Datahub"



 **Scenario:**Navigate to Extract History page from the Extract List page

     Given User logs in to prama datahub website

     When status column-cell has status "Ready" value

     And last run column-cell has userid and date populated(NOTE: throwing 
    web element locator exception)

     And the User clicks on last run column cell of first extract record

    Then the User is navigated to the Execution History 
    "execution_history" page

UPDATE: Just for kicks, when I commented out the suspected 'Scenario' keyword and accompanying @Given step, which are practically not do any thing new, the web locators are found, NO PROBLEMO ! What the fun is happening here ? There is no storage of any data from the first login scenario, no nothing. Simply logged in, asked for the web locator.


**Feature:** Data Extract List Page

    In order to test DataHub UI, 

    I want to specify the features of Extract History Page



**Scenario:** User logs in to prama datahub website 

    Given the User opens the PRAMA Datahub website

When the User types in userId "pnutala" and pacman passcode "98hgdPwYxze"

  And the User clicks submit button

Then the User lands on page "Datahub"



 **#Scenario:Navigate to Extract History page from the Extract List page**

   **#Given User logs in to prama datahub website**

      When status column-cell has status "Ready" value

      And last run column-cell has userid and date populated

      And the User clicks on last run column cell of first extract record

      Then the User is navigated to the Execution History 
      "execution_history" page



      When the execution history page shows "completed" status

      And the User clicks on extract record header

      Then verify number of records greater than zero

      And file name is a valid string

Solution

  • This issue got figured out. The problem was due to NOT realizing that Cucumber treats every scenario as brand new browser session*

    (To me it felt weird, as a feature with multiple scenarios must be about testing a single individual story. Then why would you need to destroy and restart and relogin to browser again and again ?

    *). But from Serenity, I have a configuration to keep the browser session alive through out the life time of a feature (serenity.restart.browser.for.each=feature). Now after adjusting the initial opening condition of each scenario, all is working fine. –