mucsi96 / nightwatch-api

[DEPRECATED] Cross-runner API for Nightwatch.js
https://nightwatch-api.netlify.com/
MIT License
84 stars 64 forks source link

Nightwatch API TS Definition #833

Closed jleck closed 4 years ago

jleck commented 4 years ago

Hi,

I've just been trying to use the module within my typescript project, but the following lline from index.d.ts errors:

import { Api } from 'nightwatch';

I can fix this by changing it to:

import { NightwatchAPI as Api } from 'nightwatch';

I did however look at your tsconfig, and note you load in your own type definitions. Might to be useful to document the need for setting typeRoots somewhere.

mucsi96 commented 4 years ago

Hi. Thanks for submitting the issue. Unfortunately I was expecting this issue. I will take a look what can I do

christophedebatz commented 4 years ago

Same issue currently with the last version.. :-( Can you fix the code with the @jleck solution please?

jleck commented 4 years ago

Hi @christophedebatz, if you add the types within this package as well as the standard types, it should work as is.

christophedebatz commented 4 years ago

When you say "within this package", do you mean that I have to manually modify some file of my node_modules or another file I don't know about ? Thanks @jleck

jleck commented 4 years ago

HI @christophedebatz ,

In your tsconfig.json, add:

{
    "compilerOptions": {
        "typeRoots": [
            "./node_modules/nightwatch-api/types",
            "./node_modules/@types"
        ]
    }
}

That will make it pick up the modified type definitions from this package. While I think it should be refactored so this isn't needed, it does work for now.

christophedebatz commented 4 years ago

Thanks @jleck Do you had any other issues with the typings? For me yes, just take a look here: My code, very simple:

import { client } from 'nightwatch-api'
import { Given } from 'cucumber'

Given('I go to hozana.org', () => {
  return client.assert.visible('input[name=jumbotron]')
})

And TS error:

src/features/homepage.ts:6:24 - error TS2339: Property 'visible' does not exist on type 'string | Function | Promise<Api> | Expect | Sections | Pages'.
  Property 'visible' does not exist on type 'string'.

6   return client.assert.visible('input[name=jumbotron]')
                         ~~~~~~~

Any idea?

jleck commented 4 years ago

Hi @christophedebatz ,

I'm using .waitForElementVisible('input[name=jumbotron]') without issue, does that work for you?

P.S. I'm using this with cucumber too!

jleck commented 4 years ago

@christophedebatz actually just noticed, I'm always using through a page object too.

christophedebatz commented 4 years ago

Hello @jleck thank you for replying quickly, Can you send me your conifgurations files please (tsc, cucumber and nightwatch), because I'm still encountering some types errors and the page object does not work with Typescript for me. We have the same goal: work with nightwatch and cucumber with typescript ! Thanks a lot,

christophedebatz commented 4 years ago

@jleck The waitForElementVisible is working for me but all the client.assert.XXXX assertions are not recognized by typescript linter? And you? Idem, on my project, the page ares not found by nightwatch ... :(

jleck commented 4 years ago

@christophedebatz sorry for the delay, just seen this.

I don't seem to have any TS after loading those types. Although IMO I would use any for now, as the types don't really match what's actually available.