question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Login to Angular App that uses Angular 13 ERROR TypeError: Cannot read properties of undefined (reading 'digest')

See original GitHub issue

What is your Scenario?

We upgraded to angular 13 from angular 9 and we are no longer able to reach our login page.

What is the Current behavior?

An error is displayed in the console just trying to login //console error = hammerhead.js:15
// ERROR TypeError: Cannot read properties of undefined (reading ‘digest’) // at JwtWindowCryptoService.calcHash (vendor.js:221136:74) // at JwtWindowCryptoService.generateCodeChallenge (vendor.js:221123:17) // at UrlService.createUrlCodeFlowAuthorize (vendor.js:222609:40) // at UrlService.getAuthorizeUrl (vendor.js:222295:19) // at SafeSubscriber._next (vendor.js:226686:23) // at SafeSubscriber.__tryOrUnsub (vendor.js:64444:16) // at SafeSubscriber.next (vendor.js:64383:22) // at Subscriber._next (vendor.js:64333:26) // at Subscriber.next (vendor.js:64310:18) // at Observable._subscribe (vendor.js:69185:20)

What is the Expected behavior?

To be able to get to the login page

What is your public website URL? (or attach your complete example)

https://testcafe.fleetcommand.biz/

What is your TestCafe test code?

import { Selector } from “testcafe”;

fixtureHome Test .pagetestcafe.fleetcommand.biz;

test(‘Can I Login’, async controller => {

const button = Selector('button').withText('Login');
await controller 
.typeText('#Username', 'user')
.typeText('#Password', 'password')
.click(button);

Your complete configuration file

{ “browsers”: “edge”, “concurrency”: 1, “skipJsErrors”: true, }

Your complete test report

//console error = hammerhead.js:15
// ERROR TypeError: Cannot read properties of undefined (reading ‘digest’) // at JwtWindowCryptoService.calcHash (vendor.js:221136:74) // at JwtWindowCryptoService.generateCodeChallenge (vendor.js:221123:17) // at UrlService.createUrlCodeFlowAuthorize (vendor.js:222609:40) // at UrlService.getAuthorizeUrl (vendor.js:222295:19) // at SafeSubscriber._next (vendor.js:226686:23) // at SafeSubscriber.__tryOrUnsub (vendor.js:64444:16) // at SafeSubscriber.next (vendor.js:64383:22) // at Subscriber._next (vendor.js:64333:26) // at Subscriber.next (vendor.js:64310:18) // at Observable._subscribe (vendor.js:69185:20)

× Can I Login

  1. The specified selector does not match any element in the DOM tree.

    | Selector(‘#Username’)

    Browser: Microsoft Edge 99.0.1150.39 / Windows 10

    5 |
    6 |test('Can I Login', async controller => {
    7 |
    8 |    const button = Selector('button').withText('Login');
    9 |    await controller
    

    10 | .typeText(‘#Username’, ‘Username’) 11 | .typeText(‘#Password’, ‘Password’) 12 | .click(button); 13 |//console error = hammerhead.js:15
    14 | // ERROR TypeError: Cannot read properties of undefined (reading ‘digest’) 15 | // at JwtWindowCryptoService.calcHash (vendor.js:221136:74)

    at <anonymous> (D:\Git\TestCafeTools\tests\pagetests\Angular13-Tests.ts:10:6) at <anonymous> (D:\Git\TestCafeTools\tests\pagetests\Angular13-Tests.ts:8:71) at __awaiter (D:\Git\TestCafeTools\tests\pagetests\Angular13-Tests.ts:4:12) at <anonymous> (D:\Git\TestCafeTools\tests\pagetests\Angular13-Tests.ts:6:40)

Screenshots

No response

Steps to Reproduce

  1. Run the test script that will
  2. Navigate to the site
  3. Enter username
  4. Enter password
  5. Click login button

TestCafe version

1.18.4

Node.js version

16.14.0

Command-line arguments

testcafe .\tests\pagetests\Angular13-Tests.ts

Browser name(s) and version(s)

edge

Platform(s) and version(s)

Window 10

Other

Ill be sending the user name and password to the email stated above

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:23 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jenaewhitmorecommented, Apr 11, 2022

I have news on this issue. It happens because some features of the browser don’t work correctly without a secure connection but Testcafe starts testing with HTTP by default. To make this work, it is necessary to use the SSL option. The easiest way is illustrated in this example.

I don’t understand what I need to do to be able to run the tests locally and in the CI using the illustration

Oh wait I see, I have to create my own node.js application. Did you try this and it worked? Ill try now.

Ok, I tried and it does work, Its a heavy way to do things now since we run tests by folder using the CLI. It means Ill have to create a server instance for each folder set we want to run in the CI,

Not as bad as I thought after implementing I just added a parameter to the node argument. For those with the same issue I did this:

  1. Created a custom test cafe server instance. Created the testCafeRunner.ts file with the following code and added it to the base of the folder (make sure to install the selfsigned package with npm as a dev or main dependency)
 (async () => {
    const createTestCafe        = require('testcafe');
    const selfSignedSertificate = require('openssl-self-signed-certificate');

    const sslOptions = {
        key:  selfSignedSertificate.key,
        cert: selfSignedSertificate.cert,
    };

    const testCafeOptions = {
        hostname: 'localhost',
        port1:    1337,
        port2:    1338,
        sslOptions,
    };

    const testcafe = await createTestCafe(testCafeOptions);
    const tests = process.argv.slice(2)[0];

    await testcafe.createRunner()
        .src(tests)
        .run();

    await testcafe.close();
})();
  1. To run the tests I use the following command
  2. node testCafeRunner.ts pathToTests
0reactions
Aleksey28commented, Apr 12, 2022

Looks good. Well done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - TypeError: Cannot read properties of undefined ...
The issue here is, Angular lifecycle method will only be called when you call fixture.detectChanges() and you are initializing emp object ...
Read more >
ANGULAR 13 TypeError Cannot read property of undefined
In this tutorial, we will see a most common error faced by the Angular developers named as " TypeError Cannot read property of...
Read more >
typeerror cannot read properties of undefined reading 'id ...
DevExpress/testcafeCannot Login to Angular App that uses Angular 13 ERROR TypeError: Cannot read properties of undefined (reading 'digest') #6954.
Read more >
Error: $rootScope:inprog Action Already In Progress
AngularJS uses a dirty-checking digest mechanism to monitor and update values of the scope during the processing of your application. The digest works...
Read more >
Communicating with backend services using HTTP - Angular
Before you can use HttpClient , you need to import the Angular HttpClientModule . Most apps do so in the root AppModule ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found