-
-
Notifications
You must be signed in to change notification settings - Fork 752
Description
I'm new to CodeceptJS, just went through the install and got a short test running. I noticed no typescript definitions available, which is a bummer since there is no IDE autocompletion (and no compiler check) when writing tests using Typescript.
I'm using webdriverio and noticed there is a webdriver.d.ts file (for version 3.3.0). The docs of CodeceptJS show a lot of methods that supposedly are based on webdriverio helper, but I can't find a lot of those in the type definition above, so not sure if they were added to later versions or if they are actually part of CodeceptJS and not WebdriverIO.
At any rate, I just quickly threw an incomplete type file based on the dump from codeceptjs list
/// <reference path="../../../typings/webdriverio/webdriverio.d.ts" />
type ICodeceptCallback = (i: CodeceptJS.I) => void;
declare const Feature: (string: string) => void;
declare const Scenario: (string: string, callback: ICodeceptCallback) => void;
declare const Before: (callback: ICodeceptCallback) => void;
declare const After: (callback: ICodeceptCallback) => void;
declare const within: (selector: string, callback: Function) => void;
declare namespace CodeceptJS {
export interface I extends WebdriverIO.Client<void> {
amOnPage: (url: string) => any;
rightClick: (locator: string) => any;
fillField: (field: string, value: string) => any;
appendField: (field: string, value: string) => any;
selectOption: (select, option) => any;
attachFile: (locator: string, pathToFile) => any;
checkOption: (field: string, context) => any;
grabTextFrom: (locator: string) => any;
grabHTMLFrom: (locator: string) => any;
grabValueFrom: (locator: string) => any;
grabAttributeFrom: (locator: string, attr) => any;
seeInTitle: (text: string) => any;
dontSeeInTitle: (text: string) => any;
grabTitle: () => any;
see: (text: string, context) => any;
dontSee: (text: string, context) => any;
seeInField: (field: string, value: string) => any;
dontSeeInField: (field: string, value: string) => any;
seeCheckboxIsChecked: (field) => any;
dontSeeCheckboxIsChecked: (field) => any;
seeElement: (locator: string) => any;
dontSeeElement: (locator: string) => any;
seeElementInDOM: (locator: string) => any;
dontSeeElementInDOM: (locator: string) => any;
seeInSource: (text: string) => any;
dontSeeInSource: (text: string) => any;
seeNumberOfElements: (selector, num) => any;
seeInCurrentUrl: (url) => any;
dontSeeInCurrentUrl: (url) => any;
seeCurrentUrlEquals: (url) => any;
dontSeeCurrentUrlEquals: (url) => any;
executeScript: (fn) => any;
executeAsyncScript: (fn) => any;
scrollTo: (locator: string, offsetX: number, offsetY: number) => any;
moveCursorTo: (locator: string, offsetX: number, offsetY: number) => any;
saveScreenshot: (fileName) => any;
setCookie: (cookie) => any;
clearCookie: (cookie) => any;
clearField: (locator: string) => any;
seeCookie: (name) => any;
dontSeeCookie: (name) => any;
grabCookie: (name) => any;
acceptPopup: () => any;
cancelPopup: () => any;
seeInPopup: (text: string) => any;
pressKey: (key) => any;
resizeWindow: (width: number | 'maximize', height: number) => any;
waitForElement: (locator: string, seconds?: number) => void,
wait: (seconds: number) => void
}
}
declare module "codeceptjs" {
export = CodeceptJS;
}
which on a quick glance gets the job done when assigning the CodeceptJS.I type to I:
/// <reference path="./codeceptjs.d.ts" />
Feature('My First Test');
Scenario('test something', (I: CodeceptJS.I) => {
I.amOnPage(`/`);
I.saveScreenshot('debug.png');
I.resizeWindow(1900, 1080);
I.saveScreenshot('desktop.png');
});Would be nice to get proper types for the library since it provides type safety and saves from having to look up the documentation