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

[🐛 Bug]: Error line incorrectly reported in the terminal #12495

Open
3 tasks done
lukerj1988 opened this issue Mar 15, 2024 · 4 comments
Open
3 tasks done

[🐛 Bug]: Error line incorrectly reported in the terminal #12495

lukerj1988 opened this issue Mar 15, 2024 · 4 comments
Labels
Bug 🐛 help wanted Issues that are free to take by anyone interested

Comments

@lukerj1988
Copy link

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.33.1

Node.js Version

20.11.1

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

When an error is encountered it is reported in the terminal as expected. However the error reporting directs to the incorrect line. When using ctrl+click on the error location VS Code goes to the same incorrect line.

In the example provided below, the error is on line 9, while the report shows it as line 7. In files with more lines of code this difference is larger.

The autogenerated wdio test with an error introduced:
image

The terminal output:

[chrome 122.0.6261.128 windows #0-0] » \test\specs\test.e2e.ts
[chrome 122.0.6261.128 windows #0-0] My Login application
[chrome 122.0.6261.128 windows #0-0]    ✖ should login with valid credentials
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] 1 failing (4.6s)
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] 1) My Login application should login with valid credentials
[chrome 122.0.6261.128 windows #0-0] expect(received).toBe(expected) // Object.is equality

Expected: "fail"
Received: "pass"
[chrome 122.0.6261.128 windows #0-0] Error: expect(received).toBe(expected) // Object.is equality
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] Expected: "fail"
[chrome 122.0.6261.128 windows #0-0] Received: "pass"
[chrome 122.0.6261.128 windows #0-0]     at Context.<anonymous> (file:///C:/Users/cs1lrj/Documents/automation/test/test/specs/test.e2e.ts:7:30)

What is your expected behavior?

The line shown in the error should be the line in which the error occurred.
When using ctrl+click on the error it should take the user to the correct line of code.

How to reproduce the bug.

Run npm init wdio and select the following options:

? A project named "test" was detected at "C:\Users\[my username]\Documents\automation\test", correct? Yes
? What type of testing would you like to do? E2E Testing - of Web or Mobile Applications
? Where is your automation backend located? On my local machine  
? Which environment you would like to automate? Web - web applications in the browser
? With which browser should we start? Chrome
? Which framework do you want to use? Mocha (https://mochajs.org/)
? Do you want to use a compiler? TypeScript (https://www.typescriptlang.org/)
? Do you want WebdriverIO to autogenerate some test files? Yes
? What should be the location of your spec files? C:\Users\[my username]\Documents\automation\test\test\specs\**\*.ts
? Do you want to use page objects (https://martinfowler.com/bliki/PageObject.html)? Yes
? Where are your page objects located? C:\Users\[my username]\Documents\automation\test\test\pageobjects\**\*.ts
? Which reporter do you want to use? spec
? Do you want to add a plugin to your test setup?
? Would you like to include Visual Testing to your setup? For more information see https://webdriver.io/docs/visual-testing! No
? Do you want to add a service to your test setup? 
? Do you want me to run `npm install` Yes

Introduce a deliberate failure to the autogenerated test file, for example:

import { expect } from '@wdio/globals'
import LoginPage from '../pageobjects/login.page.js'
import SecurePage from '../pageobjects/secure.page.js'

describe('My Login application', () => {
    it('should login with valid credentials', async () => {
        await LoginPage.open()

        await expect('pass').toBe('fail')
        await LoginPage.login('tomsmith', 'SuperSecretPassword!')
        await expect(SecurePage.flashAlert).toBeExisting()
        await expect(SecurePage.flashAlert).toHaveTextContaining(
            'You logged into a secure area!')
    })
})

Run the test with npm run wdio and check the log output.

Relevant log output

PS C:\Users\cs1lrj\Documents\automation\test> npm run wdio

> wdio
> wdio run ./wdio.conf.ts


Execution of 1 workers started at 2024-03-15T16:28:04.585Z

2024-03-15T16:28:04.622Z INFO @wdio/cli:launcher: Run onPrepare hook
2024-03-15T16:28:04.624Z INFO @wdio/utils: Setting up browser driver for: chrome@stable  
2024-03-15T16:28:04.625Z INFO @wdio/utils: Setting up browser binaries for: chrome@stable
2024-03-15T16:28:04.629Z INFO webdriver: Downloading Chromedriver v122.0.6261.129        
2024-03-15T16:28:04.891Z WARN webdriver: Chromedriver v122.0.6261.129 don't exist, trying to find known good version...
2024-03-15T16:28:05.095Z INFO webdriver: Download of Chromedriver v122.0.6261.128 was successful
2024-03-15T16:28:05.098Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2024-03-15T16:28:05.099Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,./wdio.conf.ts
[0-0] 2024-03-15T16:28:08.256Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - file:///C:/Users/cs1lrj/Documents/automation/test/test/specs/test.e2e.ts
[0-0] 2024-03-15T16:28:08.643Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2024-03-15T16:28:09.087Z INFO webdriver: Downloading Chromedriver v122.0.6261.129
[0-0] 2024-03-15T16:28:09.335Z WARN webdriver: Chromedriver v122.0.6261.129 don't exist, trying to find known good version...
[0-0] 2024-03-15T16:28:09.425Z INFO webdriver: Download of Chromedriver v122.0.6261.128 was successful
[0-0] 2024-03-15T16:28:10.930Z INFO chromedriver: Starting ChromeDriver 122.0.6261.128 (f18a44fedeb29764b2b5336c120fdd90ef1a3f5c-refs/branch-heads/6261@{#1057}) on port 49859
[0-0] 2024-03-15T16:28:10.930Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
[0-0] 2024-03-15T16:28:10.930Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[0-0] 2024-03-15T16:28:10.937Z INFO chromedriver: ChromeDriver was started successfully.
[0-0] 2024-03-15T16:28:11.902Z INFO @wdio/utils: Started Chromedriver v122.0.6261.129 with params --port=49859 --allowed-origins=* --allowed-ips=0.0.0.0 in 2836ms on port 49859
[0-0] 2024-03-15T16:28:12.173Z INFO webdriver: [POST] http://0.0.0.0:49859/session
[0-0] 2024-03-15T16:28:12.174Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': [Object] },
[0-0]     firstMatch: [ {} ]
[0-0]   },
[0-0]   desiredCapabilities: {
[0-0]     browserName: 'chrome',
[0-0]     'goog:chromeOptions': {
[0-0]       binary: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
[0-0]     }
[0-0]   }
[0-0] }

DevTools listening on ws://127.0.0.1:49866/devtools/browser/4ea2b772-9fb7-479f-9cde-afcc7fb49d57
[0-0] 2024-03-15T16:28:14.068Z INFO webdriver: COMMAND navigateTo("https://the-internet.herokuapp.com/login")
[0-0] 2024-03-15T16:28:14.070Z INFO webdriver: [POST] http://0.0.0.0:49859/session/8a5475891fea8e7f45b230a454413a79/url
[0-0] 2024-03-15T16:28:14.070Z INFO webdriver: DATA { url: 'https://the-internet.herokuapp.com/login' }
[0-0] 2024-03-15T16:28:18.442Z INFO webdriver: RESULT null
[0-0] Error in "My Login application.should login with valid credentials"
Error: expect(received).toBe(expected) // Object.is equality

Expected: "fail"
Received: "pass"
    at Context.<anonymous> (file:///C:/Users/cs1lrj/Documents/automation/test/test/specs/test.e2e.ts:7:30)
[0-0] 2024-03-15T16:28:18.456Z INFO webdriver: COMMAND deleteSession()
[0-0] 2024-03-15T16:28:18.457Z INFO webdriver: [DELETE] http://0.0.0.0:49859/session/8a5475891fea8e7f45b230a454413a79
[0-0] 2024-03-15T16:28:18.699Z INFO webdriver: RESULT null
[0-0] 2024-03-15T16:28:18.700Z INFO webdriver: Kill driver process with PID 1932
[0-0] FAILED in chrome - file:///C:/Users/cs1lrj/Documents/automation/test/test/specs/test.e2e.ts
2024-03-15T16:28:18.846Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2024-03-15T16:28:18.847Z INFO @wdio/cli:launcher: Run onComplete hook

 "spec" Reporter:
------------------------------------------------------------------
[chrome 122.0.6261.128 windows #0-0] Running: chrome (v122.0.6261.128) on windows
[chrome 122.0.6261.128 windows #0-0] Session ID: 8a5475891fea8e7f45b230a454413a79
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] » \test\specs\test.e2e.ts
[chrome 122.0.6261.128 windows #0-0] My Login application
[chrome 122.0.6261.128 windows #0-0]     should login with valid credentials
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] 1 failing (4.6s)
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] 1) My Login application should login with valid credentials
[chrome 122.0.6261.128 windows #0-0] 1) My Login application should login with valid credentials
[chrome 122.0.6261.128 windows #0-0] expect(received).toBe(expected) // Object.is equality

Expected: "fail"
Received: "pass"
[chrome 122.0.6261.128 windows #0-0] Error: expect(received).toBe(expected) // Object.is equality
[chrome 122.0.6261.128 windows #0-0]
[chrome 122.0.6261.128 windows #0-0] Expected: "fail"
[chrome 122.0.6261.128 windows #0-0] Received: "pass"
[chrome 122.0.6261.128 windows #0-0]     at Context.<anonymous> (file:///C:/Users/cs1lrj/Documents/automation/test/test/specs/test.e2e.ts:7:30)


Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:14

2024-03-15T16:28:18.854Z INFO @wdio/local-runner: Shutting down spawned worker
2024-03-15T16:28:19.111Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2024-03-15T16:28:19.111Z INFO @wdio/local-runner: shutting down

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues
@lukerj1988 lukerj1988 added Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet labels Mar 15, 2024
@lukerj1988 lukerj1988 changed the title [🐛 Bug]: Error line incorrectly reporter [🐛 Bug]: Error line incorrectly reported in the terminal Mar 15, 2024
@christian-bromann christian-bromann added help wanted Issues that are free to take by anyone interested and removed Needs Triaging ⏳ No one has looked into the issue yet labels Mar 15, 2024
@wdio-bot
Copy link
Contributor

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

@lukerj1988
Copy link
Author

I don't know if this will help in diagnosing the issue, but when running the same reproducible steps but staying with Javascript rather than Typescript the error line reporting works as expected. A colleague mentioned it and I've reproduced it just now.

@ykmet-IO
Copy link

ykmet-IO commented Jun 4, 2024

hello, i have the same issue with my project, i am using webdriverio 8.37, node 20.11, mocha as framework, typescript as compiler, chrome as browser ...

how can i solve that without downgrade to webdriverio 7 ?
is there any news about that?
Thanks for your helps

@christian-bromann
Copy link
Member

is there any news about that?

This might get resolved with v9 where we use tsx for TypeScript compiling. Can't guarantee this though. Contributions that resolve this problem are appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 help wanted Issues that are free to take by anyone interested
Projects
None yet
Development

No branches or pull requests

4 participants