Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Cypress Step Definitions to Reduce Duplication #629

Open
6 tasks
adriancofie opened this issue May 23, 2024 · 0 comments
Open
6 tasks

Refactor Cypress Step Definitions to Reduce Duplication #629

adriancofie opened this issue May 23, 2024 · 0 comments
Labels
on hold This will not be worked on task

Comments

@adriancofie
Copy link
Contributor

adriancofie commented May 23, 2024

TLDR: Reduce duplication, confusion, and non-deterministic code.

Currently our version of cypress-cucumber-preprocessor is far outdated and has some inherent deficiencies which required structuring the tests in a non-intuitive fashion.

This ticket is to update the preprocessor to the latest version (Note: the project maintainer changed hands a while ago and it's now @badeball/cypress-cucumber-preprocessor) and refactor the test cases to follow best practices where ideal.

There have been several breaking changes in the preprocessor and the version is now at v20.0.5 while we are at v4. We don't need to upgrade to the latest version but we should at the very least update to a version that allows us to have a sane directory structure.

Newer versions follow a well defined approach for matching step definitions:

https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/step-definitions.md


Note:

We currently have several duplicated step definitions, in the version we're using the preprocessor uses the first step definition it finds and ignores the rest, however looking statically at the code a developer would have no idea which definition to update in order make changes, nor know which ones not to change in order not to break something.

In later versions the preprocessor was updated to explicitly disallow step definitions from having duplicates-- this is the approach that cucumber itself follows (https://cucumber.io/docs/community/faq/?lang=java#duplicate-step-definition). Note this applies across defineStep types ('Given', 'Then' etc).


Note:

From version 13.0.0 onward support for AND and BUT is removed.

badeball/cypress-cucumber-preprocessor#821

See Release Notes for v13.0.0 https://github.com/badeball/cypress-cucumber-preprocessor/releases


Sub-Tasks

  • Update the preprocessor
  • Update the config and pattern matching for the preprocessor -- pull it out of package.json
  • Restructure features so they live in the same folder as their isolated step definition js
  • Move the location of common cross cutting step definitions
  • Deduplicate step definitions and move common ones to the same location
    • If a step should preferably keep the same gherkin but it has different logic for a specific component then the function itself should be abstracted and overridden

Nitty Gritty

Identical Step Definition Text and Functions

common/index.js identical duplications:

Given('trial info displays {string}', (infoText) => {...}):


BasicSearchPage.js, 
AdvancedSearchPage/AgeSection/index.js,
AdvancedSearchPage/KeywordsSection/index.js, 
AdvancedSearchPage/LeadOrganizationSection/index.js,
AdvancedSearchPage/TrialInvestigatorsSection/index.js, 
AdvancedSearchPage/TrialPhaseSection/index.js,
AdvancedSearchPage/TrialTypeSection/index.js, 
AdvancedSearchPage/DrugTreatmentSection/index.js,
AdvancedSearchPage/CancerTypeCondition/index.js, 
SearchResultsPage/GeneralPageComponents/index.js.

Given('the criteria table displays the following', (dataTable) => {...}):

 BasicSearchPage.js
 AdvancedSearchPage/AgeSection/index.js
 AdvancedSearchPage/KeywordsSection/index.js
 AdvancedSearchPage/LeadOrganizationSection/index.js
 AdvancedSearchPage/TrialInvestigatorsSection/index.js
 AdvancedSearchPage/TrialIdSection/index.js
 AdvancedSearchPage/TrialPhaseSection/index.js
 AdvancedSearchPage/TrialTypeSection/index.js
 AdvancedSearchPage/DrugTreatmentSection/index.js
 AdvancedSearchPage/CancerTypeCondition/index.js
SearchResultsPage/GeneralPageComponents/index.js

When('user clicks on Modify Search Criteria button', () => {...}):

BasicSearchPage.js
 AdvancedSearchPage/AgeSection/index.js
 AdvancedSearchPage/KeywordsSection/index.js
 AdvancedSearchPage/LeadOrganizationSection/index.js
 AdvancedSearchPage/TrialInvestigatorsSection/index.js
 AdvancedSearchPage/TrialIdSection/index.js
 AdvancedSearchPage/TrialPhaseSection/index.js
 AdvancedSearchPage/TrialTypeSection/index.js
 AdvancedSearchPage/DrugTreatmentSection/index.js
 AdvancedSearchPage/CancerTypeCondition/index.js
 SearchResultsPage/GeneralPageComponents/index.js

locationSection.js identical duplications:

Given('trial info displays {string}', (infoText) => {...}):


AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js 
 AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js

Given('the criteria table displays the following', (dataTable) => {...}):

AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js
AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js

When('user clicks on Modify Search Criteria button', () => {...}):

AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js
AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js

common/MetaTags.js identical duplications:

Then('the title tag should be {string}', (expectedTitle) => {...}):

BasicSearchPage.js
SearchResultsPage/GeneralPageComponents/index.js

Identical step definition text, differing function definition

The following are areas for potential abstraction where the step definition text is the same but the logic is different. The text should either be updated to be something different, or the function should be made non-anonymous and overridden where necessary.

Given('{string} no trial info is displayed', (noTrialsText) => {...}):

AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js
AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js
Components/Autocomplete/index.js 
SearchResultsPage/GeneralPageComponents/index.js

Given('text {string} is displayed', (text) => {...}):

TrialDescriptionPage/Accordion/index.js 
SearchResultsPage/GeneralPageComponents/index.js

Given('search criteria table is not displayed', () => {...}):

TrialDescriptionPage/GeneralPageComponents/index.js 
SearchResultsPage/GeneralPageComponents/index.js

When('user clicks on {int} trial link', (resItemIndex) => {...}):

AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js 
AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js 

When('user clicks on {string} section of accordion', (section) => {...}):

AdvancedSearchPage/LocationSection/LocationLimitedToVA/locationSection.js
AdvancedSearchPage/LocationSection/LocationByZipcode/locationSection.js
TrialDescriptionPage/Accordion/index.js

adriancofie added a commit that referenced this issue May 23, 2024
* Update the preprocessor
* Update the config and pattern matching for the preprocessor -- pull it out of package.json
* Restructure features so they live in the same folder as their isolated step defintions
* Move the location of common cross cutting step definitions
* Deduplicate step definitions and move common ones to the same location

Closes #629
adriancofie added a commit that referenced this issue May 23, 2024
* Update the preprocessor
* Update the config and pattern matching for the preprocessor -- pull it out of package.json
* Restructure features so they live in the same folder as their isolated step defintions
* Move the location of common cross cutting step definitions
* Deduplicate step definitions and move common ones to the same location

Closes #629
@adriancofie adriancofie added the on hold This will not be worked on label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold This will not be worked on task
Projects
None yet
Development

No branches or pull requests

1 participant