sgapps.io-testing-platform
TypeScript icon, indicating that this package has built-in type declarations

1.1.17 • Public • Published

🐙 SGApps.IO Testing Platform

Easy way to build testing scenarios

🐙 SGApps.IO Testing Platform

easy and intuitive functional testing based on puppeteer

Emulation mode

Testing Platform based on puppeteer and puppeteer-firefox it uses these modules for emulation part.

Offers possibility to define a scenario, if you want you may fork testing scenario and build another one

In single row you may run same testing scenario under different Browsers and environments.

  • 📳 Available emulation for 71 devices
  • You may run using Chrome 🌐 or Firefox Browsers 🦊
  • 🍽 You can fork a testing Scenario and make other with chages
  • Easily to use Expect and Assert functionalities.
  • You can easily create functionality groups and subgroups in your test
  • Support for working with file Inputs
  • 🆒 IntelliSense Support

Why to use, describing concept

Reason for creating this library was to build a very friendly environment for functional testing, that can be easily installed without additional configurations.

Concept is based building easy to read intuitive scenarios that can be understood by anyone.

When You have 2 Testing Scenarios that are the same under specific step, you can fork them on any step, and the fork represents a clone a scenario until that step.

Example

let Scenario = new TestScenario();

Scenario
	.isHeadLess(true)
	.isVerbose(false) // enable to view detailed step logs
	.getPage()
	.goto('http://google.com', { waitUntil: "domcontentloaded" })
	.wait(1000)
	.describe('Functionality Group')
		.goto('http://yahoo.com', { waitUntil: "domcontentloaded" })
		.wait(1000)
		.it(async (done, evaluate, assert, expect) => {
			let title = await evaluate('document.title');

			expect(title).to().be().a("string");

			assert.isNotNull(title);
			done();
		}, "Example of checking block » checking title")
		.goto('http://bing.com', { waitUntil: "domcontentloaded" })
		.wait(1000)
		.goto('http://jsdoc.app', { waitUntil: "domcontentloaded" })

		.describe('Functionality SubGroup')
			.goto('https://sgapps.io', { waitUntil: "domcontentloaded" })
			.wait(1000)
			.goto('https://github.com', { waitUntil: "domcontentloaded" })
			.wait(1000)
			.goto('https://npmjs.com', { waitUntil: "domcontentloaded" })
			.wait(1000)
		.describeClose()
		.wait(1000)
	.describeClose()
	.close();

ScreenShots

Testing multiple devices with same test scenario

Run Same Scenario on multiple devices

Testing in Verbose mode - view all steps

Run Same Scenario on multiple devices

Examples

API

Table of Contents

TestingScenario

Type: function ()


isHeadLess

Indicates if Browser should run in headless mode

Type: function (isHeadLess): TestingScenario

  • isHeadLess Boolean? if parameter is not passed function will return current isHeadLess value

isVerbose

Indicates if tests should run in verbose mode

Type: function (isVerbose, isHeadLess): TestingScenario

  • isVerbose
  • isHeadLess Boolean? if parameter is not passed function will return current isVerbose value

ScenarioName

Specify or get Current Scenario Name

Type: function (name): TestingScenario

  • name String? if parameter is not passed function will return current name

_getPage

Select from instance a page with specific index

Type: function (instance, index, PuppeteerInstance)

  • instance
  • index (Number | "next" | "prev" | String) Page's index or 'next', 'prev', 'last' or 'first' or pages label (optional, default (instance.currentPage._getLabelName||0))
  • PuppeteerInstance

getPage

Select from instance a page with specific index

Type: function (index): TestingScenario

  • index (Number | "next" | "prev" | String) Page's index or 'next', 'prev', 'last' or 'first' or pages label (optional, default (instance.currentPage._getLabelName||0))

setViewport

Applying specific viewport for device

Type: function (options): TestingScenario


goto

Opens an URL

Type: function (url, options): TestingScenario


wait

wait a priod of specified miliseconds

Type: function (timeMs): TestingScenario

  • timeMs Number number of miliseconds

pageEventWait

Wait until a page will reach an event

Type: function (eventName, handler): TestingScenario

  • eventName ("close" | "console" | "dialog" | "domcontentloaded" | "error" | "frameattached" | "framedetached" | "framenavigated" | "load" | "metrics" | "pageerror" | "popup" | "request" | "requestfailed" | "requestfinished" | "response" | "workercreated" | "workerdestroyed")
  • handler function (any): Promise? a function that can execute specific operations with data obtained on event

