1.5.33 • Published 3 years ago

protractor-tester-utils v1.5.33

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

protractor-tester-utils

The Protractor Tester Utils module will help the tester who works with the protractor by providing various handy Utilities. Easy to set up and use it in any protractor framework. It also now supports API calls and it can be used in the Protractor directly.

Installation

npm install protractor-tester-utils
yarn add protractor-tester-utils

Page Object setup

Import getPageObject from protractor-tester-utils and call and assign the getPageObject method with argument (file path of the .yaml or .json) to params pageObject variable. Sample snippet provided below.

import { getPageObject } from "protractor-tester-utils";
import { Config } from "protractor";

export let config: Config = {
    framework: "jasmine",
    capabilities: {
        browserName: "chrome",
    },
    seleniumAddress: "http://localhost:4444/wd/hub",
    specs: "spec.js"],
    params: {
        pageObject: getPageObject("../../../src/example/pages"),
    },
};

Usage

Javascript

const { getElement, validateGetText } = require("protractor-tester-utils");

describe("Sample Suit", () => {
    it("Test#1", () => {
        const homeHeader = getElement("header");
        validateGetText(homeHeader, "Header Title");
    });
});
Case will be Pass if the value matched exit 0

TypeScript

import { elementGetText } from "protractor-tester-utils";
console.log(elementGetText("header"));
Output should be 'Header Title'

Available utility

Available UtilityParametersReturn TypeDescription
Action Utils
holdClickUnholdCtrlKey(locator: ElementFinder)Promise< void >This util will help to perform hold ctrl and mouse click and unhold ctrl
holdClickUnholdShiftKey(locator: ElementFinder)Promise< void >This util will help to perform hold shift and mouse click and unhold shift
holdCtrlKeyPromise< void >This util will help to perform hold ctrl key
holdShiftKeyPromise< void >This util will help to perform hold shift key
mouseClick(locator: string / ElementFinder)Promise< void >This util will help to perform mouse click
mouseClickAndHold(locator: string / ElementFinder)Promise< void >This util will help to perform mouse click and hold
mouseDoubleClick(locator: string / ElementFinder)Promise< void >This util will help to perform mouse double click
mouseDragDrop(locator: string / ElementFinder, targetLocator: string / ElementFinder)Promise< void >This util will help to perform mouse drag and drop
mouseHover(locator: string / ElementFinder)Promise< void >This util will help to perform mouse hover on element
mouseReleaseClickAndUnhold(locator: string / ElementFinder)Promise< void >This util will help to perform release mouse hold
mouseSwipeLeftRight(locator: string / ElementFinder, distance: number, options: IConfig = {})Promise< void >This util will help to perform swife left or right.example: left (distance=-50), right (distance=50)
mouseSwipeUpDown(locator: string / ElementFinder, distance: number, options: IConfig = {})Promise< void >This util will help to perform swife Down or Up.example: Up (distance=-50), Down (distance=50)
pressKey(key: any, options: IConfig = {})Promise< void >This util will help to perform keyboard actions using sendKeys. example: pressKey(protractor.Key.ENTER)
pressTabKeyPromise< void >THis util will help to perform keyboard press tap key
unholdCtrlKeyPromise< void >This util will help to perform unhold ctrl key
unholdShiftKeyPromise< void >This util will help to perform unhold shift key
Assertion Utils
assertContains(actual: any, expected: any)voidThis util will check the contains value in given string
assertEqual(actual: any, expected: any)voidThis util will check the given value is equal
assertArrJsonEqual(actual: any, expected: any)voidThis util will check the given json / array value is equal
assertEqualLength(value: any, size: number)voidThis util will check the given value is in equal length
assertInvisibilityOf(locator: string / ElementFinder, millisecs: number = 10000)voidThis util will check the given Element is visible
assertIsFalse(value: any)voidThis util will check the given value is false
assertIsTrue(value: any)voidThis util will check the given value is true
assertNotContains(actual: any, expected: any)voidThis util will check the given value is not in contains
assertNotEqual(actual: any, expected: any)voidThis util will check the given value is not equal
assertNotArrJsonEqual(actual: any, expected: any)voidThis util will check the given json / array value is not equal
assertPresenceOf(locator: string / ElementFinder, millisecs: number = 10000)voidThis util will check the given Element is Present
assertVisibilityOf(locator: string / ElementFinder, millisecs: number = 10000)voidThis util will check the given Element is visible
assertOrderedDeepEquality(actual: any, expected: any)voidThis util will check the given json / array value is Ordered Deep Equality
assertUnorderedDeepEquality(actual: any, expected: any)voidThis util will check the given json / array value is Unordered Deep Equality
assertObjKeyEqual(actual: any, expected: any)voidThis util will check the Object key Equal
assertObjNestedPropertyEqual(actual: any, expectedProp: any, expectedVal?: any)voidThis util will check the Object Nested Property Equal
assertObjPropertyEqual(actual: any, expectedProp: any, expectedVal?: any)voidThis util will check the Object Property Equal
assertPartialOrderedDeepEquality(actual: any, expected: any)voidThis util will check the Partial Ordered Deep Equality
assertPartialUnorderedDeepEquality(actual: any, expected: any)voidThis util will check the Partial Unordered Deep Equality
Browser Utils
browserClosePromise< void >Used to close the browser instance
browserGet(url: string, timeoutms: number = 0)Promise< void >To launch URL in browser and aslo check the URL is valid before launch
browserGetLocationAbsUrlPromise< any >To Get Absolute URL for @example browser.get('http://angular.github.io/protractor/#/api'); expect(browser.getLocationAbsUrl()).toBe('http://angular.github.io/protractor/#/api');
browserGetPageSourcePromise< string >To get current page source
browserGetTitlePromise< string >To get current page title
browserGoBackPromise< void >To navigate back in browser
browserGoForwardPromise< void >To navigate forward in browser
browserQuitPromise< void >To quit the browser instance
browserRefreshPromise< void >To Refresh the browser
browserRestartPromise< void >To Restart the browser instance
browserRestartSyncvoidTo Restart the browser instance in sync
browserSetLocationPromise< void >Browse to another page using in-page navigation. @example browser.get('http://angular.github.io/protractor/#/tutorial'); browser.setLocation('api'); expect(browser.getCurrentUrl()).toBe('http://angular.github.io/protractor/#/api');
browserSwitchTab(tabIndex: number = 0)Promise< void >To Switch tabs on browser
browserSwitchToDefaultFramePromise< void >To switch back to default frame
browserSwitchToFrame(indexOfFrame: number, options: IConfig = {})Promise< void >To switch to frame using index
browserWaitForAngularEnabled(boolVal: boolean)Promise< void >To control angular and non angular control flow
clicker(locator: string / ElementFinder, timeoutms: number = 0)Promise< void >To perform click operation on browser by passing locator & time out in milliseconds (Optional)
elementGetText(locator: string / ElementFinder, options: IConfig = {})Promise< string >To get the text of the element
elementInputGetText(locator: string / ElementFinder, options: IConfig = {})Promise< string >To get the text from input field
elementLogger(locator: string / ElementFinder, options: IConfig = {})Promise< void >To get details of the element it will print the details of the element on console
findElementByText(searchText: string, cssSelector: string = "div, li, option")Promise< ElementFinder >To find an element by text for e.g. list items
findElementsByText(searchText: string, cssSelector: string = "div, li, option")(Promise< any[] / ElementFinder[] >)To find an array of element by text for e.g. missing css selector options
getBrowserURLPromise< string >To get the current page URL
getScreenshot(locator: ElementFinder)Promise< string >Will return the element screen shot by base 64 string
isURL(url: string)booleanTo validate the url
sendkeys(locator: string / ElementFinder, value: string / number / Promise< string / number >, timeoutms: number = 0)Promise< void >To set value in input fields on browsers
stringToJSON(jsonData: string)anyThis util will parse unformat JSON to valid JSON
switchToFrame(index?: number, locator?: string / ElementFinder)Promise< void >This util will help to switch the frame using either by index or element
takeScreenShot(locator: ElementFinder, filePath: string)Promise< void >This util will help to take screenshot and save as png file in specified file path
Date Utils
getCurrentDayPromise< string >This utill will provide specified date format
getCustomFormatDate(dateFormat: "dd-mm-yyyy" / "dd/mm/yyyy" / "yyyy-mm-dd" / "yyyy/mm/dd" / "m/d/yyyy" / "m-d-yyyy" / string)Promise< string >This utill will provide specified date format
getDateTimeStampPromise< string >This utill will provide specified date format
getddMMMyyyyPromise< string >This utill will provide specified date format
getddMMMyyyyhhmmssPromise< string >This utill will provide specified date format
getddMMMyyyymsPromise< string >This utill will provide specified date format
getddMMMyyyyssPromise< string >This utill will provide specified date format
getddMMyyyyhhmmssPromise< string >This utill will provide specified date format
getFutureDate(addDays: number)Promise< string >This utill will provide specified date format
getFutureDayfrmCurrentDay(addDays: number)Promise< string >This utill will provide specified date format
getPastDate(minusDays: number)Promise< string >This utill will provide specified date format
getTimeStampPromise< string >This utill will provide specified date format
getUSFormatePromise< string >This utill will provide specified date format
Exception Utils
throwCustomError (err: string)neverThis util will throw custom error
throwErrorMsg(err: Error)neverThis util will throw error message
throwErrorName(err: Error)neverThis util will throw error name
throwErrorStack(err: Error)neverThis util will throw error stack
Element Utils
getDynamicElement(locatorType: "binding"/ "buttontext"/ "classname"/ "css"/ "deepcss"/ "exactbinding"/ "exactrepeater"/ "id"/ "linktext"/ "model"/ "name"/ "partialbuttontext"/ "partiallinktext"/ "repeater"/ "tagname"/ "xpath"/ string,locatorVal: string)ElementFinderThis function will return ElementFinder based on the locator provided in argument
getDynamicElements(locatorType: "binding"/ "buttontext"/ "classname"/ "css"/ "deepcss"/ "exactbinding"/ "exactrepeater"/ "id"/ "linktext"/ "model"/ "name"/ "options"/ "partialbuttontext"/ "partiallinktext"/ "repeater"/ "tagname"/ "xpath"/ string,locatorVal: string)ElementArrayFinderThis function will return ElementArrayFinder based on the locator provided in argument
getElement(locatorVal: string)ElementFinderThis function will return Element Finder based on the locator provided in JSON/YAML
getElements(locatorVal: string)ElementArrayFinderThis function will return Element Array Finder based on the locator provided in JSON/YAML
JavaScript Execution Utils
jsExecAlert(alertMsg: string)Promise< void >This method displays the message in alert and close after 3 seconds
jsExecClearBrowserInstancePromise< void >Util to clear cookies, session, storage
jsExecClick(locator: string / ElementFinder)Promise< void >This util will be used to click an element using JavaScriptExecutor
jsExecHighlightElement(locator: string / ElementFinder)Promise< void >This util will be used to highlight an element using JavaScriptExecutor
jsExecMouseHoverAndClick(locatorToHover: string / ElementFinder,locatorToClick: string / ElementFinder)Promise< void >This util will be used to Mouse Hover to element and Click to the specific element using JavaScriptExecutor
jsExecOpenNewTab(url: string)Promise< void >Util to open a url in a new tab
jsExecRemoveElement(locator: string / ElementFinder, options: IConfig)Promise< void >Util to remove an element from the document
jsExecReplaceAttributeValue(attribute: string, attributeValue: string, locator: ElementFinder)Promise< void >This util will be used to Replace Attibute value in DOM level
jsExecScrollIntoView(locator: string / ElementFinder)Promise< void >This util will be used to scroll to view particullar element using JavaScriptExecutor
jsExecScrollupPromise< void >This util will be used to scroll the page to Top or Up using JavaScriptExecutor
jsExecSetDate(locator: string / ElementFinder, date: string)Promise< void >This util will be used to set date using JavaScriptExecutor
jsExecSetText(locator: string / ElementFinder, replace: string, options: IConfig)Promise< void >Util to set the text to an element
jsExecSetTextByRegEx(locator: string / ElementFinder, search: string, replace: string, options: IConfig)Promise< void >Util to set the text to element by regExp
jsExecTyper(locator: ElementFinder, value: string)Promise< void >This util will be usedTo set value to Textbox using JavaScriptExecutor
jsExecUploadFile(filePath: string, indexOfElement: number = 0)Promise< void >Util to upload a file
Request Utils
DELETE(reqConf: IRequestOptions)Promise< AxiosResponse< any > / undefined >Api call for delete request
GET(reqConf: IRequestOptions)
1.5.33

3 years ago

1.5.32

3 years ago

1.5.31

3 years ago

1.5.30

3 years ago

1.5.29

4 years ago

1.5.28

4 years ago

1.5.25

4 years ago

1.5.24

4 years ago

1.5.27

4 years ago

1.5.26

4 years ago

1.5.23

4 years ago

1.5.18

4 years ago

1.5.17

4 years ago

1.5.19

4 years ago

1.5.21

4 years ago

1.5.20

4 years ago

1.5.22

4 years ago

1.5.16

4 years ago

1.5.15

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

1.5.12

4 years ago

1.5.11

4 years ago

1.5.10

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.37

4 years ago

1.4.36

4 years ago

1.4.35

4 years ago

1.4.34

4 years ago

1.4.33

4 years ago

1.4.32

4 years ago

1.4.31

4 years ago

1.4.28

4 years ago

1.4.27

4 years ago

1.4.29

4 years ago

1.4.26

4 years ago

1.4.25

4 years ago

1.4.24

4 years ago

1.4.23

4 years ago

1.4.22

4 years ago

1.4.21

4 years ago

1.4.20

4 years ago

1.4.19

4 years ago

1.4.17

4 years ago

1.4.18

4 years ago

1.4.11

4 years ago

1.4.10

4 years ago

1.4.13

4 years ago

1.4.12

4 years ago

1.4.15

4 years ago

1.4.14

4 years ago

1.4.16

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.0.9

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.0

4 years ago