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

String parameter beginning with numbers are wrongly interpreted as numbers #190

Open
anthony-legay opened this issue Oct 10, 2024 · 4 comments · Fixed by #191
Open

String parameter beginning with numbers are wrongly interpreted as numbers #190

anthony-legay opened this issue Oct 10, 2024 · 4 comments · Fixed by #191

Comments

@anthony-legay
Copy link

Describe the bug
Say we have spec like this one:
* Get product with id "81423165-ad04-4c7b-9f85-75d1a8aa1b0d"

Since #186, which now uses Number.parseFloat directly instead of Number constructor in the PrimitiveParser, strings like the UUID above or even parameters which could be product IDs like "012345" are now successfully converted to Number (instead of NaN), dropping useful characters in the process (excess hex letters for the UUID, leading zeroes for the product ID)...which makes it pretty much unusable right now.

To Reproduce
Steps to reproduce the behavior:
Just use a UUID or a static parameter beginning with one or more 0

Expected behavior
A clear and concise description of what you expected to happen.
With a spec like:

* Get product with id "81423165-ad04-4c7b-9f85-75d1a8aa1b0d"

and an implementation like:

@Step("Get product with id <productId>")
public async getCart(productId: string) {
  assert.equal(productId, "81423165-ad04-4c7b-9f85-75d1a8aa1b0d") // currently 81423165
}

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.7
  • Gauge and plugin version 3.0.2 (latest)
  • Node version: 20.17.0
  • Npm version: 10.8.2
@zabil
Copy link
Member

zabil commented Oct 11, 2024

Re-opening to cover the following case #191 (comment)

@zabil zabil reopened this Oct 11, 2024
@anthony-legay
Copy link
Author

We also need to be careful with a simple startsWith('0') (I already thought about this one actually 😅) as it would also not cover values like "0.42" (like a rate or something) 🤯

@zabil
Copy link
Member

zabil commented Oct 11, 2024

@anthony-legay

I believe this is covered in the current code. I've tried the following.

* Check number starting with 0 for example "012" is correct
* Check number starting with 0 and decimal "0.12" is correct
  @Step("Check number starting with zero for example <value> is correct")
  async numberStartingWithZero(value: string) {
    assert.strictEqual(typeof value, "string");
    assert.strictEqual(value, "012");
  }

  @Step("Check number starting with zero and decimal <value> is correct")
  async decimal(value: string) {
    assert.strictEqual(value, "0.12");
  }

Have you tried running it?

@hazzik
Copy link

hazzik commented Oct 12, 2024

In 0.3.5 I'm getting "1" passed down as a number instead of string.

This is my step.

Write "1" into "Phone number"

And this is my step implementation:

@Step("Write <value> into <name>")
public static async writeInto(value: string, name: string) { /*...*/ }

To clarify: this step is a part of test that will check that the field shows "invalid phone number" warning.

Is it possible to get the correct type from the implementation method definition instead of blindly trying to convert to number if it fits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants