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')
1 Like

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')

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?

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')                                                                                
        |         ^

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.