waitForFileChooser

add a files to input[type="file"] in instance's page

Type: function (files, selector): TestingScenario

  • files Array<String> list of file paths to be added to input
  • selector String CSS Selector used to identify input[type="file"]

waitForFunction

wait until browser will pageFunction will return true value

Type: function (pageFunction, options): TestingScenario


waitForNavigation

wait specific navigation state

Type: function (options): TestingScenario


waitForSelector

Wait for the selector to appear in page. If at the moment of calling the method the selector already exists, the method will return immediately. If the selector doesn't appear after the timeout milliseconds of waiting, the function will throw.

Type: function (selector, options): TestingScenario


waitForXPath

Wait for the xpath to appear in page. If at the moment of calling the method the xpath already exists, the method will return immediately. If the xpath doesn't appear after the timeout milliseconds of waiting, the function will throw.

Type: function (xpath, options): TestingScenario


userAgent

Handle User agent of instance

Type: function (handler): TestingScenario

  • handler function (userAgent): Promise if parameter is present will handle UserAgent value

clearPermissionOverrides

Clears all permission overrides for the browser context.

Type: function (): TestingScenario


overridePermissions

Override permissions for the browser context.

Type: function (origin, permissions): TestingScenario


pageClose

Close a page from instance

Type: function (options, index): TestingScenario


pageSetLabel

Set page label, for easier selecting using .getPage(label)

Type: function (label): TestingScenario

  • label String label that will be set on current page

pageReload

Close a page from instance

Type: function (index, options): TestingScenario


pageContent

Handle User agent of instance

Type: function (handler)

  • handler function (userAgent) if parameter is present will handle UserAgent value

clickOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to click in the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector, options): TestingScenario


typeOnSelector

Sends a keydown, keypress/input, and keyup event for each character in the text.

Type: function (selector, text, options): TestingScenario

  • selector String A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
  • text String A text to type into a focused element.
  • options TestingScenarioTypeOnSelectorOptions Optional parameters

tapOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.touchscreen to tap in the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector to search for element to tap. If there are multiple elements satisfying the selector, the first will be tapped.

focusOnSelector

This method fetches an element with selector and focuses it. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector of an element to focus. If there are multiple elements satisfying the selector, the first will be focused.

hoverOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to hover over the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.

evaluate

If the function passed to the page.evaluate returns a non-Serializable value, then page.evaluate resolves to undefined. DevTools Protocol also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity, and bigint literals.

