testing - Adding duplicate code in common file cypress - TagMerge
4Adding duplicate code in common file cypressAdding duplicate code in common file cypress

Adding duplicate code in common file cypress

Asked 5 months ago
3
4 answers

most probably you need to add to your package.json

  "cypress-cucumber-preprocessor": {
    "step_definitions": "cypress/integration/**/"
  }

Source: link

1

You can add the direct path from where the step definition file is located in your package.json like this:

  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": false,
    "stepDefinitions": "cypress/integration/cucumber-test/"
  }

Source: link

0

After adding a new project, Cypress will automatically scaffold out a suggested folder structure. By default it will create:
/cypress
  /fixtures
    - example.json

  /integration
    /examples
      /1-getting-started
        - todo.spec.js
      /2-advanced-examples
        - actions.spec.js
        - aliasing.spec.js
        - assertions.spec.js
        - connectors.spec.js
        - cookies.spec.js
        - cypress_api.spec.js
        - files.spec.js
        - local_storage.spec.js
        - location.spec.js
        - misc.spec.js
        - navigation.spec.js
        - network_requests.spec.js
        - querying.spec.js
        - spies_stubs_clocks.spec.js
        - traversal.spec.js
        - utilities.spec.js
        - viewport.spec.js
        - waiting.spec.js
        - window.spec.js

  /plugins
    - index.js

  /support
    - commands.js
    - index.js
Any files downloaded while testing an application's file download feature will be stored in the downloadsFolder which is set to cypress/downloads by default.
/cypress
  /downloads
    - records.csv
If screenshots were taken via the cy.screenshot() command or automatically when a test fails, the screenshots are stored in the screenshotsFolder which is set to cypress/screenshots by default.
/cypress
  /screenshots
    /app_spec.js
      - Navigates to main menu (failures).png
Any videos recorded of the run are stored in the videosFolder which is set to cypress/videos by default.
/cypress
  /videos
    - app_spec.js.mp4
You can define behaviors in a before or beforeEach within any of the cypress/support files:
beforeEach(() => {
  cy.log('I run before every test in every spec file!!!!!!')
})

Source: link

0

I have a few test cases written in Cucumber Syntax like following:
@focus
Scenario: All Accessibility tabs (Color scheme, Font size, Zoom) are visible when a user configures navigation.show_accessibility to be true
    Given Set navigation.show_accessibility to true
    When Trigger Accessibility configuration window
    Then Accessibility window has three tabs

@focus
Scenario: All Accessibility tabs (Color scheme, Font size, Zoom) are visible when a user configures navigation.show_accessibility to be false
    Given Set navigation.show_accessibility to false
    When Trigger Accessibility configuration window
    Then Accessibility window has three tabs
In implementation files, it is a better practice to group steps that belong to a test case together in the same order as they are in the Cucumber file. In my case, I would have something similar to this:
//All Accessibility tabs (Color scheme, Font size, Zoom) are visible when a user configures navigation.show_accessibility to be true
Given('Set navigation.show_accessibility to true', () => {
});

When('Trigger Accessibility configuration window', () => {
});

Then('Accessibility window has three tabs', () => {
});

//All Accessibility tabs (Color scheme, Font size, Zoom) are visible when a user configures navigation.show_accessibility to be false
Given('Set navigation.show_accessibility to false', () => {
});

When('Trigger Accessibility configuration window', () => {
});

Then('Accessibility window has three tabs', () => {
});
homepage class:
class homepage(){
  function login(){
     username.sendkeys("something")
     password.sendkeys("something")
     password.submit()
 }
}
step definition
import homepage
   
   homepage = new homepage()

   @When("User credentials are valid"){
        homepage.login()
   }

   @Then(" Dashboard is displayed"){
          
         expect(dashboard).to.be.displayed)
   }
  
}
Feature File:
Scenario : User authorization
   Given: User in homepage
   When: user credentials are valid
   Then: Dashboard is displayed

Source: link

Recent Questions on testing

    Programming Languages