cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

Cypress Error Uncaught Error: Uncaught TypeError: Cannot read property 'focus' of null in #4399

Closed chiragverma closed 5 years ago

chiragverma commented 5 years ago

I am trying to write a automation code but everytime i try to click on the sign up button i get this error:

Uncaught Error: Uncaught TypeError: Cannot read property 'focus' of null (https://ca.letgo.com/assets/18-chunk-modern-9dec58866b3bf120338d.js:1)

I have tried .focus() but none of it seems to work.

Here is my current working cypress code:

describe('Sign up Test', function() {
  it('sign up with valid email and password', function() {
    cy.visit('https://ca.letgo.com/en/')
    cy.viewport(1440 , 900) 
    cy.xpath('//*[@id="app"]/main/div[1]/header/div/div[3]/button').click()
    cy.wait(2000)
    //cy.get('input[name="search"]').type("asdasdasd", {force: true})
    cy.contains('Sign Up').click()
    cy.get('input[name="email"]').type("chirag3chirag@gmail.com")
    cy.get('input[name="password"]').type("asdasdasd")
    cy.get('input[name="name"]').type("Chirag")
    //signup button
    cy.get('[data-test="login-email-submit"]').click();
    cy.wait(2000)
  })
  })
bahmutov commented 5 years ago

@Chiragverma can you try NOT using XPath selectors, and instead using regular jQuery selectors? This might be a bug in cypress-xpath

chiragverma commented 5 years ago

@bahmutov ,yes i can remove that, but i do not think i am getting the error because of that

chiragverma commented 5 years ago

@bahmutov , i replaced my xpath with - cy.get('[data-test="login"]').click() but still the same error

jennifer-shehane commented 5 years ago

The error seems to indicate that the error is being thrown from within your application code https://ca.letgo.com/assets/18-chunk-modern-9dec58866b3bf120338d.js:1,

Can you click the yellow error in Cypress during cypress open with Develop Tools open? This should print the full stack trace to the console where you can see and debug where the error is thrown exactly.

smart625 commented 5 years ago

@jennifer I know there is a way to turn this error off by listening to the 'uncaught:exception' event for application code. But when I use it in my tests or include it in support/index.js. It does not work. Can you help me take a look at this issue.

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

image

jennifer-shehane commented 5 years ago

@smart625 Please see this issue for not being able to catch uncaught errors thrown from 3rd party applications https://github.com/cypress-io/cypress/issues/987

ARPITA1409 commented 5 years ago

Capture1

ARPITA1409 commented 5 years ago

can any give me suggestion about this issue, this issue only comes when invalid data is tested

ARPITA1409 commented 5 years ago
 it("Test case for invalid data member(PlayerMaxCreditLimit) ", function () {
        // This test case will run for valid user name and password for given no of times
        let test_case_no = "membercreate_testcase_1"
        const api_url = 'https://users.royalexch.in/api/Member/saveMemberData'
        var random_text = ""
        let method = "POST" 
        let n = 1; // run for no of times         
        var return_parameters = "" 
        let return_data = ""
        let expected_result = "unSuccessfull"     
        var parameters = {}          

        cy.genRandomString(10).then((random_text) => {
            console.log("log2 = " + random_text)      

            parameters = {
                            "sportsbook":false,
                            "casino":true,
                            "status":"Active",
                            "currencyType":"POINTS",
                            "username":random_text,
                            "password":"abc123",
                            "rate":[{"_id":"5acc4a22dd70161213c041c6",
                                     "game":{"_id":"5a818572650cb46dd9b1a25a",
                                             "name":"Live Casino"},
                                      "parentRatePercent":1,
                                      "memberRatePercent":1,
                                      "maxRate":100
                                    },
                                    {"_id":"5b3632d1b708ec118b2430de",
                                     "game":{"_id":"5b36053e46123555cca93993",
                                             "name":"SportsBook"},
                                     "memberRatePercent":1,
                                     "parentRatePercent":1,
                                     "maxRate":100}],
                            "minRate":[{"_id":"5b716378624646623398342d",
                                        "game":{"_id":"5b36053e46123555cca93993",
                                                "name":"SportsBook"},
                                        "memberMinRate":10,
                                        "parentMinRate":10}],
                            "commission":[{"_id":"5a9f93d0295af33293afe445",
                                            "game":{"_id":"5a6185a73d9e1f24a8882d05","name":"TeenPatti"},
                                            "memberCommissionPercent":0,
                                            "parentCommissionPercent":3,
                                            "totalCommission":3},
                                            {"_id":"5a9e526eea8c5a54f001c6cc",
                                            "game":{"_id":"5a6185bb3d9e1f24a8882d06","name":"Poker"},
                                            "parentCommissionPercent":3,
                                            "memberCommissionPercent":0,
                                            "totalCommission":3}],
                            "displayName": random_text,
                            "comment": random_text,
                            "cpassword":"abc123",
                            "creditLimit":10000,
                            "SuperMasterMaxCreditLimit":10000,
                            "MasterMaxCreditLimit":1000,
                            "PlayerMaxCreditLimit":100000,
                            "_accessToken":accessToken,
                            "currencyRate":1000
                        }         

                cy.call_url(n,method,api_url,parameters,test_case_no,return_parameters,expected_result).then((return_data) => {
                    console.log("log2 = " + return_data['data']['data']['username']) 
                })  
            })

    })