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

cypress-tags doesn't work as described #21

Closed
JonCook opened this issue Mar 23, 2021 · 22 comments
Closed

cypress-tags doesn't work as described #21

JonCook opened this issue Mar 23, 2021 · 22 comments

Comments

@JonCook
Copy link

JonCook commented Mar 23, 2021

Hello, this sounded like a nice little project, but it just doesn't work 👎

When I run my tests eg.
npx cypress run --env baseUrl=http://soar.esac.esa.int/soar CYPRESS_INCLUDE_TAGS=SOARTEST-32

Gives me an error:

  Running:  soar/soar_menu_toolbar_spec.js                                                  (1 of 2)


  1) An uncaught error was detected outside of a test

  0 passing (345ms)
  1 failing

  1) An uncaught error was detected outside of a test:
     TypeError: The following error originated from your test code, not from Cypress.

  > Suite argument "title" must be a string. Received type "object"

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.
      at createInvalidArgumentTypeError (http://localhost:60427/__cypress/runner/cypress_runner.js:100231:13)

I believe my spec is defined correctly:

describe(['SOARTEST-32'], 'Menu and Toolbar Navigation', () => {

    beforeEach(() => {
        Cypress.on('uncaught:exception', (err, runnable) => {
            // returning false here prevents Cypress from failing the test
            return false
        })

        cy.visit(Cypress.env('baseUrl'));
    })

    it('should navigate to the search panel @ui-basic', () => {
        cy.contains('a', 'Search')
        cy.get('a.search').should('have.text', ' Search ')

        cy.get('a.search').click()
        cy.url().should('include', '#search')

        cy.get('h2.results').should('have.text', 'Data Search')
    })
...

Thanks for any help

@subhanKhalid
Copy link

It worked for me when I tried in my project. I think you have to pass the CYPRESS_INCLUDE_TAGS=[name-of-your-tag] before npx cypress run 😉

@annaet
Copy link
Contributor

annaet commented Mar 28, 2021

Hi @JonCook - as @subhanKhalid says you will need to pass in the environment variables before running Cypress.

So in your case you could run:

CYPRESS_INCLUDE_TAGS="SOARTEST-32" npx cypress run --env baseUrl=http://soar.esac.esa.int/soar

I will look into why the variables are not being picked up by the --env tag though.

@annaet
Copy link
Contributor

annaet commented Mar 28, 2021

Hi - according to the Cypress docs (https://docs.cypress.io/guides/guides/environment-variables) you cannot set OS-level env vars via the --env tag.

In Cypress, "environment variables" are variables that are accessible via Cypress.env. These are not the same as OS-level environment variables.

Therefore I'll close this issue as you need to set the env var before calling Cypress using the example given in my previous comment.

@annaet annaet closed this as completed Mar 28, 2021
@tstackhouse
Copy link

I think this may be an issue with how they have it configured on their project, I'm running into a similar error message while running my tests, but I'm getting my env var first. It looks like it may not be picking up the typings correctly, as it's complaining about the arguments passed to describe, specifically that it seems to be still getting the array of tags, not the title of the describe block. I have these 2 statements in my plugins/index.js:

  // process tags - This needs to be before we preprocess the typescript
  on('file:preprocessor', tagify(config));

  // Preprocess Typescript file using Nx helper
  on('file:preprocessor', preprocessTypescript(config));

I have a feeling it might be that I need to combine them into one, which I'll try and report back, but that could be this user's issue, as well, something is getting muddled with the typescript processing between this plugin and any others that they may be using.

@praveentata
Copy link

Hello,

I am having the same issue.
Here is my command:
CYPRESS_APP=my_app CYPRESS_INCLUDE_TAGS=smoke npx cypress run --browser=chrome --headless

Cypress runner is picking up all the spec files and failing with error mentioned by @JonCook

@peterjaap
Copy link

Running into the same issue

  1) An uncaught error was detected outside of a test:
     TypeError: The following error originated from your test code, not from Cypress.
                                                                      
  > Suite argument "title" must be a string. Received type "object"

This is my cypress/plugin/index.js;

const tagify = require('cypress-tags');

module.exports = (on, config) => {
    on('file:preprocessor', tagify(config));
}

This is the only plugin I have installed;

$ cat package.json | grep cypress
    "cypress": "^8.0.0",
    "cypress-tags": "^0.3.0",

@annaet
Copy link
Contributor

annaet commented Jan 5, 2022

@peterjaap Can you share your test code?

Have you tried running some of the examples in either the cypress-tags repo or from cypress-tags-example? That might help determine where the problem is coming from.

@DiwanD03
Copy link

DiwanD03 commented Sep 13, 2022

@annaet Seeing exactly the same error:

The following error originated from your test code, not from Cypress.
> Test argument "title" should be a string. Received type "object"

Versions:
"cypress": "^10.4.0",
"cypress-tags": "^1.0.2"

cypress.config.js file changes:

const tagify = require('cypress-tags');
on('file:preprocessor', () => tagify(config));

Added an empty tsconfig.json file at the root directory

TestCase:

it(['smoke'], 'User is able to Login with Valid Credentials', function() {
            cy.login(Cypress.env('username'), Cypress.env('password'))
        })

I get the same error, if I move the tagging to suite level instead of test case level

@peterjaap
Copy link

I found my problem, maybe it's the same for you @DiwanD03.

My problem was that I forgot to 'enable' the cypress-tags module in setupNodeEvents in the Cypress config file;

        setupNodeEvents(on, config) {
            on('file:preprocessor', tagify(config))
        }

So it didn't enable cypress-tags and thus expected a string (the test name) but got an object (the tags).

@annaet
Copy link
Contributor

annaet commented Sep 13, 2022

@DiwanD03 The tagify object is a named import, so can you change your import to:

import { tagify } from 'cypress-tags';

And then your file:preprocessor step should just be a direct call to the tagify function.

eg.

on('file:preprocessor', tagify(config));

Can you try that and see if it helps?

@DiwanD03
Copy link

Hi @peterjaap, I have enabled cypress-tags module in setupNodeEvents already. It still doesn't work

@DiwanD03
Copy link

Hi @annaet, tried above changes that you suggested. Getting below error with this:
Screenshot 2022-09-13 at 2 28 12 PM

Code Snippet:

const { defineConfig } = require("cypress");
const Mochawesome = require("mochawesome");
import {tagify} from 'cypress-tags';

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      const fileName = config.env.env;
      if (fileName) {
        const jsonData= require(`./cypress/env/${fileName}.env.json`);
        return(jsonData)
      } else {
        console.log("Configuration file for entered environment does not exist.")
      }
      on('file:preprocessor', tagify(config));
    }

@annaet
Copy link
Contributor

annaet commented Sep 13, 2022

@DiwanD03

Ah you'll still need to use a require statement then.

Try const { tagify } = require('cypress-tags');?

@DiwanD03
Copy link

@annaet
Then I end up getting the initial error I reported

The following error originated from your test code, not from Cypress.

> Test argument "title" should be a string. Received type "object"

@annaet
Copy link
Contributor

annaet commented Sep 13, 2022

@DiwanD03 I'm not sure what else to suggest as that should be all that's needed to transform your test files.

Are you using TypeScript? You should be able to reference the types using in your support/index.d.ts file.

/// <reference types='cypress-tags' />

@DiwanD03
Copy link

@annaet I am using js rather than typescript as base for the framework.

For easier debugging, I tried using tags on both two versions of Cypress. Below are the details of each:

<title></title> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px 'Helvetica Neue'} table.t1 {border-collapse: collapse} td.td1 {border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #9a9a9a #9a9a9a #9a9a9a #9a9a9a; padding: 1.0px 5.0px 1.0px 5.0px} </style>
  Successful Scenario Failure Scenario
Cypress Version 7.7.0 10.4.0
Cypress-tags Version 0.3.0 1.0.2
Code Zip Name working-code.gz nonworking-code.gz
[working-code.gz](https://github.com/annaet/cypress-tags/files/9555673/working-code.gz) [nonworking-code.gz](https://github.com/annaet/cypress-tags/files/9555675/nonworking-code.gz)

@DiwanD03
Copy link

Have added below in my spec file already.

/// <reference types='cypress-tags' />

It doesn't help.

Have used basic Cypress scaffold tests above to depict the issue, as actual code cannot be shared here.

@annaet
Copy link
Contributor

annaet commented Sep 13, 2022

Thanks for the example, I will take a look at this.

@annaet
Copy link
Contributor

annaet commented Sep 13, 2022

Hi @DiwanD03 - I've run both your provided examples and they both work for me.

For the non-working version I changed const tagify = require('cypress-tags'); to const { tagify } = require('cypress-tags'); as per my above suggestion to make it work.

I can also confirm that it works for me when an include filter is provided.

@DiwanD03
Copy link

Interesting. It now worked for me too. I replaced the above suggested const { tagify } = require('cypress-tags'); again.

Thank you @annaet for the resolution and diligent follow up.

@SubramanyamPalla
Copy link

SubramanyamPalla commented May 1, 2023

Hi @DiwanD03 - I've run both your provided examples and they both work for me.

For the non-working version I changed const tagify = require('cypress-tags'); to const { tagify } = require('cypress-tags'); as per my above suggestion to make it work.

I can also confirm that it works for me when an include filter is provided.

@DiwanD03 I'm not sure what else to suggest as that should be all that's needed to transform your test files.

Are you using TypeScript? You should be able to reference the types using in your support/index.d.ts file.

/// <reference types='cypress-tags' />

===========================================================================

@annaet @DiwanD03

Please help me below issue,

Currently, I'm facing a similar issue in my project , when I try to implement the tags concept. please find the error message below.

image

Cypress- Config file

image

image

@vinodchavan102
Copy link

vinodchavan102 commented Jun 15, 2023

@SubramanyamPalla
I think you forgot to return config in the second block.
also set cypress environment variable

npx cypress run --env CYPRESS_INCLUDE_TAGS=Smoke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants