protractor-tester-utils
TypeScript icon, indicating that this package has built-in type declarations

1.5.33 • Public • Published

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 Utility Parameters Return Type Description
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
holdCtrlKey Promise< void > This util will help to perform hold ctrl key
holdShiftKey Promise< 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)
pressTabKey Promise< void > THis util will help to perform keyboard press tap key
unholdCtrlKey Promise< void > This util will help to perform unhold ctrl key
unholdShiftKey Promise< void > This util will help to perform unhold shift key
Assertion Utils
assertContains (actual: any, expected: any) void This util will check the contains value in given string
assertEqual (actual: any, expected: any) void This util will check the given value is equal
assertArrJsonEqual (actual: any, expected: any) void This util will check the given json / array value is equal
assertEqualLength (value: any, size: number) void This util will check the given value is in equal length
assertInvisibilityOf (locator: string / ElementFinder, millisecs: number = 10000) void This util will check the given Element is visible
assertIsFalse (value: any) void This util will check the given value is false
assertIsTrue (value: any) void This util will check the given value is true
assertNotContains (actual: any, expected: any) void This util will check the given value is not in contains
assertNotEqual (actual: any, expected: any) void This util will check the given value is not equal
assertNotArrJsonEqual (actual: any, expected: any) void This util will check the given json / array value is not equal
assertPresenceOf (locator: string / ElementFinder, millisecs: number = 10000) void This util will check the given Element is Present
assertVisibilityOf (locator: string / ElementFinder, millisecs: number = 10000) void This util will check the given Element is visible
assertOrderedDeepEquality (actual: any, expected: any) void This util will check the given json / array value is Ordered Deep Equality
assertUnorderedDeepEquality (actual: any, expected: any) void This util will check the given json / array value is Unordered Deep Equality
assertObjKeyEqual (actual: any, expected: any) void This util will check the Object key Equal
assertObjNestedPropertyEqual (actual: any, expectedProp: any, expectedVal?: any) void This util will check the Object Nested Property Equal
assertObjPropertyEqual (actual: any, expectedProp: any, expectedVal?: any) void This util will check the Object Property Equal
assertPartialOrderedDeepEquality (actual: any, expected: any) void This util will check the Partial Ordered Deep Equality
assertPartialUnorderedDeepEquality (actual: any, expected: any) void This util will check the Partial Unordered Deep Equality
Browser Utils
browserClose Promise< 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
browserGetLocationAbsUrl Promise< 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');
browserGetPageSource Promise< string > To get current page source
browserGetTitle Promise< string > To get current page title
browserGoBack Promise< void > To navigate back in browser
browserGoForward Promise< void > To navigate forward in browser
browserQuit Promise< void > To quit the browser instance
browserRefresh Promise< void > To Refresh the browser
browserRestart Promise< void > To Restart the browser instance
browserRestartSync void To Restart the browser instance in sync
browserSetLocation Promise< 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
browserSwitchToDefaultFrame Promise< 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
getBrowserURL Promise< 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) boolean To 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) any This 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
getCurrentDay Promise< 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
getDateTimeStamp Promise< string > This utill will provide specified date format
getddMMMyyyy Promise< string > This utill will provide specified date format
getddMMMyyyyhhmmss Promise< string > This utill will provide specified date format
getddMMMyyyyms Promise< string > This utill will provide specified date format
getddMMMyyyyss Promise< string > This utill will provide specified date format
getddMMyyyyhhmmss Promise< 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
getTimeStamp Promise< string > This utill will provide specified date format
getUSFormate Promise< string > This utill will provide specified date format
Exception Utils
throwCustomError  (err: string) never This util will throw custom error
throwErrorMsg (err: Error) never This util will throw error message
throwErrorName (err: Error) never This util will throw error name
throwErrorStack (err: Error) never This 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) ElementFinder This 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) ElementArrayFinder This function will return ElementArrayFinder based on the locator provided in argument
getElement (locatorVal: string) ElementFinder This function will return Element Finder based on the locator provided in JSON/YAML
getElements (locatorVal: string) ElementArrayFinder This 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
jsExecClearBrowserInstance Promise< 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
jsExecScrollup Promise< 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) Promise< AxiosResponse< any > / undefined > Api call for get request
POST (reqConf: IRequestOptions) Promise< AxiosResponse< any > / undefined > Api call for post request
PUT (reqConf: IRequestOptions) Promise< AxiosResponse< any > / undefined > Api call for put request
Select Utils
selectDropDown (selectLocator: string / ElementFinder, selectBy: "visibletext" / "value" / "index" / "multiselect", value: string, tagName: string = "option") Promise< void > This util will be used to select value from dropdown based on argument
Validation Utils
validateCheckboxChecked (locator: ElementFinder, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate Checkbox is checked or not
validateDropDownList (locator: ElementFinder, expected: string, tagName: string = "option", type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate list in drop down
validateDropDownSelectedValue (locator: ElementFinder, expected: string, tagAndValue: string = "option:checked", type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate Selected drop down value
validateDropDownValue (locator: ElementFinder, expected: string, tagName: string = "option", type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate value available in drop down list
validateDropDownValuesCount (locator: ElementFinder, expected: number, tagAndValue: string = "option", type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate the count of the drop down list
validateElementIsDisplayed (locator: string / ElementFinder, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate is element displayed
validateElementIsEnabled (locator: string / ElementFinder, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate is element enabled
validateElementIsPresent (locator: string / ElementFinder, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate is element present
validateElementIsSelected (locator: string / ElementFinder, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate is element selected
validateGetText (locator: string / ElementFinder, expected: string, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate element text
validateInputFieldValue (locator: string / ElementFinder, expected: string, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate element entered field text
validatePlaceholdeValue (locator: string / ElementFinder, expected: string, type: "POSITIVE" / "NEGATIVE" = "POSITIVE") Promise< void > This util will validate element placeholder value
Wait Utils
waitUntilAlertPresence (millisecs: number = 10000) Promise< void > This util will wait until the alert present based on given time
waitUntilElementClickable (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until the element will clickable
waitUntilElementDisappear (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until invisible of the element
waitUntilElementPresence (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until the element presence
waitUntilElementSelected (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until the element selected
waitUntilElementStaleness (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until staleness of the element
waitUntilElementVisible (locator: string / ElementFinder, millisecs: number = 10000) Promise< void > This util will wait until visible of the element
waitUntilGivenTime (millisecs: number = 10000) Promise< void > This util will wait until given time
waitUntilPageLoad (urlcontains: string, millisecs: number = 10000) Promise< void > This util will wait until the page load by contains url string
waitUntilTextPresent (locator: string / ElementFinder, text: string, millisecs: number = 10000) Promise< void > This util will wait until Text Present in HTML Page
Api Utils
ApiUtils

License

MIT License

Copyright (c) 2020 Muralidharan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release Notes

Notes for the released versions

1.5.33

v1.5.33: Date method updated

1.5.32

v1.5.32: Retry try catch implemented for clicker and sendkeys method

1.5.31

v1.5.31: Scroll into view functionality updated in clicker method

1.5.30

v1.5.30: Wait methods updated

1.5.29

v1.5.29: select method updated

1.5.28

v1.5.28: Wait methods updated

1.5.27

v1.5.27: element return type updated for getElement(s) method

1.5.26

v1.5.26: Report path generation error fixed

1.5.25

v1.5.25: Packages updated

1.5.24

v1.5.24: Package updated

1.5.23

v1.5.23: Report folder creation updated

1.5.22

v1.5.22: Drop down list validator method issue fixed

1.5.21

v1.5.21: Drop down list validator method issue fixed

1.5.20

v1.5.20: Drop down list validator method issue fixed

1.5.19

v1.5.19: Drop down list validator method updated

1.5.18

v1.5.18: Drop down list validator method updated

1.5.17

v1.5.17: Drop down validator methods updated

1.5.16

v1.5.16: Date utils & Java script executor methods updated

1.5.15

v1.5.15: API interface updated

1.5.14

v1.5.14: methods added for text field actions

1.5.13

v1.5.13: Select multi drop down method bug fixed

1.5.12

v1.5.12: Select drop down method bug fixed

1.5.11

v1.5.11: Select drop down method updated

1.5.10

v1.5.10: Multi select drop down method updated

1.5.9

v1.5.9: custom date method updated

1.5.8

v1.5.8: select method updated

1.5.7

v1.5.7: general bug fix

1.5.6

v1.5.6: general bug fix

1.5.5

v1.5.5: Multi select method updated

1.5.4

v1.5.4: MS SQL utils added

1.5.3

v1.5.3: MS SQL utils added

  • MS SQL utils added
  • getElement and getElements method updated
  • waitUntilElementDisappear method updated

1.5.2

v1.5.2: logger utils added

  • Logger utils added
  • Support both angular & non angular
  • sendkeys method updated for empty string
  • Excel to feature method updated

1.5.1

v1.5.1: Excel to feature method updated

1.5.0

v1.5.0: Functions updated

  • Added brwser title validation method
  • Updated validation methods
  • JavaScript Executor methods methods updated by default element will have getWebElement wrapper
  • Excel to feature method updated

1.4.37

v1.4.37: Assertion methods added

1.4.36

v1.4.36: Alert Handler methods added

1.4.35

v1.4.35: File path list method Added

1.4.34

v1.4.34: Default timeout restore method updated

1.4.33

v1.4.33: Default timeout override and restore method updated

1.4.32

v1.4.32: Double click method issue fixed

1.4.31

v1.4.31: Assertion methods added custom error message args

1.4.30

v1.4.30: Assertion methods added custom error message args

1.4.29

v1.4.29: YAML method updated

1.4.28

v1.4.28: YAML method updated

1.4.27

v1.4.27: Encryption and Decryption method updated

1.4.26

v1.4.26: Encryption and Decryption method updated

1.4.25

v1.4.25: Encryption and Decryption method updated

1.4.24

v1.4.24: Encryption and Decryption method added

1.4.23

v1.4.23: yaml version updated

1.4.22

v1.4.22: getAttribute Method included

1.4.21

v1.4.21: Bug fix

1.4.20

v1.4.20: Bug fix

1.4.19

v1.4.19: Bug fix

1.4.18

v1.4.18: Bug fix

1.4.17

v1.4.17: Update on YML/YAML file reading

1.4.16

v1.4.16: Bug fix

1.4.15

v1.4.15: Bug fix

1.4.14

v1.4.14: Excel to Feature functionality updated

1.4.13

v1.4.13: Exception handled for Element locators methods

1.4.12

v1.4.12: Method patch update

1.4.11

v1.4.11: Method patch update

1.4.10

v1.4.10: Method patch update

1.4.9

v1.4.9: Method patch update

1.4.8

v1.4.8: Method patch update

1.4.7

v1.4.7: Excel 2 feature method updated

1.4.6

v1.4.6: Exception handled for Wait utility

1.4.5

v1.4.5: Bug fix

1.4.4

v1.4.4: methods updated for excel to feature and updated wait util for default timeout

1.4.3

v1.4.3: methods updated for excel to feature and updated wait util for default timeout

1.4.2

v1.4.2: methods updated

1.4.1

v1.4.1: methods updated

1.4.0

v1.4.0: Added few more utils functionality and fixed few bugs

1.3.9

v1.3.9: Added few more utils functionality

1.3.8

v1.3.8: Bug fix

1.3.7

v1.3.7: Added few more utils functionality

1.3.6

v1.3.6: Added date util functionality

1.3.5

v1.3.5: Added few more assertions functionality, Fixed known issues

1.3.4

v1.3.4: Fixed known issues

1.3.3

v1.3.3: Fixed known issues

1.3.2

v1.3.2: Added few more assertions functionality, Fixed known issues

1.3.1

v1.3.1: Added properties for API methods

1.3.0

v1.3.0: Added API handle methods, Fixed known issues, Added few more functionality

1.2.1

v1.2.1: Added few more functionality

1.2.0

v1.2.0: Added few more functionality

1.1.0

v1.1.0: Async issue resolved for few more functionality

1.0.9

v1.0.9: Async issue resolved, getPageObject method updated the functionalit

1.0.8

bug fix

1.0.7

Bug fix file path

1.0.6

Bug fix

1.0.5

Typo corrected

1.0.4

Features added

1.0.3

Features added for auto deploy

1.0.2

Features added

1.0.0

Initial release

Package Sidebar

Install

npm i protractor-tester-utils

Weekly Downloads

19

Version

1.5.33

License

MIT

Unpacked Size

478 kB

Total Files

83

Last publish

Collaborators

  • muralidharan92
  • adithiya_baskaran
  • veeranarayana.jami