44
Web based automation testing on Node.js environment Kimi

Web based automation testing on Node.js environment

Embed Size (px)

Citation preview

Page 1: Web based automation testing on Node.js environment

Web based automation testing on Node.js environment

Kimi

Page 2: Web based automation testing on Node.js environment

Agenda• Unit Test, TDD and BDD

• Mocha and Chai

• Selenium

• Nightwatch

• GUI vs Non-GUI

• Jenkins integration

• Challenge

• Q&A

Page 3: Web based automation testing on Node.js environment

Unit Test, TDD and BDD

Page 4: Web based automation testing on Node.js environment

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

• Integration tests

• Acceptance tests (also called Functional tests)

case 1

case 2

Page 5: Web based automation testing on Node.js environment

TDD• Test Driven Development (TDD)

• A process for when you write and run your tests

• Test-coverage

Page 6: Web based automation testing on Node.js environment

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.”

Page 7: Web based automation testing on Node.js environment
Page 8: Web based automation testing on Node.js environment

Chai and Mocha

Page 9: Web based automation testing on Node.js environment

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’

Page 10: Web based automation testing on Node.js environment

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

• BDD framework

• Open Source

• Node.js based

• Writing User Story

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

Page 11: Web based automation testing on Node.js environment

\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);

});

});

Page 12: Web based automation testing on Node.js environment

Selenium

Page 13: Web based automation testing on Node.js environment

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.

Page 14: Web based automation testing on Node.js environment

How it works?

Page 15: Web based automation testing on Node.js environment

Selenium - working flow

Webdriver, webdriver and webdriver

Page 16: Web based automation testing on Node.js environment

Selenium - Webdriver

• Install a browser

• Find and install it’s Webdriver

• Can NOT work without webdriver

Page 17: Web based automation testing on Node.js environment

Selenium RC• Remote Control

• HTTP proxy based

192.168.100.101:12600

Page 18: Web based automation testing on Node.js environment

Selenium - Demo

• Step 1: Open Safari browser

• Step 2: Maximum window

• Step 3: Search a keyword

• Non Selenium RC

Page 19: Web based automation testing on Node.js environment

Take a break

Page 20: Web based automation testing on Node.js environment

Nightwatch

Page 21: Web based automation testing on Node.js environment

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

Page 22: Web based automation testing on Node.js environment

How it works?

Page 23: Web based automation testing on Node.js environment

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

Page 24: Web based automation testing on Node.js environment
Page 25: Web based automation testing on Node.js environment

Nightwatch - Configuration • Webdriver path

• Test result output path

• Test cases path

• Screenshot path

• Selenium RC address

• Browser capabilities

Page 26: Web based automation testing on Node.js environment

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

safari

• npm run chrome

• npm run sarari

Page 27: Web based automation testing on Node.js environment

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

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

Page 28: Web based automation testing on Node.js environment

Demo

Page 29: Web based automation testing on Node.js environment

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

Page 30: Web based automation testing on Node.js environment

Demo

Page 31: Web based automation testing on Node.js environment

Nightwatch - Parallel Running • Tests to be run in parallel

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

Test Cases

Page 32: Web based automation testing on Node.js environment

Get element via CSS/Xpath

Page 33: Web based automation testing on Node.js environment

Nightwatch - Selector

Page 34: Web based automation testing on Node.js environment

Chrome - extensions (CSS)

Page 35: Web based automation testing on Node.js environment

Chrome - extensions (Xpath)

Page 36: Web based automation testing on Node.js environment

Non GUI testing

Page 37: Web based automation testing on Node.js environment

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

Page 38: Web based automation testing on Node.js environment

Non GUI testing demo

Page 39: Web based automation testing on Node.js environment

Jenkins CI integration

Page 40: Web based automation testing on Node.js environment

Jenkins integration• xUnit Test report

• Path of the test report

• Set PASS/FAIL threshold

Page 41: Web based automation testing on Node.js environment

Jenkins integration - Slack notification

Page 42: Web based automation testing on Node.js environment

Challenge

Page 43: Web based automation testing on Node.js environment

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?

Page 44: Web based automation testing on Node.js environment

Q & A