node package manager

selen

A Bootstrap for Selenium3.0. just only install this, you can E2E automation testing.

Installation

yarn add selen

or

npm i selen -D

Usage

selen.run() is an simple API which launch Browser. Both of generator function and normal function with prommise are supported.(Below example is written generator function)

index.js

const Selen = require('selen');
const selen = new Selen({
  browserName: 'chrome'
});
selen.run(function* (driver, webdriver) {
  yield driver.get('http://www.google.com/ncr');
  yield driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
  yield driver.findElement(webdriver.By.name('btnG')).click();
  yield driver.wait(webdriver.until.titleIs('webdriver - Google Search'), 5000);
});
node index.js

Features

Basically, you don't need setup other special for Selenium except for this

Originally, below things is required to be worked Selenium

  • Download & Install Selenium Standalone
  • Launch Selenium Standalone Server
  • Download & Set PATH for driver binary of each browsers(except for safari10~)

Fully Inherit native Webdriver for NodeJS

So writable native Webdriver for NodeJS in function selen.run

Better APIs than native Webdriver API

Problem of driver.executeScript and driver.executeAsyncScript

The problem is that they are should to be passed as string like below.

driver.executeScript('document.querySelector(".login-button").click();return [Arguments, are, available, at, here].join(" ");');
driver.executeAsyncScript('var callback = arguments[arguments.length = 1];document.querySelector(".login-button").click();setTimeout(function() {callback([Arguments, are, available, at, here].join(" "))}, 10000);')

this.executeScript

this.executeScript(func[, Arg1, Arg2, ...]);
example
this.executeScript(function(Arguments, are, available, at, here) {
 
  document.querySelector(".login-button").click();
 
  return [Arguments, are, available, at, here].join(' ');//Passed "Arguments are available at here;" 
}, 'Arguments', 'are', 'available', 'at', 'here');

this.executeAsyncScript

this.executeAsyncScript(func[, Arg1, Arg2, ...]);
example
this.executeAsyncScript(function(Arguments, are, available, at, here) {
  var callback = arguments[arguments.length = 1];
 
  document.querySelector(".login-button").click();
 
  setTimeout(function() {
    callback([Arguments, are, available, at, here].join(" "))//Passed "Arguments are available at here;" 
  }, 10000);
}, 'Arguments', 'are', 'available', 'at', 'here');

this.takeScreenshot

this.takeScreenshot(path);
this.takeScreenshot('./my_screenshot/hoge.png');// -> save screenshot into specified path 
  • Emulating fullpage screenshot with scrolling page for browsers which is not support fullpage screenshot(e.g. chrome).
  • Unnecessary to write fs.writeFile' orfs.writeFileSync` by yourself to save screenshot image..

Roadmap

v.0.9.3
  • remove some dependencies of Mocha and MOCHAWESOME for working as simple Selenium
v.0.9.0
  • add custom takeScreenshot API
v.1.0.0
  • support windows OS and browsers
  • add function output browser logs

Changed log

None.

Services for Remote Testing and Multi Devices Testing

In the same way as native Webdriver, if you specify the service unique capability, then you can use these services.

They are awesome cloud testing services using real browsers and devices.




Dependencies