1.0.0 • Published 4 years ago

@lubowiecki/node-protractor v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

node-protractor

Helpers

Local storage

clear() {#localStorage}

Clear browser local storage

await LocalStorage.clear();

Logs

clear() {#logs}

Clear browser console logs

await Logs.clear();

expectNoErrors()

Run test that expects no errors are logged in browser console

await Logs.expectNoErrors();

Scroll

toElement()

Scroll page to the provided element

await Scroll.toElement();

Url

getCurrentPath()

Get current pathname

await Url.getCurrentPath();

isCurrentPath(pattern: RegExp)

Check if the current pathname matches the pattern

await Url.isCurrentPath(/home/);

VisualRegression

Config {#visualRegression}

Add 'protractor-image-comparison' plugin configuration in your protractor.conf.js

exports.config = {
  plugins: [
    {
      package: 'protractor-image-comparison',
      options: {
        formatImageName: `{tag}-{logName}-{width}x{height}`,
        baselineFolder: join(process.cwd(), './e2e/goldens/'),
        screenshotPath: join(process.cwd(), '/e2e/.tmp/'),
        savePerInstance: true,
        disableCSSAnimation: true,
        autoSaveBaseline: true,
        clearRuntimeFolder: true,
      },
    },
  ],
};

checkScreen(tag: string, lang: Langs, options?: SaveScreenMethodOptions)

Compares an image of a viewport

await VisualRegression.checkScreen('screenName', 'pl');

checkFullPageScreen(tag: string, lang: Langs, options?: SaveFullPageMethodOptions)

Compares an image of a page

await VisualRegression.checkFullPageScreen('pageName', 'pl');

Wait

sleep(time: number)

Stop test for the given amount of time in miliseconds

await Wait.sleep(500);

forElementInView(element: ElementFinder, waitTime = 5000)

Wait for the element to be visible in browser window

await Wait.forElementInView(element(by.css('h1')));

Locators

Config {#locators}

Add locators configuration in your protractor.conf.js

exports.config = {
  onPrepare() {
    require('@lubowiecki/node-protractor/dist/locators');
  },
};

testId(id: RegExp | string, parentElement?: Element)

Find element by test-id

<div test-id="myName"></div>
const myDiv = element(by.testId('myName'));

headingWithText(pattern: RegExp | string, parentElement?: Element)

Find heading that matches pattern

<h1>My title</h1>
const myHeading = element(by.headingWithText('My title'));

inputWithLabel(label: string | RegExp, parentElement?: Element)

Find input with label that matches pattern

<label for="myInput">My label</label> <input id="myInput" />
const myInput = element(by.inputWithLabel('My label'));