All Projects → gogoyqj → Karma Event Driver Ext

gogoyqj / Karma Event Driver Ext

Licence: mit
use webdriverio like api in browser with karma lol

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Karma Event Driver Ext

Tib
Easy e2e browser testing in Node
Stars: ✭ 64 (+276.47%)
Mutual labels:  webdriver, browser
Browser Monkey
Reliable DOM testing
Stars: ✭ 53 (+211.76%)
Mutual labels:  karma, browser
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+68082.35%)
Mutual labels:  karma, browser
Marionette
Selenium alternative for Crystal. Browser manipulation without the Java overhead.
Stars: ✭ 119 (+600%)
Mutual labels:  webdriver, browser
Python Scripts
Collection of Various Python Script's.💻
Stars: ✭ 195 (+1047.06%)
Mutual labels:  webdriver, browser
Undetected Chromedriver
Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
Stars: ✭ 365 (+2047.06%)
Mutual labels:  webdriver, browser
react-ssr-spa
Server side rendered single page app using reactjs official libraries.
Stars: ✭ 30 (+76.47%)
Mutual labels:  webdriver, karma
Webdriver
Remote control interface that enables introspection and control of user agents.
Stars: ✭ 546 (+3111.76%)
Mutual labels:  webdriver, browser
Beaker
An experimental peer-to-peer Web browser
Stars: ✭ 6,411 (+37611.76%)
Mutual labels:  browser
Exokit
Native VR/AR/XR engine for JavaScript 🦖
Stars: ✭ 809 (+4658.82%)
Mutual labels:  browser
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (+4311.76%)
Mutual labels:  browser
Gitbeaker
🤖 GitLab API NodeJS library with full support of all the Gitlab API services.
Stars: ✭ 755 (+4341.18%)
Mutual labels:  browser
Triflejs
Headless automation for Internet Explorer
Stars: ✭ 815 (+4694.12%)
Mutual labels:  browser
Auth0.js
Auth0 headless browser sdk
Stars: ✭ 755 (+4341.18%)
Mutual labels:  browser
Tridentsandbox
An In-Browser Scripting IDE for HTML5/Javascript
Stars: ✭ 5 (-70.59%)
Mutual labels:  browser
Javascript Obfuscator
A powerful obfuscator for JavaScript and Node.js
Stars: ✭ 8,204 (+48158.82%)
Mutual labels:  browser
Bigpicture.js
bigpicture.js is a Javascript library that allows infinite panning and infinite zooming in HTML pages.
Stars: ✭ 733 (+4211.76%)
Mutual labels:  browser
Hackbrowser
A hackable, cross-platform Chromium-based browser written in JS
Stars: ✭ 16 (-5.88%)
Mutual labels:  browser
Qutebrowser
A keyboard-driven, vim-like browser based on PyQt5.
Stars: ✭ 7,401 (+43435.29%)
Mutual labels:  browser
Cef4delphi
CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
Stars: ✭ 785 (+4517.65%)
Mutual labels:  browser

karma-event-driver-ext

Join the chat at https://gitter.im/karma-event-driver-ext/Lobby

Build Status

Introduction


Logic

This project aims to integrate webdriverio into karma, for writing event-drive-tests conveniently.

for example, in your browser side test code, call webdriverio api to simulate dragAndMove behavior:

        await browser
            .moveToObject(document.body, 0, 0) // top-left corner
            .buttonDown() // left-mouse down
            .moveTo(null, 0, -100) // mouse-move -100 on the Y-axis
            .buttonUp() // left-mouse up
            .$apply(); // execute

LOL Good News!!!

WarningFeature rely on WebdriverIO, seems a bug need to be fixed, detail Issue.

Since version 0.0.13, ext will auto route apis for PC to mobile support apis, for example:

moveToObject(ele, x, y) + buttonDown() => touchDown(ele.left + x, ele.top + y)

more [email protected]. Then most of ur tests can run both sides of PC and mobile, Write once, run twice.

How it works

browser in karma-event-driver-ext is just a proxy to receive command. while a webdriverio-like api being called, proxy will format arguments received, for example, convert an argument which type is Element to unique query, then call $apply to sends drive-commands to socket server and wait for executing response.

webdriverio is used to drive the browser and simulate user-behavior.

Tips:

  • must not hard refresh karma test page [Chrome is fine, while firefox goes wrong unexpectedly]
  • must call $apply, a promise will be returned.
  • if Element has no id, event-drivers-hook js will assign a unique id to it automatically.
  • aim to simulate event and most webdriverio api support[except $, $$, then and all Window/api]. more api

