UNPKG

codeceptjs

Version:

Modern Era Acceptance Testing Framework for NodeJS

1,429 lines (1,428 loc) 369 kB
/** @namespace CodeceptJS */ declare namespace CodeceptJS { class ApiDataFactory { /** * Generates a new record using factory and saves API request to store it. * * ```js * // create a user * I.have('user'); * // create user with defined email * // and receive it when inside async function * const user = await I.have('user', { email: 'user@user.com'}); * ``` * * @param {*} factory factory to use * @param {*} params predefined parameters */ have(factory: any, params: any): void; /** * Generates bunch of records and saves multiple API requests to store them. * * ```js * // create 3 posts * I.haveMultiple('post', 3); * * // create 3 posts by one author * I.haveMultiple('post', 3, { author: 'davert' }); * ``` * * @param {*} factory * @param {*} times * @param {*} params */ haveMultiple(factory: any, times: any, params: any): void; /** * Executes request to create a record in API. * Can be replaced from a in custom helper. * * @param {*} factory * @param {*} data */ _requestCreate(factory: any, data: any): void; /** * Executes request to delete a record in API * Can be replaced from a custom helper. * * @param {*} factory * @param {*} id */ _requestDelete(factory: any, id: any): void; } /** * Appium Special Methods for Mobile only */ class Appium { /** * Execute code only on iOS * * ```js * I.runOnIOS(() => { * I.click('//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'); * I.see('Hi, IOS', '~welcome'); * }); * ``` * * Additional filter can be applied by checking for capabilities. * For instance, this code will be executed only on iPhone 5s: * * * ```js * I.runOnIOS({deviceName: 'iPhone 5s'},() => { * // ... * }); * ``` * * Also capabilities can be checked by a function. * * ```js * I.runOnAndroid((caps) => { * // caps is current config of desiredCapabiliites * return caps.platformVersion >= 6 * },() => { * // ... * }); * ``` * * @param {*} caps * @param {*} fn */ runOnIOS(caps: any, fn: any): void; /** * Execute code only on Android * * ```js * I.runOnAndroid(() => { * I.click('io.selendroid.testapp:id/buttonTest'); * }); * ``` * * Additional filter can be applied by checking for capabilities. * For instance, this code will be executed only on Android 6.0: * * * ```js * I.runOnAndroid({platformVersion: '6.0'},() => { * // ... * }); * ``` * * Also capabilities can be checked by a function. * In this case, code will be executed only on Android >= 6. * * ```js * I.runOnAndroid((caps) => { * // caps is current config of desiredCapabiliites * return caps.platformVersion >= 6 * },() => { * // ... * }); * ``` * * @param {*} caps * @param {*} fn */ runOnAndroid(caps: any, fn: any): void; /** * Execute code only in Web mode. * * ```js * I.runInWeb(() => { * I.waitForElement('#data'); * I.seeInCurrentUrl('/data'); * }); * ``` * * @param {*} fn */ runInWeb(fn: any): void; /** * Check if an app is installed. * * ```js * I.seeAppIsInstalled("com.example.android.apis"); * ``` * * @param {string} bundleId String ID of bundled app * * Appium: support only Android */ seeAppIsInstalled(bundleId: string): void; /** * Check if an app is not installed. * * ```js * I.seeAppIsNotInstalled("com.example.android.apis"); * ``` * * @param {string} bundleId String ID of bundled app * * Appium: support only Android */ seeAppIsNotInstalled(bundleId: string): void; /** * Install an app on device. * * ```js * I.installApp('/path/to/file.apk'); * ``` * @param {string} path path to apk file * * Appium: support only Android */ installApp(path: string): void; /** * Remove an app from the device. * * ```js * I.removeApp('appName', 'com.example.android.apis'); * ``` * @param {string} appId * @param {string} bundleId String ID of bundle * * Appium: support only Android */ removeApp(appId: string, bundleId: string): void; /** * Check current activity on an Android device. * * ```js * I.seeCurrentActivityIs(".HomeScreenActivity") * ``` * @param {string} currentActivity * * Appium: support only Android */ seeCurrentActivityIs(currentActivity: string): void; /** * Check whether the device is locked. * * ```js * I.seeDeviceIsLocked(); * ``` * * Appium: support only Android */ seeDeviceIsLocked(): void; /** * Check whether the device is not locked. * * ```js * I.seeDeviceIsUnlocked(); * ``` * * Appium: support only Android */ seeDeviceIsUnlocked(): void; /** * Check the device orientation * * ```js * I.seeOrientationIs('PORTRAIT'); * I.seeOrientationIs('LANDSCAPE') * ``` * * @param {'LANDSCAPE'|'PORTRAIT'} orientation LANDSCAPE or PORTRAIT * * Appium: support Android and iOS */ seeOrientationIs(orientation: 'LANDSCAPE' | 'PORTRAIT'): void; /** * Set a device orientation. Will fail, if app will not set orientation * * ```js * I.setOrientation('PORTRAIT'); * I.setOrientation('LANDSCAPE') * ``` * * @param {'LANDSCAPE'|'PORTRAIT'} orientation LANDSCAPE or PORTRAIT * * Appium: support Android and iOS */ setOrientation(orientation: 'LANDSCAPE' | 'PORTRAIT'): void; /** * Get list of all available contexts * * ``` * let contexts = await I.grabAllContexts(); * ``` * * Appium: support Android and iOS */ grabAllContexts(): void; /** * Retrieve current context * * ```js * let context = await I.grabContext(); * ``` * * Appium: support Android and iOS */ grabContext(): void; /** * Get current device activity. * * ```js * let activity = await I.grabCurrentActivity(); * ``` * * Appium: support only Android */ grabCurrentActivity(): void; /** * Get information about the current network connection (Data/WIFI/Airplane). * The actual server value will be a number. However WebdriverIO additional * properties to the response object to allow easier assertions. * * ```js * let con = await I.grabNetworkConnection(); * ``` * * Appium: support only Android */ grabNetworkConnection(): void; /** * Get current orientation. * * ```js * let orientation = await I.grabOrientation(); * ``` * * Appium: support Android and iOS */ grabOrientation(): void; /** * Get all the currently specified settings. * * ```js * let settings = await I.grabSettings(); * ``` * * Appium: support Android and iOS */ grabSettings(): void; /** * Switch to the specified context. * * @param {*} context the context to switch to */ _switchToContext(context: any): void; /** * Switches to web context. * If no context is provided switches to the first detected web context * * ```js * // switch to first web context * I.switchToWeb(); * * // or set the context explicitly * I.switchToWeb('WEBVIEW_io.selendroid.testapp'); * ``` * * @param {string} [context] */ switchToWeb(context?: string): void; /** * Switches to native context. * By default switches to NATIVE_APP context unless other specified. * * ```js * I.switchToNative(); * * // or set context explicitly * I.switchToNative('SOME_OTHER_CONTEXT'); * ``` * @param {*} context */ switchToNative(context: any): void; /** * Start an arbitrary Android activity during a session. * * ```js * I.startActivity('io.selendroid.testapp', '.RegisterUserActivity'); * ``` * * Appium: support only Android */ startActivity(): void; /** * Set network connection mode. * * * airplane mode * * wifi mode * * data data * * ```js * I.setNetworkConnection(0) // airplane mode off, wifi off, data off * I.setNetworkConnection(1) // airplane mode on, wifi off, data off * I.setNetworkConnection(2) // airplane mode off, wifi on, data off * I.setNetworkConnection(4) // airplane mode off, wifi off, data on * I.setNetworkConnection(6) // airplane mode off, wifi on, data on * ``` * See corresponding [webdriverio reference](http://webdriver.io/api/mobile/setNetworkConnection.html). * * Appium: support only Android */ setNetworkConnection(): void; /** * Update the current setting on the device * * ```js * I.setSettings({cyberdelia: 'open'}); * ``` * * @param {object} settings object * * Appium: support Android and iOS */ setSettings(settings: any): void; /** * Hide the keyboard. * * ```js * // taps outside to hide keyboard per default * I.hideDeviceKeyboard(); * I.hideDeviceKeyboard('tapOutside'); * * // or by pressing key * I.hideDeviceKeyboard('pressKey', 'Done'); * ``` * * @param {'tapOutside' | 'pressKey'} strategy desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’) * * Appium: support Android and iOS */ hideDeviceKeyboard(strategy: 'tapOutside' | 'pressKey'): void; /** * Send a key event to the device. * List of keys: https://developer.android.com/reference/android/view/KeyEvent.html * * ```js * I.sendDeviceKeyEvent(3); * ``` * * @param {number} keyValue Device specific key value * * Appium: support only Android */ sendDeviceKeyEvent(keyValue: number): void; /** * Open the notifications panel on the device. * * ```js * I.openNotifications(); * ``` * * Appium: support only Android */ openNotifications(): void; /** * The Touch Action API provides the basis of all gestures that can be * automated in Appium. At its core is the ability to chain together ad hoc * individual actions, which will then be applied to an element in the * application on the device. * [See complete documentation](http://webdriver.io/api/mobile/touchAction.html) * * ```js * I.makeTouchAction("~buttonStartWebviewCD", 'tap'); * ``` * * Appium: support Android and iOS */ makeTouchAction(): void; /** * Taps on element. * * ```js * I.tap("~buttonStartWebviewCD"); * ``` * * Shortcut for `makeTouchAction` * * @param {*} locator */ tap(locator: any): void; /** * Perform a swipe on the screen or an element. * * ```js * let locator = "#io.selendroid.testapp:id/LinearLayout1"; * I.swipe(locator, 800, 1200, 1000); * ``` * * [See complete reference](http://webdriver.io/api/mobile/swipe.html) * * @param {CodeceptJS.LocatorOrString} locator * @param {number} xoffset * @param {number} yoffset * @param {number} [speed=1000] (optional), 1000 by default * * Appium: support Android and iOS */ swipe(locator: CodeceptJS.LocatorOrString, xoffset: number, yoffset: number, speed?: number): void; /** * Perform a swipe on the screen. * * ```js * I.performswipe(100,200); * ``` * * @param {number} from * @param {number} to * * Appium: support Android and iOS */ performSwipe(from: number, to: number): void; /** * Perform a swipe down on an element. * * ```js * let locator = "#io.selendroid.testapp:id/LinearLayout1"; * I.swipeDown(locator); // simple swipe * I.swipeDown(locator, 500); // set speed * I.swipeDown(locator, 1200, 1000); // set offset and speed * ``` * * @param {CodeceptJS.LocatorOrString} locator * @param {number} [yoffset] (optional) * @param {number} [speed=1000] (optional), 1000 by default * * Appium: support Android and iOS */ swipeDown(locator: CodeceptJS.LocatorOrString, yoffset?: number, speed?: number): void; /** * * Perform a swipe left on an element. * * ```js * let locator = "#io.selendroid.testapp:id/LinearLayout1"; * I.swipeLeft(locator); // simple swipe * I.swipeLeft(locator, 500); // set speed * I.swipeLeft(locator, 1200, 1000); // set offset and speed * ``` * * @param {CodeceptJS.LocatorOrString} locator * @param {number} [xoffset] (optional) * @param {number} [speed=1000] (optional), 1000 by default * * Appium: support Android and iOS */ swipeLeft(locator: CodeceptJS.LocatorOrString, xoffset?: number, speed?: number): void; /** * Perform a swipe right on an element. * * ```js * let locator = "#io.selendroid.testapp:id/LinearLayout1"; * I.swipeRight(locator); // simple swipe * I.swipeRight(locator, 500); // set speed * I.swipeRight(locator, 1200, 1000); // set offset and speed * ``` * * @param {CodeceptJS.LocatorOrString} locator * @param {number} [xoffset] (optional) * @param {number} [speed=1000] (optional), 1000 by default * * Appium: support Android and iOS */ swipeRight(locator: CodeceptJS.LocatorOrString, xoffset?: number, speed?: number): void; /** * Perform a swipe up on an element. * * ```js * let locator = "#io.selendroid.testapp:id/LinearLayout1"; * I.swipeUp(locator); // simple swipe * I.swipeUp(locator, 500); // set speed * I.swipeUp(locator, 1200, 1000); // set offset and speed * ``` * * @param {CodeceptJS.LocatorOrString} locator * @param {number} [yoffset] (optional) * @param {number} [speed=1000] (optional), 1000 by default * * Appium: support Android and iOS */ swipeUp(locator: CodeceptJS.LocatorOrString, yoffset?: number, speed?: number): void; /** * Perform a swipe in selected direction on an element to searchable element. * * ```js * I.swipeTo( * "android.widget.CheckBox", // searchable element * "//android.widget.ScrollView/android.widget.LinearLayout", // scroll element * "up", // direction * 30, * 100, * 500); * ``` * * @param {string} searchableLocator * @param {string} scrollLocator * @param {string} direction * @param {number} timeout * @param {number} offset * @param {number} speed * * Appium: support Android and iOS */ swipeTo(searchableLocator: string, scrollLocator: string, direction: string, timeout: number, offset: number, speed: number): void; /** * Performs a specific touch action. * The action object need to contain the action name, x/y coordinates * * ```js * I.touchPerform([{ * action: 'press', * options: { * x: 100, * y: 200 * } * }, {action: 'release'}]) * * I.touchPerform([{ * action: 'tap', * options: { * element: '1', // json web element was queried before * x: 10, // x offset * y: 20, // y offset * count: 1 // number of touches * } * }]); * ``` * * Appium: support Android and iOS */ touchPerform(): void; /** * Pulls a file from the device. * * ```js * I.pullFile('/storage/emulated/0/DCIM/logo.png', 'my/path'); * // save file to output dir * I.pullFile('/storage/emulated/0/DCIM/logo.png', output_dir); * ``` * * Appium: support Android and iOS */ pullFile(): void; /** * Perform a shake action on the device. * * ```js * I.shakeDevice(); * ``` * * Appium: support only iOS */ shakeDevice(): void; /** * Perform a rotation gesture centered on the specified element. * * ```js * I.rotate(120, 120) * ``` * * See corresponding [webdriverio reference](http://webdriver.io/api/mobile/rotate.html). * * Appium: support only iOS */ rotate(): void; /** * Set immediate value in app. * * See corresponding [webdriverio reference](http://webdriver.io/api/mobile/setImmediateValue.html). * * Appium: support only iOS */ setImmediateValue(): void; /** * Simulate Touch ID with either valid (match == true) or invalid (match == false) fingerprint. * * ```js * I.touchId(); // simulates valid fingerprint * I.touchId(true); // simulates valid fingerprint * I.touchId(false); // simulates invalid fingerprint * ``` * * Appium: support only iOS * TODO: not tested */ simulateTouchId(): void; /** * Close the given application. * * ```js * I.closeApp(); * ``` * * Appium: support only iOS */ closeApp(): void; /** * Appends text to a input field or textarea. * Field is located by name, label, CSS or XPath * * ```js * I.appendField('#myTextField', 'appended'); * ``` * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator * @param {string} value text value to append. * {--end--} * */ appendField(field: CodeceptJS.LocatorOrString, value: string): void; /** * Selects a checkbox or radio button. * Element is located by label or name or CSS or XPath. * * The second parameter is a context (CSS or XPath locator) to narrow the search. * * ```js * I.checkOption('#agree'); * I.checkOption('I Agree to Terms and Conditions'); * I.checkOption('agree', '//form'); * ``` * @param {CodeceptJS.LocatorOrString} field checkbox located by label | name | CSS | XPath | strict locator. * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS | XPath | strict locator. * {--end--} * */ checkOption(field: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): void; /** * Perform a click on a link or a button, given by a locator. * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. * For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched. * For images, the "alt" attribute and inner text of any parent links are searched. * * The second parameter is a context (CSS or XPath locator) to narrow the search. * * ```js * // simple link * I.click('Logout'); * // button of form * I.click('Submit'); * // CSS button * I.click('#form input[type=submit]'); * // XPath * I.click('//form/*[@type=submit]'); * // link in context * I.click('Logout', '#nav'); * // using strict locator * I.click({css: 'nav a.login'}); * ``` * * @param {CodeceptJS.LocatorOrString} locator clickable link or button located by text, or any element located by CSS|XPath|strict locator. * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element to search in CSS|XPath|Strict locator. * {--end--} * */ click(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString): void; /** * Verifies that the specified checkbox is not checked. * * ```js * I.dontSeeCheckboxIsChecked('#agree'); // located by ID * I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label * I.dontSeeCheckboxIsChecked('agree'); // located by name * ``` * * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator. * {--end--} * */ dontSeeCheckboxIsChecked(field: CodeceptJS.LocatorOrString): void; /** * Opposite to `seeElement`. Checks that element is not visible (or in DOM) * * ```js * I.dontSeeElement('.modal'); // modal is not shown * ``` * * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|Strict locator. * {--end--} */ dontSeeElement(locator: CodeceptJS.LocatorOrString): void; /** * Checks that value of input field or textarea doesn't equal to given value * Opposite to `seeInField`. * * ```js * I.dontSeeInField('email', 'user@user.com'); // field by name * I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS * ``` * * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator. * @param {string} value value to check. * {--end--} * */ dontSeeInField(field: CodeceptJS.LocatorOrString, value: string): void; /** * Opposite to `see`. Checks that a text is not present on a page. * Use context parameter to narrow down the search. * * ```js * I.dontSee('Login'); // assume we are already logged in. * I.dontSee('Login', '.nav'); // no login inside .nav element * ``` * * @param {string} text which is not present. * @param {CodeceptJS.LocatorOrString} [context] (optional) element located by CSS|XPath|strict locator in which to perfrom search. * {--end--} */ dontSee(text: string, context?: CodeceptJS.LocatorOrString): void; /** * Fills a text field or textarea, after clearing its value, with the given string. * Field is located by name, label, CSS, or XPath. * * ```js * // by label * I.fillField('Email', 'hello@world.com'); * // by name * I.fillField('password', secret('123456')); * // by CSS * I.fillField('form#login input[name=username]', 'John'); * // or by strict locator * I.fillField({css: 'form#login input[name=username]'}, 'John'); * ``` * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator. * @param {string} value text value to fill. * {--end--} * */ fillField(field: CodeceptJS.LocatorOrString, value: string): void; /** * Retrieves a text from an element located by CSS or XPath and returns it to test. * Resumes test execution, so **should be used inside async with `await`** operator. * * ```js * let pin = await I.grabTextFrom('#pin'); * ``` * If multiple elements found returns an array of texts. * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * @returns {Promise<string|string[]>} attribute value * {--end--} * */ grabTextFrom(locator: CodeceptJS.LocatorOrString): Promise<string | string[]>; /** * Retrieves a value from a form element located by CSS or XPath and returns it to test. * Resumes test execution, so **should be used inside async function with `await`** operator. * * ```js * let email = await I.grabValueFrom('input[name=email]'); * ``` * @param {CodeceptJS.LocatorOrString} locator field located by label|name|CSS|XPath|strict locator. * @returns {Promise<string>} attribute value * {--end--} * */ grabValueFrom(locator: CodeceptJS.LocatorOrString): Promise<string>; /** * Verifies that the specified checkbox is checked. * * ```js * I.seeCheckboxIsChecked('Agree'); * I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms * I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'}); * ``` * * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator. * {--end--} * */ seeCheckboxIsChecked(field: CodeceptJS.LocatorOrString): void; /** * Checks that a given Element is visible * Element is located by CSS or XPath. * * ```js * I.seeElement('#modal'); * ``` * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator. * {--end--} * */ seeElement(locator: CodeceptJS.LocatorOrString): void; /** * Checks that the given input field or textarea equals to given value. * For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath. * * ```js * I.seeInField('Username', 'davert'); * I.seeInField({css: 'form textarea'},'Type your comment here'); * I.seeInField('form input[type=hidden]','hidden_value'); * I.seeInField('#searchform input','Search'); * ``` * @param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator. * @param {string} value value to check. * {--end--} * */ seeInField(field: CodeceptJS.LocatorOrString, value: string): void; /** * Checks that a page contains a visible text. * Use context parameter to narrow down the search. * * ```js * I.see('Welcome'); // text welcome on a page * I.see('Welcome', '.content'); // text inside .content div * I.see('Register', {css: 'form.register'}); // use strict locator * ``` * @param {string} text expected on page. * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text. * {--end--} * */ see(text: string, context?: CodeceptJS.LocatorOrString): void; /** * Selects an option in a drop-down select. * Field is searched by label | name | CSS | XPath. * Option is selected by visible text or by value. * * ```js * I.selectOption('Choose Plan', 'Monthly'); // select by label * I.selectOption('subscription', 'Monthly'); // match option by text * I.selectOption('subscription', '0'); // or by value * I.selectOption('//form/select[@name=account]','Premium'); * I.selectOption('form select[name=account]', 'Premium'); * I.selectOption({css: 'form select[name=account]'}, 'Premium'); * ``` * * Provide an array for the second argument to select multiple options. * * ```js * I.selectOption('Which OS do you use?', ['Android', 'iOS']); * ``` * @param {CodeceptJS.LocatorOrString} select field located by label|name|CSS|XPath|strict locator. * @param {string|Array<*>} option visible text or value of option. * {--end--} * * * Supported on only for web testing! */ selectOption(select: CodeceptJS.LocatorOrString, option: string | any[]): void; /** * Waits for element to be present on page (by default waits for 1sec). * Element can be located by CSS or XPath. * * ```js * I.waitForElement('.btn.continue'); * I.waitForElement('.btn.continue', 5); // wait for 5 secs * ``` * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * @param {number} [sec] (optional, `1` by default) time in seconds to wait * {--end--} * */ waitForElement(locator: CodeceptJS.LocatorOrString, sec?: number): void; /** * Waits for an element to become visible on a page (by default waits for 1sec). * Element can be located by CSS or XPath. * * ```js * I.waitForVisible('#popup'); * ``` * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * @param {number} [sec=1] (optional, `1` by default) time in seconds to wait * {--end--} * */ waitForVisible(locator: CodeceptJS.LocatorOrString, sec?: number): void; /** * Waits for an element to be removed or become invisible on a page (by default waits for 1sec). * Element can be located by CSS or XPath. * * ```js * I.waitForInvisible('#popup'); * ``` * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * @param {number} [sec=1] (optional, `1` by default) time in seconds to wait * {--end--} * */ waitForInvisible(locator: CodeceptJS.LocatorOrString, sec?: number): void; /** * Waits for a text to appear (by default waits for 1sec). * Element can be located by CSS or XPath. * Narrow down search results by providing context. * * ```js * I.waitForText('Thank you, form has been submitted'); * I.waitForText('Thank you, form has been submitted', 5, '#modal'); * ``` * * @param {string }text to wait for. * @param {number} [sec=1] (optional, `1` by default) time in seconds to wait * @param {CodeceptJS.LocatorOrString} [context] (optional) element located by CSS|XPath|strict locator. * {--end--} * */ waitForText(text: string, sec?: number, context?: CodeceptJS.LocatorOrString): void; } class FileSystem { /** * Enters a directory In local filesystem. * Starts from a current directory * @param {string} openPath */ amInPath(openPath: string): void; /** * Writes test to file * @param {string} name * @param {string} text */ writeToFile(name: string, text: string): void; /** * Checks that file exists * @param {string} name */ seeFile(name: string): void; /** * Checks that file found by `seeFile` includes a text. * @param {string} text * @param {string} encoding */ seeInThisFile(text: string, encoding: string): void; /** * Checks that file found by `seeFile` doesn't include text. * @param {string} text * @param {string} encoding */ dontSeeInThisFile(text: string, encoding: string): void; /** * Checks that contents of file found by `seeFile` equal to text. * @param {string} text * @param {string} encoding */ seeFileContentsEqual(text: string, encoding: string): void; /** * Checks that contents of file found by `seeFile` doesn't equal to text. * @param {string} text * @param {string} encoding */ dontSeeFileContentsEqual(text: string, encoding: string): void; } class GraphQL { /** * Executes query via axios call * * @param {object} request */ _executeQuery(request: any): void; /** * Prepares request for axios call * * @param {object} operation * @param {object} headers */ _prepareGraphQLRequest(operation: any, headers: any): void; /** * Send query to GraphQL endpoint over http. * Returns a response as a promise. * * ```js * * const response = await I.sendQuery('{ users { name email }}'); * // with variables * const response = await I.sendQuery( * 'query getUser($id: ID) { user(id: $id) { name email }}', * { id: 1 }, * ) * const user = response.data.data; * ``` * * @param {String} query * @param {object} variables that may go along with the query * @param {object} options are additional query options * @param {object} headers */ sendQuery(query: string, variables: any, options: any, headers: any): void; /** * Send query to GraphQL endpoint over http * * ```js * I.sendMutation(` * mutation createUser($user: UserInput!) { * createUser(user: $user) { * id * name * email * } * } * `, * { user: { * name: 'John Doe', * email: 'john@xmail.com' * } * }, * }); * ``` * * @param {String} mutation * @param {object} variables that may go along with the mutation * @param {object} options are additional query options * @param {object} headers */ sendMutation(mutation: string, variables: any, options: any, headers: any): void; } class GraphQLDataFactory { /** * Generates a new record using factory, sends a GraphQL mutation to store it. * * ```js * // create a user * I.mutateData('createUser'); * // create user with defined email * // and receive it when inside async function * const user = await I.mutateData('createUser', { email: 'user@user.com'}); * ``` * * @param {string} operation to be performed * @param {*} params predefined parameters */ mutateData(operation: string, params: any): void; /** * Generates bunch of records and sends multiple GraphQL mutation requests to store them. * * ```js * // create 3 users * I.mutateMultiple('createUser', 3); * * // create 3 users of same age * I.mutateMultiple('createUser', 3, { age: 25 }); * ``` * * @param {string} operation * @param {number} times * @param {*} params */ mutateMultiple(operation: string, times: number, params: any): void; /** * Executes request to create a record to the GraphQL endpoint. * Can be replaced from a custom helper. * * @param {string} operation * @param {*} variables to be sent along with the query */ _requestCreate(operation: string, variables: any): void; /** * Executes request to delete a record to the GraphQL endpoint. * Can be replaced from a custom helper. * * @param {string} operation * @param {*} data of the record to be deleted. */ _requestDelete(operation: string, data: any): void; } class MockRequest { /** * Starts mocking of http requests. * Used by mockRequest method to automatically start * mocking requests. * * @param {*} title */ startMocking(title?: any): void; /** * Creates a polly instance by registering puppeteer adapter with the instance * * @param {*} title */ _connectPuppeteer(title: any): void; /** * Creates polly object in the browser window context using xhr and fetch adapters, * after loading PollyJs and adapter scripts. * * @param {*} title */ _connectWebDriver(title: any): void; /** * Mock response status * * ```js * I.mockRequest('GET', '/api/users', 200); * I.mockRequest('ANY', '/secretsRoutes/*', 403); * I.mockRequest('POST', '/secrets', { secrets: 'fakeSecrets' }); * I.mockRequest('GET', '/api/users/1', 404, 'User not found'); * ``` * * Multiple requests * * ```js * I.mockRequest('GET', ['/secrets', '/v2/secrets'], 403); * ``` * @param {string} method request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`. * @param {string|string[]} oneOrMoreUrls url(s) to mock. Can be exact URL, a pattern, or an array of URLs. * @param {number|string|object} dataOrStatusCode status code when number provided. A response body otherwise * @param {string|object} additionalData response body when a status code is set by previous parameter. * */ mockRequest(method: string, oneOrMoreUrls: string | string[], dataOrStatusCode: number | string | any, additionalData: string | any): void; /** * Starts mocking if it's not started yet. */ _checkAndStartMocking(): void; /** * Stops mocking requests. */ stopMocking(): void; } class Nightmare { /** * Get HAR * * ```js * let har = await I.grabHAR(); * fs.writeFileSync('sample.har', JSON.stringify({log: har})); * ``` */ grabHAR(): void; /** * Locate elements by different locator types, including strict locator. * Should be used in custom helpers. * * This method return promise with array of IDs of found elements. * Actual elements can be accessed inside `evaluate` by using `codeceptjs.fetchElement()` * client-side function: * * ```js * // get an inner text of an element * * let browser = this.helpers['Nightmare'].browser; * let value = this.helpers['Nightmare']._locate({name: 'password'}).then(function(els) { * return browser.evaluate(function(el) { * return codeceptjs.fetchElement(el).value; * }, els[0]); * }); * ``` */ _locate(): void; /** * Add a header override for all HTTP requests. If header is undefined, the header overrides will be reset. * * ```js * I.haveHeader('x-my-custom-header', 'some value'); * I.haveHeader(); // clear headers * ``` */ haveHeader(): void; /** * Opens a web page in a browser. Requires relative or absolute url. * If url starts with `/`, opens a web page of a site defined in `url` config parameter. * * ```js * I.amOnPage('/'); // opens main page of website * I.amOnPage('https://github.com'); // opens github * I.amOnPage('/login'); // opens a login page * ``` * * @param {string} url url path or global url. * {--end--} * @param {?object} headers list of request headers can be passed * */ amOnPage(url: string, headers: any): void; /** * Checks that title contains text. * * ```js * I.seeInTitle('Home Page'); * ``` * * @param {string} text text value to check. * {--end--} */ seeInTitle(text: string): void; /** * Checks that title does not contain text. * * ```js * I.dontSeeInTitle('Error'); * ``` * * @param {string} text value to check. * {--end--} */ dontSeeInTitle(text: string): void; /** * Retrieves a page title and returns it to test. * Resumes test execution, so **should be used inside async with `await`** operator. * * ```js * let title = await I.grabTitle(); * ``` * * @returns {Promise<string>} title * {--end--} */ grabTitle(): Promise<string>; /** * Get current URL from browser. * Resumes test execution, so should be used inside an async function. * * ```js * let url = await I.grabCurrentUrl(); * console.log(`Current URL is [${url}]`); * ``` * * @returns {Promise<string>} current URL * {--end--} */ grabCurrentUrl(): Promise<string>; /** * Checks that current url contains a provided fragment. * * ```js * I.seeInCurrentUrl('/register'); // we are on registration page * ``` * * @param {string} url a fragment to check * {--end--} */ seeInCurrentUrl(url: string): void; /** * Checks that current url does not contain a provided fragment. * * @param {string} url value to check. * {--end--} */ dontSeeInCurrentUrl(url: string): void; /** * Checks that current url is equal to provided one. * If a relative url provided, a configured url will be prepended to it. * So both examples will work: * * ```js * I.seeCurrentUrlEquals('/register'); * I.seeCurrentUrlEquals('http://my.site.com/register'); * ``` * * @param {string} url value to check. * {--end--} */ seeCurrentUrlEquals(url: string): void; /** * Checks that current url is not equal to provided one. * If a relative url provided, a configured url will be prepended to it. * * ```js * I.dontSeeCurrentUrlEquals('/login'); // relative url are ok * I.dontSeeCurrentUrlEquals('http://mysite.com/login'); // absolute urls are also ok * ``` * * @param {string} url value to check. * {--end--} */ dontSeeCurrentUrlEquals(url: string): void; /** * Checks that a page contains a visible text. * Use context parameter to narrow down the search. * * ```js * I.see('Welcome'); // text welcome on a page * I.see('Welcome', '.content'); // text inside .content div * I.see('Register', {css: 'form.register'}); // use strict locator * ``` * @param {string} text expected on page. * @param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text. * {--end--} */ see(text: string, context?: CodeceptJS.LocatorOrString): void; /** * Opposite to `see`. Checks that a text is not present on a page. * Use context parameter to narrow down the search. * * ```js * I.dontSee('Login'); // assume we are already logged in. * I.dontSee('Login', '.nav'); // no login inside .nav element * ``` * * @param {string} text which is not present. * @param {CodeceptJS.LocatorOrString} [context] (optional) element located by CSS|XPath|strict locator in which to perfrom search. * {--end--} */ dontSee(text: string, context?: CodeceptJS.LocatorOrString): void; /** * Checks that a given Element is visible * Element is located by CSS or XPath. * * ```js * I.seeElement('#modal'); * ``` * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|strict locator. * {--end--} */ seeElement(locator: CodeceptJS.LocatorOrString): void; /** * Opposite to `seeElement`. Checks that element is not visible (or in DOM) * * ```js * I.dontSeeElement('.modal'); // modal is not shown * ``` * * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|Strict locator. * {--end--} */ dontSeeElement(locator: CodeceptJS.LocatorOrString): void; /** * Checks that a given Element is present in the DOM * Element is located by CSS or XPath. * * ```js * I.seeElementInDOM('#modal'); * ``` * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * {--end--} */ seeElementInDOM(locator: CodeceptJS.LocatorOrString): void; /** * Opposite to `seeElementInDOM`. Checks that element is not on page. * * ```js * I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not * ``` * * @param {CodeceptJS.LocatorOrString} locator located by CSS|XPath|Strict locator. * {--end--} */ dontSeeElementInDOM(locator: CodeceptJS.LocatorOrString): void; /** * Checks that the current page contains the given string in its raw source code. * * ```js * I.seeInSource('<h1>Green eggs &amp; ham</h1>'); * ``` * @param {string} text value to check. * {--end--} */ seeInSource(text: string): void; /** * Checks that the current page does not contains the given string in its raw source code. * * ```js * I.dontSeeInSource('<!--'); // no comments in source * ``` * * @param {string} value to check. * {--end--} */ dontSeeInSource(value: string): void; /** * Asserts that an element appears a given number of times in the DOM. * Element is located by label or name or CSS or XPath. * * * ```js * I.seeNumberOfElements('#submitBtn', 1); * ``` * * @param {CodeceptJS.LocatorOrString} locator element located by CSS|XPath|strict locator. * @param {number} num number of elements. * {--end--} */ seeNumberOfElements(locator: CodeceptJS.LocatorOrString, num: number): void;