Type: function (pageFunction, handler, variables, meta): TestingScenario

  • pageFunction (function (Object): any | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction
  • variables Object context passed to pageFunction (optional, default {})
  • meta

evaluateOnSelectorAll

If the function passed to the page.evaluate returns a non-Serializable value, then page.evaluate resolves to undefined. DevTools Protocol also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity, and bigint literals.

Type: function (selector, pageFunction, handler, value): TestingScenario

  • selector String A selector for an selecting element
  • pageFunction (Function | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction, this parameter can be skipped
  • value any? context passed to pageFunction

Examples:

Example usage of string pageFunction.

test.evaluateOnSelectorAll('a[href]', 'element.click()');

Example usage of string pageFunction with handler

test.evaluateOnSelectorAll('input[type="text"]', 'element.value', function (value) {
    console.log(value);
});

Example usage of string pageFunction and context

test.evaluateOnSelectorAll('input[type="email"]', 'element.value = value', 'user.email@example.com');

Example usage of string pageFunction with handler and context

test.evaluateOnSelectorAll('input[type="checkbox"]', 'element.value = value; element.checked', function (isChecked) {
    console.log('isChecked')
} 'On');

Example usage of pageFunction.

test.evaluateOnSelectorAll('a[href]', function (element) { element.click() });

Example usage of pageFunction with handler

test.evaluateOnSelectorAll(
    'input[type="text"]',
    function (element) {
        return element.value;
    }, function (value) {
        console.log(value);
    }
);

Example usage of pageFunction and context

test.evaluateOnSelectorAll(
    'input[type="email"]',
    function (element, value) {
        element.value = value;
    },
    'user.email@example.com'
);

Example usage of pageFunction with handler and context

test.evaluateOnSelectorAll(
    'input[type="checkbox"]',
    function (element, value) {
        element.value = value;
        return element.checked;
    },
    function (isChecked) {
        console.log('isChecked');
    },
    'On'
);

evaluateOnSelectorOnlyOne

Similar with evaluateOnSelectorAll but throws an error if detected more than one element

Type: function (selector, pageFunction, handler, value): TestingScenario

  • selector String A selector for an selecting element
  • pageFunction (Function | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction, this parameter can be skipped
  • value any? context passed to pageFunction

pageEmulate

Emulates specific configuration of device

Type: function (config): TestingScenario


message

Add a specific message to last operation

Type: function (message): TestingScenario


operationLabels

Add labels to operation

Type: function (labels): TestingScenario


operationLabelsRemove

Remove labels from operation

Type: function (labels): TestingScenario


deactivate

activate or deactivate operation by adding or removing operation label "__Deactivated"

Type: function (status): TestingScenario

  • status Boolean if status is true than operation will be deactivated

describe

Describe a section of testing scenario

Type: function (message): TestingScenario

  • message String the message that will describe the Scenario Section

describeClose

Close Describe section of testing scenario

Type: function (message): TestingScenario

  • message String message on succeed

group

Describe a group of testing scenario similar to TestingScenario.describe

Type: function (message): TestingScenario

  • message String the name of group the Scenario Section

groupClose

Close Group section of testing scenario

Type: function (message): TestingScenario

  • message String message on succeed

injectScenario

Inject other testing Scenario on specific step

Type: function (Scenario)


it

Assert some functionality from test

Type: function (handler, message): TestingScenario

Example:

test.goto('http://example.com')
   .describe('Testing Page')
       .describe('Testing Title')
           .it((done, evaluate, assert, expect) => {
               let title = evaluate('document.title');
               expect(title).to().be().eq('Page Title', 'default page title - message shown on error');
               done();
           })
       .describeClose()
       // check if using some browsers api
       .describe('Testing Title')
           .it(async (done, evaluate, assert, expect) => {
               let title = await evaluate(
                   () => {
                       return document.title
                   }
               );
               assert.isNotNull(title);
               done();
           })
       .describeClose()
   .describeClose()

fork

Timestamp The timestamp when the metrics sample was taken. Documents Number of documents in the page. Frames Number of frames in the page. JSEventListeners Number of events in the page. Nodes Number of DOM nodes in the page. LayoutCount Total number of full or partial page layout. RecalcStyleCount Total number of page style recalculations. LayoutDuration Combined durations of all page layouts. RecalcStyleDuration Combined duration of all page style recalculations. ScriptDuration Combined duration of JavaScript execution. TaskDuration Combined duration of all tasks performed by the browser. JSHeapUsedSize Used JavaScript heap size. JSHeapTotalSize Total JavaScript heap size.

Type: function ()


fork

Fork or Clone Testing Scenario

Type: function ()


close

Close device Instance

Type: function ()


run

Run your tests under specific environment

Type: function (device, device2, device3, device4, device5, device6, device7, device8, otherDevices, devices)


TestingScenarioSetViewportOptions

Type: Object

  • width Number? device width in pixels. Default value is 1920
  • height Number? device height in pixels. Default value is 1080
  • deviceScaleFactor Number? Device Scale Factor. Default value is 1
  • hasTouch Boolean? Emulate touch instead of click. Default value is false
  • isLandscape Boolean? is device in landscape mode. Default value is true
  • isMobile isMobile? is mobile device. Default value is false

TestingScenarioGotoOptions

Type: Object

  • waitUntil ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")? When to consider navigation succeeded, defaults to 'load'. Given an array of event strings, navigation is considered to be successful after all events have been fired. Default value is 'domcontentloaded'
  • timeout Number? Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods. Default value is 30
  • referer String? Referer header value. If provided it will take preference over the referer header value set by page.setExtraHTTPHeaders().

TestingScenarioWaitForFunctionOptions

Type: Object

  • polling ("raf" | "polling" | "mutation")? An interval at which the pageFunction is executed, defaults to 'raf'. If polling is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling is a string, then it can be one of the following values:- raf - to constantly execute pageFunction in requestAnimationFrame callback. This is the tightest polling mode which is suitable to observe styling changes.
    • mutation - to execute pageFunction on every DOM mutation.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

TestingScenarioWaitForNavigationOptions

Type: Object

  • waitUntil ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")? When to consider navigation succeeded, defaults to 'load'. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:- load - consider navigation to be finished when the load event is fired.
    • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
    • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
    • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

TestingScenarioWaitForSelectorOptions

Type: Object

  • visible Boolean? wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.
  • hidden Boolean? wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

TestingScenarioWaitForXPathOptions

Type: Object

  • visible Boolean? wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.
  • hidden Boolean? wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

TestingScenarioInstancePermissions

Type: ("geolocation" | "midi" | "midi-sysex" | "notifications" | "push" | "camera" | "microphone" | "background-sync" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "accessibility-events" | "clipboard-read" | "clipboard-write" | "payment-handler")


TestingScenarioPageCloseOptions

Type: Object

  • runBeforeUnload Boolean Defaults to false. Whether to run the before unload page handlers.

TestingScenarioPageReloadOptions

Type: Object

  • timeout Number Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
  • waitUntil (TestingScenarioPageReloadOptionsWaitUntil | Array<TestingScenarioPageReloadOptionsWaitUntil>) When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:- load - consider navigation to be finished when the load event is fired.
    • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
    • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
    • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

TestingScenarioPageReloadOptionsWaitUntil

When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:

  • load - consider navigation to be finished when the load event is fired.
  • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
  • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
  • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

Type: ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")


TestingScenarioClickOnSelectorOptions

Type: Object

  • button ("left" | "right" | "middle") Defaults to left.
  • clickCount Number defaults to 1.
  • delay Number Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.

TestingScenarioTypeOnSelectorOptions

Type: Object

  • delay Number Time to wait between key presses in milliseconds. Defaults to 0.

TestingScenarioPageEmulateConfigViewport

Type: Object

  • width Number page width in pixels.
  • height Number page height in pixels.
  • deviceScaleFactor Number Specify device scale factor (can be thought of as dpr). Defaults to 1.
  • isMobile Boolean Whether the meta viewport tag is taken into account. Defaults to false.
  • hasTouch Boolean Specifies if viewport supports touch events. Defaults to false
  • isLandscape Boolean Specifies if viewport is in landscape mode. Defaults to false.

TestingScenarioPageEmulateDeviceName

Type: ("Blackberry PlayBook" | "Blackberry PlayBook landscape" | "BlackBerry Z30" | "BlackBerry Z30 landscape" | "Galaxy Note 3" | "Galaxy Note 3 landscape" | "Galaxy Note II" | "Galaxy Note II landscape" | "Galaxy S III" | "Galaxy S III landscape" | "Galaxy S5" | "Galaxy S5 landscape" | "iPad" | "iPad landscape" | "iPad Mini" | "iPad Mini landscape" | "iPad Pro" | "iPad Pro landscape" | "iPhone 4" | "iPhone 4 landscape" | "iPhone 5" | "iPhone 5 landscape" | "iPhone 6" | "iPhone 6 landscape" | "iPhone 6 Plus" | "iPhone 6 Plus landscape" | "iPhone 7" | "iPhone 7 landscape" | "iPhone 7 Plus" | "iPhone 7 Plus landscape" | "iPhone 8" | "iPhone 8 landscape" | "iPhone 8 Plus" | "iPhone 8 Plus landscape" | "iPhone SE" | "iPhone SE landscape" | "iPhone X" | "iPhone X landscape" | "iPhone XR" | "iPhone XR landscape" | "JioPhone 2" | "JioPhone 2 landscape" | "Kindle Fire HDX" | "Kindle Fire HDX landscape" | "LG Optimus L70" | "LG Optimus L70 landscape" | "Microsoft Lumia 550" | "Microsoft Lumia 950" | "Microsoft Lumia 950 landscape" | "Nexus 10" | "Nexus 10 landscape" | "Nexus 4" | "Nexus 4 landscape" | "Nexus 5" | "Nexus 5 landscape" | "Nexus 5X" | "Nexus 5X landscape" | "Nexus 6" | "Nexus 6 landscape" | "Nexus 6P" | "Nexus 6P landscape" | "Nexus 7" | "Nexus 7 landscape" | "Nokia Lumia 520" | "Nokia Lumia 520 landscape" | "Nokia N9" | "Nokia N9 landscape" | "Pixel 2" | "Pixel 2 landscape" | "Pixel 2 XL" | "Pixel 2 XL landscape")


TestingScenarioPageEmulateDeviceConfig

Type: Object


TestingScenarioPageEmulateCallbackResult

Type: Object


TestingScenarioPageEmulateCallback

Type: Function


TestingScenarioPageEmulateDeviceConfigOptions

Type: Object

  • ignoreHTTPSErrors boolean Whether to ignore HTTPS errors during navigation. Defaults to false.
  • headless boolean Whether to run browser in headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to true unless the devtools option is true.
  • executablePath string Path to a Chromium or Chrome executable to run instead of the bundled Chromium. If executablePath is a relative path, then it is resolved relative to current working directory.
  • slowMo number Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.
  • defaultViewport TestingScenarioSetViewportOptions Sets a consistent viewport for each page. Defaults to an 800x600 viewport. null disables the default viewport.
  • args Array<String> Additional arguments to pass to the browser instance. The list of Chromium flags can be found here.
  • ignoreDefaultArgs (boolean | Array<String>) If true, then do not use puppeteer.defaultArgs(). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to false.
  • handleSIGINT boolean Close the browser process on Ctrl-C. Defaults to true.
  • handleSIGTERM boolean Close the browser process on SIGTERM. Defaults to true.
  • handleSIGHUP boolean Close the browser process on SIGHUP. Defaults to true.
  • timeout number Maximum time in milliseconds to wait for the browser instance to start. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
  • dumpio boolean Whether to pipe the browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.
  • userDataDir string Path to a User Data Directory.
  • env Object Specify environment variables that will be visible to the browser. Defaults to process.env.
  • devtools boolean Whether to auto-open a DevTools panel for each tab. If this option is true, the headless option will be set false.
  • pipe boolean Connects to the browser over a pipe instead of a WebSocket. Defaults to false.

TestingScenarioPageEmulateConfig

Type: Object


TestingScenarioItHandlerCallback

Type: Function

  • done Function function that should be executed when check id done
  • evaluate Function function executed in Browser's context that return an result

assert

Type: function (expectValue, value, message, isNegated, comparingFunction)

  • expectValue any
  • value any
  • message String
  • isNegated
  • comparingFunction

expect

Type: function (value)

  • value any

to

Type: function (): expectTo


expectTo

Type: function (value)

  • value

be

Type: function (): expectToBe


expectToBe

Type: function (value)

  • value

ExpectedType

Type: ("string" | "number" | "boolean" | "function" | "object" | "array" | "null" | "NaN" | "NUMBER_FINITE" | "NUMBER_SAFE_INTEGER" | "INFINITY" | "POSITIVE_INFINITY" | "NEGATIVE_INFINITY")


Expect.to.be.a


Expect.to.be.notA


Expect.to.be.instanceOf

  • instanceType (Object | Error | any)
  • message String what to show wen conditions are not meet

expectValueDescribe

Type: function (value)

  • value

TestingScenario

Type: function ()


_getPage

Select from instance a page with specific index

Type: function (instance, index, PuppeteerInstance)

  • instance
  • index (Number | "next" | "prev" | String) Page's index or 'next', 'prev', 'last' or 'first' or pages label (optional, default (instance.currentPage._getLabelName||0))
  • PuppeteerInstance

getPage

Select from instance a page with specific index

Type: function (index): TestingScenario

  • index (Number | "next" | "prev" | String) Page's index or 'next', 'prev', 'last' or 'first' or pages label (optional, default (instance.currentPage._getLabelName||0))

setViewport

Type: function (options)

  • options

  • width Number? device width in pixels

  • height Number? device height in pixels

  • deviceScaleFactor Number? Device Scale Factor

  • hasTouch Boolean? Emulate touch instead of click

  • isLandscape Boolean? is device in landscape mode

  • isMobile isMobile? is mobile device


setViewport

Applying specific viewport for device

Type: function (options): TestingScenario

  • options TestingScenarioSetViewportOptions

goto

Type: function (url, options)

  • url

  • options

  • waitUntil ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")? When to consider navigation succeeded, defaults to 'load'. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:

  • timeout Number? Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the page.setDefaultNavigationTimeout(timeout) or page.setDefaultTimeout(timeout) methods.

  • referer String? Referer header value. If provided it will take preference over the referer header value set by page.setExtraHTTPHeaders().


goto

Opens an URL

Type: function (url, options): TestingScenario

  • url String URL to navigate page to. The url should include scheme, e.g. https://.
  • options TestingScenarioGotoOptions? Navigation parameters

wait

wait a priod of specified miliseconds

Type: function (timeMs): TestingScenario

  • timeMs Number number of miliseconds

pageEventWait

Wait until a page will reach an event

Type: function (eventName, handler): TestingScenario

  • eventName ("close" | "console" | "dialog" | "domcontentloaded" | "error" | "frameattached" | "framedetached" | "framenavigated" | "load" | "metrics" | "pageerror" | "popup" | "request" | "requestfailed" | "requestfinished" | "response" | "workercreated" | "workerdestroyed")
  • handler function (any): Promise? a function that can execute specific operations with data obtained on event

waitForFileChooser

add a files to input[type="file"] in instance's page

Type: function (files, selector): TestingScenario

  • files Array<String> list of file paths to be added to input
  • selector String CSS Selector used to identify input[type="file"]

waitForFunction

Type: function (pageFunction, options)

  • pageFunction

  • options

  • polling ("raf" | "polling" | "mutation")? An interval at which the pageFunction is executed, defaults to raf. If polling is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling is a string, then it can be one of the following values:- raf - to constantly execute pageFunction in requestAnimationFrame callback. This is the tightest polling mode which is suitable to observe styling changes.

    • mutation - to execute pageFunction on every DOM mutation.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


waitForFunction

wait until browser will pageFunction will return true value

Type: function (pageFunction, options): TestingScenario

  • pageFunction (String | Function) Function to be evaluated in browser context
  • options TestingScenarioWaitForFunctionOptions Optional waiting parameters

waitForNavigation

wait specific navigation state

Type: function (options): TestingScenario

  • options TestingScenarioWaitForNavigationOptions Optional waiting parameters

waitForNavigation

Type: function (options)

  • options

  • waitUntil ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")? When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:- load - consider navigation to be finished when the load event is fired.

    • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
    • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
    • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


waitForSelector

Wait for the selector to appear in page. If at the moment of calling the method the selector already exists, the method will return immediately. If the selector doesn't appear after the timeout milliseconds of waiting, the function will throw.

Type: function (selector, options): TestingScenario

  • selector String A selector of an element to wait for
  • options TestingScenarioWaitForSelectorOptions Optional waiting parameters

waitForSelector

Type: function (selector, options)

  • selector

  • options

  • visible Boolean? wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.

  • hidden Boolean? wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.

  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


waitForXPath

Type: function (xpath, options)

  • xpath

  • options

  • visible Boolean? wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.

  • hidden Boolean? wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.

  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


waitForXPath

Wait for the xpath to appear in page. If at the moment of calling the method the xpath already exists, the method will return immediately. If the xpath doesn't appear after the timeout milliseconds of waiting, the function will throw.

Type: function (xpath, options): TestingScenario

  • xpath String A xpath of an element to wait for
  • options TestingScenarioWaitForXPathOptions Optional waiting parameters

waitForXPath

Type: function (xpath, options)

  • xpath

  • options

  • visible Boolean? wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.

  • hidden Boolean? wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.

  • timeout Number? maximum time to wait for in milliseconds, Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


waitForXPath

Wait for the xpath to appear in page. If at the moment of calling the method the xpath already exists, the method will return immediately. If the xpath doesn't appear after the timeout milliseconds of waiting, the function will throw.

Type: function (xpath, options): TestingScenario

  • xpath String A xpath of an element to wait for
  • options TestingScenarioWaitForXPathOptions Optional waiting parameters

userAgent

Handle User agent of instance

Type: function (handler): TestingScenario

  • handler function (userAgent): Promise if parameter is present will handle UserAgent value

clearPermissionOverrides

Clears all permission overrides for the browser context.

Type: function (): TestingScenario


overridePermissions

Override permissions for the browser context.

Type: function (origin, permissions): TestingScenario


pageClose

Type: function (options, index)

  • options

  • index

  • runBeforeUnload Boolean Defaults to false. Whether to run the before unload page handlers.


pageClose

Close a page from instance

Type: function (options, index): TestingScenario

  • options TestingScenarioPageCloseOptions? set of options
  • index String? page's index

pageSetLabel

Set page label, for easier selecting using .getPage(label)

Type: function (label): TestingScenario

  • label String label that will be set on current page

pageReload

Close a page from instance

Type: function (index, options): TestingScenario

  • index String page's index
  • options TestingScenarioPageReloadOptions set of options

pageReload

Type: function (index, options)

  • index

  • options

  • timeout Number Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.

  • waitUntil (TestingScenarioPageReloadOptionsWaitUntil | Array<TestingScenarioPageReloadOptionsWaitUntil>) When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:- load - consider navigation to be finished when the load event is fired.

    • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
    • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
    • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

pageContent

Handle User agent of instance

Type: function (handler)

  • handler function (userAgent) if parameter is present will handle UserAgent value

clickOnSelector

Type: function (selector, options)

  • selector

  • options

  • button ("left" | "right" | "middle") Defaults to left.

  • clickCount Number defaults to 1.

  • delay Number Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.


clickOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to click in the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector, options): TestingScenario

  • selector String A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
  • options TestingScenarioClickOnSelectorOptions Optional parameters

typeOnSelector

Type: function (selector, text, options)

  • selector

  • text

  • options

  • delay Number Time to wait between key presses in milliseconds. Defaults to 0.


typeOnSelector

Sends a keydown, keypress/input, and keyup event for each character in the text.

Type: function (selector, text, options): TestingScenario

  • selector String A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
  • text String A text to type into a focused element.
  • options TestingScenarioTypeOnSelectorOptions Optional parameters

tapOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.touchscreen to tap in the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector to search for element to tap. If there are multiple elements satisfying the selector, the first will be tapped.

focusOnSelector

This method fetches an element with selector and focuses it. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector of an element to focus. If there are multiple elements satisfying the selector, the first will be focused.

hoverOnSelector

This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to hover over the center of the element. If there's no element matching selector, the method throws an error.

Type: function (selector): TestingScenario

  • selector String A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.

evaluate

If the function passed to the page.evaluate returns a non-Serializable value, then page.evaluate resolves to undefined. DevTools Protocol also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity, and bigint literals.

Type: function (pageFunction, handler, variables): TestingScenario

  • pageFunction (function (Object): any | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction
  • variables Object context passed to pageFunction (optional, default {})

evaluateOnSelectorAll

If the function passed to the page.evaluate returns a non-Serializable value, then page.evaluate resolves to undefined. DevTools Protocol also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity, and bigint literals.

Type: function (selector, pageFunction, handler, value): TestingScenario

  • selector String A selector for an selecting element
  • pageFunction (Function | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction, this parameter can be skipped
  • value any? context passed to pageFunction

Examples:

Example usage of string pageFunction.

test.evaluateOnSelector('a[href]', 'element.click()');

Example usage of string pageFunction with handler

test.evaluateOnSelector('input[type="text"]', 'element.value', function (value) {
    console.log(value);
});

Example usage of string pageFunction and context

test.evaluateOnSelector('input[type="email"]', 'element.value = value', 'user.email@example.com');

Example usage of string pageFunction with handler and context

test.evaluateOnSelector('input[type="checkbox"]', 'element.value = value; element.checked', function (isChecked) {
    console.log('isChecked')
} 'On');

Example usage of pageFunction.

test.evaluateOnSelector('a[href]', function (element) { element.click() });

Example usage of pageFunction with handler

test.evaluateOnSelector(
    'input[type="text"]',
    function (element) {
        return element.value;
    }, function (value) {
        console.log(value);
    }
);

Example usage of pageFunction and context

test.evaluateOnSelector(
    'input[type="email"]',
    function (element, value) {
        element.value = value;
    },
    'user.email@example.com'
);

Example usage of pageFunction with handler and context

test.evaluateOnSelector(
    'input[type="checkbox"]',
    function (element, value) {
        element.value = value;
        return element.checked;
    },
    function (isChecked) {
        console.log('isChecked');
    },
    'On'
);

evaluateOnSelectorOnlyOne

Similar with evaluateOnSelectorAll but throws an error if detected more than one element

Type: function (selector, pageFunction, handler, value): TestingScenario

  • selector String A selector for an selecting element
  • pageFunction (Function | String) Function to be evaluated in the page context
  • handler function (result): Promise? function that receives serializable data from pageFunction, this parameter can be skipped
  • value any? context passed to pageFunction

pageEmulate

Type: function (config)

  • config

  • width Number page width in pixels.

  • height Number page height in pixels.

  • deviceScaleFactor Number Specify device scale factor (can be thought of as dpr). Defaults to 1.

  • isMobile Boolean Whether the meta viewport tag is taken into account. Defaults to false.

  • hasTouch Boolean Specifies if viewport supports touch events. Defaults to false

  • isLandscape Boolean Specifies if viewport is in landscape mode. Defaults to false.


pageEmulate

Type: function (config)

  • config

  • viewport TestingScenarioPageEmulateConfigViewport viewport options

  • userAgent String user agent definition


pageEmulate

Emulates specific configuration of device

Type: function (config): TestingScenario


fork

Timestamp The timestamp when the metrics sample was taken. Documents Number of documents in the page. Frames Number of frames in the page. JSEventListeners Number of events in the page. Nodes Number of DOM nodes in the page. LayoutCount Total number of full or partial page layout. RecalcStyleCount Total number of page style recalculations. LayoutDuration Combined durations of all page layouts. RecalcStyleDuration Combined duration of all page style recalculations. ScriptDuration Combined duration of JavaScript execution. TaskDuration Combined duration of all tasks performed by the browser. JSHeapUsedSize Used JavaScript heap size. JSHeapTotalSize Total JavaScript heap size.

Type: function ()


close

Close device Instance

Type: function ()


run

Run your tests under specific environment

Type: function (device, device2, device3, device4, device5, device6, device7, device8, otherDevices, devices)


TestingScenarioInstancePermissions

Type: ("geolocation" | "midi" | "midi-sysex" | "notifications" | "push" | "camera" | "microphone" | "background-sync" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "accessibility-events" | "clipboard-read" | "clipboard-write" | "payment-handler")


TestingScenarioPageReloadOptionsWaitUntil

When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:

  • load - consider navigation to be finished when the load event is fired.
  • domcontentloaded - consider navigation to be finished when the DOMContentLoaded event is fired.
  • networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
  • networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

Type: ("load" | "domcontentloaded" | "networkidle0" | "networkidle2")


TestingScenarioPageEmulateDeviceName

Type: ("Blackberry PlayBook" | "Blackberry PlayBook landscape" | "BlackBerry Z30" | "BlackBerry Z30 landscape" | "Galaxy Note 3" | "Galaxy Note 3 landscape" | "Galaxy Note II" | "Galaxy Note II landscape" | "Galaxy S III" | "Galaxy S III landscape" | "Galaxy S5" | "Galaxy S5 landscape" | "iPad" | "iPad landscape" | "iPad Mini" | "iPad Mini landscape" | "iPad Pro" | "iPad Pro landscape" | "iPhone 4" | "iPhone 4 landscape" | "iPhone 5" | "iPhone 5 landscape" | "iPhone 6" | "iPhone 6 landscape" | "iPhone 6 Plus" | "iPhone 6 Plus landscape" | "iPhone 7" | "iPhone 7 landscape" | "iPhone 7 Plus" | "iPhone 7 Plus landscape" | "iPhone 8" | "iPhone 8 landscape" | "iPhone 8 Plus" | "iPhone 8 Plus landscape" | "iPhone SE" | "iPhone SE landscape" | "iPhone X" | "iPhone X landscape" | "iPhone XR" | "iPhone XR landscape" | "JioPhone 2" | "JioPhone 2 landscape" | "Kindle Fire HDX" | "Kindle Fire HDX landscape" | "LG Optimus L70" | "LG Optimus L70 landscape" | "Microsoft Lumia 550" | "Microsoft Lumia 950" | "Microsoft Lumia 950 landscape" | "Nexus 10" | "Nexus 10 landscape" | "Nexus 4" | "Nexus 4 landscape" | "Nexus 5" | "Nexus 5 landscape" | "Nexus 5X" | "Nexus 5X landscape" | "Nexus 6" | "Nexus 6 landscape" | "Nexus 6P" | "Nexus 6P landscape" | "Nexus 7" | "Nexus 7 landscape" | "Nokia Lumia 520" | "Nokia Lumia 520 landscape" | "Nokia N9" | "Nokia N9 landscape" | "Pixel 2" | "Pixel 2 landscape" | "Pixel 2 XL" | "Pixel 2 XL landscape")



Package Sidebar

Install

npm i sgapps.io-testing-platform

Weekly Downloads

5

Version

1.1.17

License

Apache-2.0

Unpacked Size

2.38 MB

Total Files

60

Last publish

Collaborators

  • sgapps.io