Web based automation testing on Node.js environment

Preview:

Citation preview

Web based automation testing on Node.js environment

Kimi

Agenda• Unit Test, TDD and BDD

• Mocha and Chai

• Selenium

• Nightwatch

• GUI vs Non-GUI

• Jenkins integration

• Challenge

• Q&A

Unit Test, TDD and BDD

Unit Test• Simple, quick to write and quick to run

• Integration tests

• Acceptance tests (also called Functional tests)

case 1

case 2

TDD• Test Driven Development (TDD)

• A process for when you write and run your tests

• Test-coverage

BDD• Behaviour Driven Development

• Agile development

• Connecting with TDD

• User story

• Human readable

“An approach to development that improves communication between business and technical teams to create software with business value.”

Chai and Mocha

Chai• https://github.com/chaijs/chai

• BDD / TDD assertion library

• Open Source

• Node.js based

• Expressive language

• Readable style

Simple code:var foo = ‘bar’if foo == ‘bar’

Mocha• https://github.com/mochajs/mocha

• BDD framework

• Open Source

• Node.js based

• Writing User Story

• Export testing report (JSON, HTML et al.)

\describe('math module', function(){

it('should add numbers', function () {

assert.equal((1+1), '2');

assert.strictEqual(127 + 319, 446);

});

it('should sub numbers', function () {

assert.equal((22-1), '21');

assert.strictEqual(127 - 7, 120);

});

});

Selenium

Selenium• http://www.seleniumhq.org

• Open Source

• An automating web applications

• Cross platform

• Support lots of browser vendors

Chrome, Safari et al.

• Support lots of Programming language

Python, Node.js et al.

How it works?

Selenium - working flow

Webdriver, webdriver and webdriver

Selenium - Webdriver

• Install a browser

• Find and install it’s Webdriver

• Can NOT work without webdriver

Selenium RC• Remote Control

• HTTP proxy based

192.168.100.101:12600

Selenium - Demo

• Step 1: Open Safari browser

• Step 2: Maximum window

• Step 3: Search a keyword

• Non Selenium RC

Take a break

Nightwatch

Nightwatch• http://nightwatchjs.org/

• Open Source

• A BDD Web-based auto testing framework

• Node.js base

• A Chai, Mocha and Selenium combination framework

• Selenium RC protocol

• Screenshot when a test fails

How it works?

module.exports = { 'Demo test Google' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]') .setValue('input[type=text]', 'rembrandt van rijn') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('ol#rso li:first-child', 'Rembrandt - Wikipedia') .end(); }};

Nightwatch - Simple Code

Mocha framework

Selenium framework

Chai framework

Nightwatch - Configuration • Webdriver path

• Test result output path

• Test cases path

• Screenshot path

• Selenium RC address

• Browser capabilities

Nightwatch - package.json • Execute CMD: nightwatch -c ./Nightwatch.js --env

safari

• npm run chrome

• npm run sarari

Nightwatch - Tags • nightwatch -c ./Nightwatch.js --tag google

• nightwatch -c ./Nightwatch.js --skiptags google

Demo

Nightwatch - Disabling • nightwatch -c ./Nightwatch.js --env chrome

Demo

Nightwatch - Parallel Running • Tests to be run in parallel

• nightwatch -c ./Nightwatch.js --env chrome, firefox

Test Cases

Get element via CSS/Xpath

Nightwatch - Selector

Chrome - extensions (CSS)

Chrome - extensions (Xpath)

Non GUI testing

PhantomJS - Non GUI testing• Effectively and faster

• Easy implement

• PhantomJS (Ghost driver)

• http://phantomjs.org/

• Friendly to command-line base

• Hard to debug

• Screenshot is necessary

Non GUI testing demo

Jenkins CI integration

Jenkins integration• xUnit Test report

• Path of the test report

• Set PASS/FAIL threshold

Jenkins integration - Slack notification

Challenge

Challenge• Microsoft IE

Unix-like interacte with Windows

• macOS Safari

Need a Mac device

• AWS command-line base platform

Need a GUI bridge

• Mobile platform (RWD)

Fix Browser resolution? or Use Appium framework?

Q & A