requirements

then must export path to $PATH where u put drivers* or copy drivers* to project directory.

usage

npm install

karma.conf.js

module.exports = {
     customLaunchers: {
        'Chrome': {
            base: 'WebDriverio',
            browserName: 'chrome',
            name: 'Karma'
        },
        'Firefox': {
            base: 'WebDriverio',
            browserName: 'firefox',
            name: 'Karma-Firefox',
            config: {
                browserName: 'firefox',
                host: '127.0.0.1', // default
                port: '4444' // default
            }
        }
    },
    browsers: ['Chrome'],
    // if plugins assigned, should:
    // since with plugins, karma won't auto load karma-* modules
    plugins: [
        'karma-webdriverio-launcher'
    ]
    ...
}

Tests code get webdriverio api:

basic usage
    import { beforeHook, beforeEachHook, afterHook, browser, config } from 'karma-event-driver-ext/cjs/event-driver-hooks';
    let { $serial } = browser;
    // ext using socket-io to communicate with webdriver-io, host & port is changeable
    config({
        host: 127.0.0.1, // default
        port: 8848       // default, if modified, keep same to init({ port: 8848 })
    });
    describe('Test', function() {
        // first increase timeout
        ...
        // then before all hook
        before(async () => {
            await beforeHook();
            ...
        })

        // required if using $serial
        beforeEach(async () => {
            await beforeEachHook();
        });

        after(async () => {
            ...
            await afterHook();
        })

        it('Example', async () => {
            await browser
                .click(document.body)
                .$apply();
            
            await browser
                .pause(1000)
                .$apply(); // wait 1000 ms
            ...
        })
    });
advanced usage

in specified situation, eg: React Component, tests won't start until componentDidMount trigger, More complex, will pause and wait for componentDidUpdate to resume.

always need wrapping a promise:

it('test', async () => {
    let rs, rj, prom = new Promise((s, j) => {
        rs = s;
        rj = j;
    })
    class A extends Component {
        ...

        componentDidMount() {
            rs();
        }

        componentDidUpdate() {
            rs();
        }

        click() {
            this.setState({
                reRender: true
            })
        }
        render() {
            return <div id="button">click me</div>
        }
        ...
    }
    let inst = ReactDom.render(<A/>, document.body);
    await prom;
    prom = new Promise((s, j) => {
        rs = s;
        rj = j;
    };
    await browser
        .click('#button')
        .$apply();
    await prom;
})

Ext makes a new way that use $serial api to wrap test in serial, then use browser.$next(status) to start/resume/reject and $apply('applyAndWaitForNext')/$applyAndWaitForNext() to pause test, $serial return a promise which will be resolved if all tests finished.

Instead of wrapping promise, u can:

    class A {
        ...
        componentDidMount() {
            browser.$next();
        }

        componentDidUpdate() {
            browser.$next();
        }
    }
    
    ReactDom.render(<A/>, document.body);

    // await or return, $serial return a promise
    return browser.$serial(
        async () => {
            await browser
                .click('#button')
                .$apply('applyAndWaitForNext');
        },
        async () => {
            await browser
                .click('#button')
                .$applyAndWaitForNext();
        }
    );

If browser.$next() ran before $serial, a resolved promise flag will be assigned to browser. then while calling $serial, if there is a resolved promised flag, serial tests will auto start.

Ensure calling beforeEachHook() in beforeEach if using $serial

    beforeEach(async () => {
        await beforeEachHook();
    });

And, once test broke, it won't resume util calling browser.$next()

   await browser
        .click(xxx)
        .$applyAndWaitForNext(); // or .$apply('applyAndWaitForNext');
   // pause here, util browser.$next()
   pausing code wait for next
   ...

Examples

Run Test:

cli

    // start selenium-server-standalone
    java -jar selenium-server-standalone-3.3.1.jar
    // start karma server && event-driver server
    node node_modules/karma-event-driver-ext
    // or 
    ./node_modules/.bin/karma-event-driver-ext

api: runner.js

    let ext, { init } = require('karma-event-driver-ext');
    let karmaServer = init({
        onExit: (exitCode) {
            console.log('exitCode',  exitCode);
        },
        port: 8848 // default, same to config({ port: 8848 })
    });
    node runner.js
    // or 
    ./node_modules/.bin/karma-event-driver-ext runner.js

    // or if npm install -g: ^0.0.10, ensure all dependencies installed -g.
    // karma-event-driver-ext runner.js
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].