blackboard / protractor-sync

Wrapper around Protractor, providing synchronous test writing and lots of helper functions.
MIT License
17 stars 5 forks source link
e2e-test protractor protractor-sync selenium typescript webdriver

What is this?

Protractor-sync builds on Protractor and provides:

Installation

Pre-reqs:

Install: npm install protractor-sync

Example

import * as ab from 'asyncblock';
import { browserSync, configure, elementSync, polledExpect} from '../../app/index';

configure({ implicitWaitMs: 500 });

function createTest(fn: Function, errorMsg?: string) {
  return (done: Function) => {
    ab(() => {
      fn();
    }, (err: any) => {
      if (errorMsg) {
        expect(err.message).toEqual(errorMsg);
      } else {
        expect(err && err.stack || err || undefined).toBeUndefined();
      }
      done();
    });
  };
}

describe('Google Translate', () => {
  const googleTranslateUrl = 'https://translate.google.com/';

  it('does not show the clear button when no text exists in the source field', createTest(() => {
    browserSync.get(googleTranslateUrl);

    const rootElement = elementSync.findVisible('#gt-src-c');
    polledExpect(() => rootElement.findElement('.clear-button').isDisplayed()).toEqual(false);
  }));

  it('does show the clear button after entering text in the source field', createTest(() => {
    browserSync.get(googleTranslateUrl);

    const rootElement = elementSync.findVisible('#gt-src-c');
    rootElement.findVisible('textarea#source').clear().sendKeys('12345');
    polledExpect(() => rootElement.findElement('.clear-button').isDisplayed()).toEqual(true);
  }));
});

See test/spec/protractor-sync_test.ts for more examples.

How to contribute

Thanks you for your interest in Protractor-sync. In lieu of a formal style guide, take care to maintain the existing coding style. Please add tests for any new or changed functionality.

API

See API.md

Tips

Build tasks

This project will automatically build, lint and test when pushing code to a remote repository.