Skip to content

Simple-Automation-Testing/promod

Repository files navigation

PROMOD

Motivation. I really like protractor framework, and its api. Unfortunately protractor is deprecated.
That's why i decided to build this library and this library should allow you replace protractor framework in your TAF without massive refactoring.

API

Browser and element APIs should work in same way (as it was in protractor). But this library does not have ExpectedConditions object - replacement for this is simple browser.wait with browser/element API.

Element

Elements

Browser

Init driver

Usage with selenium engine

  const {seleniumWD} = require('promod');
  const {$, $$, getDriver, browser} = seleniumWD;

  ;(async () => {
    const searchInput = $('input[name="q"]');
    const sections = $$('section');
    await getDriver({seleniumAddress: 'http://localhost:4444/wd/hub'}, browser);
    await browser.get('https://www.npmjs.com/');
    await searchInput.sendKeys(`promod${browser.Key.ENTER}`);
    console.log(await sections.get(0).$('a').getText());
  })()

Usage with playwright engine (only for local execution)

  const {playwrightWD} = require('promod');
  const {$, $$, getDriver, browser} = playwrightWD;

  ;(async () => {
    const searchInput = $('input[name="q"]');
    const sections = $$('section');
    await getDriver(browser);
    await browser.get('https://www.npmjs.com/');
    await searchInput.sendKeys(`promod${browser.Key.ENTER}`);
    console.log(await sections.get(0).$('a').getText());
  })()

Transition from protractor to promod. Mocha example.

Current test command

  "test": "protractor ./protractor.conf.js"

Update to

  "test": "mocha $(find specs -name '*.spec.*') --file ./mocha.hooks.js --timeout 500000"

Where: $(find specs -name '*.spec.*') spec files --file ./mocha.hooks.js mocha hooks file

mocha.hooks.js example

const {config} = require('./protractor.conf.js');
const {seleniumWD} = require('promod');

before(async function() {
  /**
   * onPrepare - protractor part
   * rest - other config data
   */
  const {onPrepare, ...rest} = config;
  const {getDriver, browser, $, $$} = seleniumWD;

	await getDriver(rest, browser);

  // i am not a big fan of global object usage, but if it is suitable for you, just add API to global
  global.browser = browser;
  global.$ = $;
  global.$$ = $$;

  if (onPrepare) {
    await onPrepare();
  }
});

after(async function() {
  await global.browser.quit();
});

Current drivers update command

  "update:driver": "webdriver-manager update"

Update to

  "update:driver": "selenium-standalone install"

Improvement plan

  • Add documentation - in progress
  • Add playwright integration - in progress
  • Add test runner - in progress
  • Add logger - in progress