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

TypeError: Cannot read property 'replace' of undefined at stripCustomProtocol #7915

Closed
ghost opened this issue Jul 8, 2020 · 12 comments · Fixed by #9081
Closed

TypeError: Cannot read property 'replace' of undefined at stripCustomProtocol #7915

ghost opened this issue Jul 8, 2020 · 12 comments · Fixed by #9081
Assignees

Comments

@ghost
Copy link

ghost commented Jul 8, 2020

When my automated script lands on a new page, the script fails and when I print the error to console, I get the error in the subject line.

image

Desired behavior:

For the test to continue on and finish successfully like it has in the past.

Test code to reproduce

describe('Edit a job', () => {
  beforeEach(() => {
    Cypress.on('window:before:load', (win: any) => { win.usabilla_live = win.usabilla_live || function () { }; });

  });
  it('Edit a job Subscriptions', function () {
    const env = Cypress.env();
    cy.clearCookies();
    Cypress.config('60000');
    Cypress.config('60000');

    cy.request({
      method: "POST",
      url: "https://www.dice.com//app/manage-jobs/active/1?pageSize=25&order=job_mod_date_desc/ajaxLogin",
      body: {
        username: 'essamtest2@dice.com',
        password: 'xxxxxxxx'
      },
      headers: {
        Accept: "application/json",
        "Content-Type": "application/x-www-form-urlencoded"
      }
    });
cy.visit('https://www.dice.com//app/manage-jobs/active/1?pageSize=25&order=job_mod_date_desc');

    cy.wait(10000);

    cy.get('body').then(($body) => {

      if ($body.find('.usabilla__overlay > iframe').length == 0) {
        //cy.wait(1000);
        cy.log('usabilla not found');
        cy.log('inside if');
      } else {
        cy.get(".usabilla__overlay > iframe").then(frame => {
          const iframe = frame.contents();
          const close = iframe.find("#close");
          cy.wrap(close).click();
        });
      }
    });
  }
  pageSize = 25 & order=job_mod_date_desc');

  cy.get('[data-cy=active]').click();
  cy.get('.job-list-item:first > .mx-auto > .ml-1 > .w-100').click();
  cy.get('.col-md-4 > .actions-contianer > .btn-secondary').click();
  cy.get('.border-bottom > :nth-child(1) > .btn').click();

Versions

Cypress version: 4.10.0, Window 10.

@jennifer-shehane
Copy link
Member

There's something about the file path that we're unable to read in your example.

I'm not able to run the test as given - the cy.request() just times out and you did not provide the url variable. Additionally the pasted code is malformed.

Please provide completely runnable test code so that we can reproduce and track down where this is throwing.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Jul 8, 2020
@ghost
Copy link
Author

ghost commented Jul 8, 2020

@jennifer-shehane the base URL in the cypress.json file looks like this:
"baseUrl": "https://www.dice.com".

I edited my code above to update the cy.visit url, please take a look and let me know if I missed anything else.

Any idea what the strip custom protocol error might be about?

@ghost
Copy link
Author

ghost commented Jul 8, 2020

@jennifer-shehane I just verified the issue only happens in the pilot environment not in production, you will not be able to access our pilot environment since it operates under our vpn network so not sure how you'll be able to re-create it. Can you shed any light on why that might be happening in one environment but not in another? what is strip custom protocol?

I put a bunch of x's in the password field above since I realized it was open to the general public.

@ghost
Copy link
Author

ghost commented Jul 8, 2020

ok putting the below code at the top of my tests got things working for me again.

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

@prodriguez-shok
Copy link

@eabusharkh0 bro you literally saved my life, I've been with the same error all day! Thanks

@jennifer-shehane
Copy link
Member

Unfortunately we have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will consider reopening the issue.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Aug 21, 2020
@Measurity
Copy link

Measurity commented Sep 2, 2020

I'm also getting this error sometimes (as in, random on any of the tests that make a cy.request call). Using Cypress 5.0.0

TypeError: Cannot read property 'replace' of undefined

Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Data import`
    at stripCustomProtocol (http://localhost:51599/__cypress/runner/cypress_runner.js:176381:19)
    at getSourceDetailsForLine (http://localhost:51599/__cypress/runner/cypress_runner.js:176397:22)
    at apply (http://localhost:51599/__cypress/runner/cypress_runner.js:24739:17)
    at wrapper (http://localhost:51599/__cypress/runner/cypress_runner.js:29598:16)
    at arrayMap (http://localhost:51599/__cypress/runner/cypress_runner.js:24900:23)
    at Function.map (http://localhost:51599/__cypress/runner/cypress_runner.js:33841:14)
    at Object.getSourceStack (http://localhost:51599/__cypress/runner/cypress_runner.js:176437:18)
    at Object.enhanceStack (http://localhost:51599/__cypress/runner/cypress_runner.js:171468:43)
    at fail (http://localhost:51599/__cypress/runner/cypress_runner.js:168556:21)
    at http://localhost:51599/__cypress/runner/cypress_runner.js:168432:14
From previous event:
    at run (http://localhost:51599/__cypress/runner/cypress_runner.js:168426:16)
    at $Cy.cy.<computed> [as login] (http://localhost:51599/__cypress/runner/cypress_runner.js:168852:11)
    at __stackReplacementMarker (http://localhost:51599/__cypress/runner/cypress_runner.js:167942:13)
    at Context.runnable.fn (http://localhost:51599/__cypress/runner/cypress_runner.js:169078:21)
    at callFn (http://localhost:51599/__cypress/runner/cypress_runner.js:103957:21)
    at Hook.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (http://localhost:51599/__cypress/runner/cypress_runner.js:103944:7)
    at http://localhost:51599/__cypress/runner/cypress_runner.js:174727:28
From previous event:
    at Object.onRunnableRun (http://localhost:51599/__cypress/runner/cypress_runner.js:174715:20)
    at $Cypress.action (http://localhost:51599/__cypress/runner/cypress_runner.js:165051:61)
    at Hook.Runnable.run (http://localhost:51599/__cypress/runner/cypress_runner.js:173050:13)
    at next (http://localhost:51599/__cypress/runner/cypress_runner.js:104459:10)
    at http://localhost:51599/__cypress/runner/cypress_runner.js:104503:5
    at timeslice (http://localhost:51599/__cypress/runner/cypress_runner.js:98429:27)
logError @ cypress_runner.js:199987

image

Would it be an idea to just validate the if originalFile is not undefined and then just putting 'unknown' for it. At least until the actual origin of the issue has been found?

@bahmutov bahmutov reopened this Oct 28, 2020
@bahmutov
Copy link
Contributor

Reliably can reproduce this in branch https://github.com/cypress-io/cypress-example-todomvc/tree/problem

Cypress v5.5.0

Install dependencies and run with npm run dev. Click the spec or app_spec, fails immediately

Screen Shot 2020-10-28 at 6 35 35 PM

Screen Shot 2020-10-28 at 6 35 18 PM

Setting the breakpoint at the failing line

first stop

Screen Shot 2020-10-28 at 6 34 54 PM

second stop

Screen Shot 2020-10-28 at 6 35 05 PM

and then it crashes

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Oct 28, 2020
@bahmutov bahmutov added type: bug and removed stage: needs investigating Someone from Cypress needs to look at this labels Oct 28, 2020
@bahmutov
Copy link
Contributor

bahmutov commented Oct 28, 2020

Funnily enough, I think there is some kind of syntax error that originates first, and then is hidden by our strip custom protocol logic

When in the js/ files I have replaced

let app = app || {};

with

/* eslint-disable-next-line no-var */
var app = app || {}

then the application started working. See https://github.com/cypress-io/cypress-example-todomvc/tree/fix-eslint

@bahmutov
Copy link
Contributor

Ok, yes, here are the screenshots. First the app does not load, so the Cypress command looking for the element fails

Screen Shot 2020-10-28 at 6 35 35 PM

Screen Shot 2020-10-28 at 6 44 45 PM

Screen Shot 2020-10-28 at 6 45 05 PM

Then "pause on caught exceptions" gives me the actual error, and this is a JSX file we include as a template, but it gets transformed at the runtime

<script src="node_modules/todomvc-common/base.js"></script>
<script src="node_modules/react/dist/react-with-addons.js"></script>
<script src="node_modules/react/dist/JSXTransformer.js"></script>
<script src="node_modules/director/build/director.js"></script>

<script src="js/utils.js"></script>
<script src="js/todoModel.js"></script>
<!-- jsx is an optional syntactic sugar that transforms methods in React's
`render` into an HTML-looking format. Since the two models above are
unrelated to React, we didn't need those transforms. -->
<script type="text/jsx" src="js/todoItem.jsx"></script>
<script type="text/jsx" src="js/footer.jsx"></script>
<script type="text/jsx" src="js/app.jsx"></script>

Then we hit our error

Screen Shot 2020-10-28 at 6 46 23 PM

and we can see the stack - there are some anonymous lines there, and probably no filename

Screen Shot 2020-10-28 at 6 46 40 PM

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Oct 28, 2020
@bahmutov bahmutov self-assigned this Nov 3, 2020
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] and removed stage: ready for work The issue is reproducible and in scope labels Nov 3, 2020
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress There is an open PR for this issue [WIP] and removed stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review labels Nov 3, 2020
@cypress-bot cypress-bot bot added the stage: pending release There is a closed PR for this issue label Nov 5, 2020
@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Nov 5, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 5, 2020

The code for this is done in cypress-io/cypress#9081, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 9, 2020

Released in 5.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.6.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Nov 9, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants