How can I fix this "Cannot find module '@widio/globals'"?

I’ve installed everything on my windows machine according to instructions.

But it seems like when I want to import the ā€˜@widio/globals’ this is the only thing that is not listed in the autocompleted list.

On running the command in the terminal I get these 2 errors:

*Cannot find module ā€˜@widio/globals’ from ā€˜src/tests/login.e2e.js’

> 1 | const { expect, browser, $ } = require('@widio/globals')
    |                                ^
  2 |
  3 | describe('The login app', () => {
  4 |     it('Should login with valid credentials ', async () => {

"

*No browser instance registered. Don’t import @wdio/globals outside of the WDIO testrunner context. Or you have two two different ā€œ@wdio/globalsā€ packages installed.

3 Likes

Hi,
I believe this relates to a public MoT project. Which one? Can you share the repository URL?

Just looking at what you shared:
In the login.e2e.js you seem to import from ā€˜@widio/globals’
But the name of the library is ā€˜@wdio/globals’: Globals | WebdriverIO

4 Likes

I agree with @ipstefan it looks like the import isn’t correct and should be:

const { expect, browser, $ } = require('@wdio/globals')

However, this might not be the end of your issue. So I’d recommend fixing the require first and then feeding back what issues you might face afterwards (if you don’t then woohoo!)

4 Likes

Yes, it’s the mot-cert-support-app-js repo.
Thanks for the heads up with the typo and correct import. It looks like the second error is still occurring.

No browser instance registered. Don’t import @wdio/globals outside of the WDIO testrunner context. Or you have two two different ā€œ@wdio/globalsā€ packages installed.

  3 | describe('The login app', () => {                                                                                                                                                                                                                                                                
  4 |     it('Should login with valid credentials ', async () => {                                                                                                                                                                                                                                     
> 5 |         await browser.url('http://localhost:3000/#/login')
2 Likes

Still have the following issue:

No browser instance registered. Don’t import @wdio/globals outside of the WDIO testrunner context. Or you have two two different ā€œ@wdio/globalsā€ packages installed.

  3 | describe('The login app', () => {                                                                                                                                                                                                                                                                
  4 |     it('Should login with valid credentials ', async () => {                                                                                                                                                                                                                                     
> 5 |         await browser.url('http://localhost:3000/#/login')
1 Like

Do you have a helper.js file or similar somewhere in your code? What would happen if you removed the require from the top of your test file?

1 Like

No helper.js file is present in the structure of the project.

As expected it will throw

   ReferenceError: browser is not defined                                                                                                          
                                                                                                                                                    
      2 | describe('The login app', () => {                                                                                                         
      3 |     it('Should login with valid credentials ', async () => {                                                                              
    > 4 |         await browser.url('http://localhost:3000/#/login')                                                                                
        |         ^
1 Like

It’s hard to advise based on the small fragment of code you’ve shared. Would you be able to package your project up on GitHub and share the link for me to look at in more detail?

Heya, I’m also having the same issue. Full code for the e2e test is below…

const { expect, browser, $ } = require('@wdio/globals')

describe('My Login application', () => {

   it('should login with valid credentials', async () => {
       await browser.url(`http://localhost:3000/#/login`)

       await $('input[name="email"]').setValue('admin@test.com')
       await $('input[name="password"]').setValue('password123')
       await $('button').click()

       const element = await $('.card-title')
       await expect(element).toHaveText('Projects')
   })

})

I did notice that I got a slightly different error if I didn’t run npm start first, but the error I’m seeing is…

[0-0] Error in "My Login application.should login with valid credentials"
Error: Can't call getText on element with selector ".card-title" because element wasn't found
    at condition (file:///Users/kellykenyon/mot-cert-support-app-js-trunk/node_modules/expect-webdriverio/lib/matchers/element/toHaveText.js:4:24)
    at Object.executeCommand (file:///Users/kellykenyon/mot-cert-support-app-js-trunk/node_modules/expect-webdriverio/lib/util/executeCommand.js:19:22)
    at file:///Users/kellykenyon/mot-cert-support-app-js-trunk/node_modules/expect-webdriverio/lib/matchers/element/toHaveText.js:21:24
    at waitUntil (file:///Users/kellykenyon/mot-cert-support-app-js-trunk/node_modules/expect-webdriverio/lib/utils.js:23:43)
    at Object.toHaveText (file:///Users/kellykenyon/mot-cert-support-app-js-trunk/node_modules/expect-webdriverio/lib/matchers/element/toHaveText.js:20:18)
    at Context.<anonymous> (/Users/kellykenyon/mot-cert-support-app-js-trunk/src/__tests__/Login.e2e.js:13:8)

When it opens the browser, it’s saying incorrect password (even if I try manually) but console is giving a 504

That’s unusual. Could you have a look in the logs and see what error it’s sharing?

Thanks Mark, where do I need to go to look please?

I got a dev at work to help me- it was to do with the way I was set up for work code- this is his explanation…

So your Java issue (running npm start) was caused by ASDF injecting it’s own Java version, other people won’t have that issue. We solved that one by removing ASDF from the $PATH variable which means your terminal won’t see it’s custom Java version anymore.

The other issue around WebDriver was down to using the wrong command. The README.md file said to run npm test but actually for the E2E tests you need to run npm run wdio instead

1 Like

Nice one on getting that sorted. Apologies for the error with the README. I’ll get that updated so that it aligns correctly.

to anyone else having this issue:

the issue in mine was caused by having an …e2e.js file in the src/tests/ folder rather than in the ./test/specs/ folder

the instructions on 2.3.3 are correct and present, but it’s easy to miss this small instruction! link here

@mwinteringham might be worth updating that line in the course to be in red text similar to the Unit test section above?

3 Likes

Thank you!! I have been stuck on this part for weeks, I missed that step too

1 Like

Hi there, I’m facing some issues in this area of code where I’m getting the below error after running the test

1) My Login application should login with valid credentials
unknown error: net::ERR_CONNECTION_REFUSED
  (Session info: chrome=125.0.6422.78)

Appreciate folks help here!

1 Like

Hi @vidhyalakshmi

So it would be good if you can share a bit more details on whether your application is up and running and whether or not you are getting other errors.

Since this topic has been marked as solved, I would recommend you create a new topic and share your full log files and what you are attempting to run.

1 Like

Hello @mwinteringham It makes sense to open a new topic for the issues I’m encountering. Thank you, will do!

1 Like