Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions types/nightwatch/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ export interface ElementProperties {
* @example
* 'css selector'
*/
locateStrategy?: string;
locateStrategy?: LocateStrategy;

/**
* used to target a specific element in a query that results in multiple elements returned. Normally,
Expand Down Expand Up @@ -1626,11 +1626,11 @@ export interface EnhancedElementInstance<T> {
selector: string;
}

export type EnhancedSectionInstance<Commands = {}, Elements = {}, Sections extends EnhancedPageObjectSections = {}> = EnhancedPageObject<
Commands,
Elements,
Sections
>;
export type EnhancedSectionInstance<
Commands = {},
Elements = {},
Sections extends EnhancedPageObjectSections = {},
> = EnhancedPageObject<Commands, Elements, Sections>;

export interface EnhancedPageObjectSections {
[name: string]: EnhancedSectionInstance<any, any, any>;
Expand Down Expand Up @@ -4691,3 +4691,32 @@ export interface WebDriverProtocolMobileRelated {
*/
setContext(context: string, callback?: () => void): this;
}

/**
* Map of DOM element locators as shorthand string selectors based on
* global selector setting or ElementLocator
*
* @example
* const elements: PageElements {
* header: "h1",
* banner: {
* locateStrategy: "css selector",
* selector: "#bannerId"
* }
* }
*/
export interface PageElements {
[key: string]: string | ElementProperties;
}

/**
* Type for defining page object models allowing for optional type-safe
* inclusion of url, elements, sections, commands, and props properties.
*/
export interface PageObjectModel {
url?: string | ((...args: any) => string);
elements?: PageElements;
sections?: EnhancedPageObjectSections;
commands?: any;
props?: any;
}
12 changes: 5 additions & 7 deletions types/nightwatch/test/nightwatch-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
EnhancedSectionInstance,
NightwatchAPI,
NightwatchAssertion,
NightwatchBrowser,
NightwatchTests,
PageObjectModel,
} from 'nightwatch';

//
Expand Down Expand Up @@ -64,10 +64,8 @@ const testGeneral: NightwatchTests = {
},

'test user defined globals': () => {
browser
.url(`http://${browser.globals.username}:${browser.globals.password}@example.com`)
.end();
}
browser.url(`http://${browser.globals.username}:${browser.globals.password}@example.com`).end();
},
};

//
Expand Down Expand Up @@ -125,7 +123,7 @@ interface MenuSection
{ apps: AppsSection }
> {}

const googlePage = {
const googlePage: PageObjectModel = {
commands: [
{
submit(this: GooglePage) {
Expand All @@ -151,7 +149,7 @@ const googlePage = {

// export = googlePage;

const iFrame = {
const iFrame: PageObjectModel = {
elements: {
iframe: '#mce_0_ifr',
textbox: 'body#tinymce p',
Expand Down