taiko icon indicating copy to clipboard operation
taiko copied to clipboard

Dropdown multiple values not supported in Typescript

Open fmpanelli opened this issue 5 years ago • 2 comments

Describe the bug Since PR #1602 Taiko supports multiple value selection for dropdowns, but that does not work in Typescript due to type inconsistency (as already mentioned in the PR comments)

To Reproduce Steps (or script) to reproduce the behavior:

  1. Create a new folder and cd into it
  2. Initialize the npm project with npm init
  3. Add Taiko to the project npm i taiko
  4. Add Typescript to the project npm i -D typescript
  5. Create a new file like:
//index.ts
import  { dropDown } from "taiko";
async function main() {
  const myDropdown = dropDown('Vehicle:');
  await myDropdown.select(['Car','Van'])
  const values: string[] = await myDropdown.value()
}
  1. try compiling with npx tsc
  2. you get an error like:
index.ts:6:9 - error TS2322: Type 'string' is not assignable to type 'string[]'.
6   const values: string[] = await myDropdown.value()

Logs

index.ts:6:9 - error TS2322: Type 'string' is not assignable to type 'string[]'.
6   const values: string[] = await myDropdown.value()

Expected behavior DropDownWrapper now extends ValueWrapper which has a method value() returning Promise<string>.

I think DropDownWrapper should extend a new MultiValueWrapper which has a method values() returning Promise<string | Array<string> | Array<number>>. The ValueWrapper should remain as it is for the elements that actually implement that behavior such as ColorWrapper, TextBoxWrapper, etc.

Screenshots If applicable, add screenshots to help explain your problem.

Versions:

  • Taiko: 1.0.26
  • OS: Win10 home 10.0.19041
  • Node.js: v14.4.0
  • Typescript: 4.0.5

Additional context Add any other context about the problem here.

fmpanelli avatar Nov 01 '20 10:11 fmpanelli

I think DropDownWrapper should extend a new MultiValueWrapper which has a method values() returning Promise<string | Array | Array>. The ValueWrapper should remain as it is for the elements that actually implement that behavior such as ColorWrapper, TextBoxWrapper, etc.

@fmpanelli Since you already have the fix in your mind, would you like to raise a PR for the same?

BugDiver avatar Nov 02 '20 07:11 BugDiver

@fmpanelli Since you already have the fix in your mind, would you like to raise a PR for the same?

Sure! Hopefully I'll be able to submit a PR this evening.

fmpanelli avatar Nov 02 '20 10:11 fmpanelli