Closed reallymello closed 1 year ago
PR #3778 resolves the issue with clickSearch()
in TypeScript. You can try it by running npm i -D "garg3133/nightwatch#fix-pageObjects-types"
in your project.
As for the first issue, Step 7 and 8 stated above are not correct. These should be as follows:
"extends": "../tsconfig"
below compilerOptions../tsconfig.json
add:
"compilerOptions": {
...
},
// files should contain the path to type declaration files
"files": ["./nightwatch/types/page-objects.d.ts"],
// include should contain the path to directory where your tests are present (where these tsconfigs should be applied)
"include": ["./nightwatch"]
We are working on creating a separate doc page for TypeScript where all these steps will be clearly mentioned.
Tested with https://github.com/nightwatchjs/nightwatch/pull/3778 and it appears to be working
Description of the bug/issue
When I use a typescript page object command in a Nightwatch test project I expect to be able to explicitly specific the page object's interface as the type and use commands defined in the page object in command chaining, but instead I receive error
and
Steps to reproduce
(as of writing that should setup Nightwatch 3.0.1)
import { EnhancedPageObject, PageObjectModel } from 'nightwatch';
const ecosiaCommands = { clickSearch(this: EcosiaPage) { return this.waitForElementVisible('@submit', 10000) .click('@submit') .waitForElementNotPresent('@submit'); }, };
const ecosiaPage: PageObjectModel = { url: 'http://www.ecosia.com', commands: [ecosiaCommands], elements: { searchInput: { selector: 'input[type=search]', }, submit: { selector: 'button[type=submit]', }, }, };
export default ecosiaPage;
export interface EcosiaPage extends EnhancedPageObject< typeof ecosiaCommands, typeof ecosiaPage.elements, null
"include": ["types"]
below compilerOptions"include": ["./nightwatch/types"]
(I'm not sure if 7 and 8 are necessary, but was following steps from a prior bug ticket)
npx nightwatch -t nightwatch\tests\ecosia.ts
Receive error:
Might also be worth noting if you don't specific the test and choose to run all you get no output at all (which seems like another issue)
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
3.0.1
Node Version
18.16.0
Browser
Chrome 114.0.5735.134
Operating System
Windows 10
Additional Information
nightwatch.zip