Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Web based automation testing on Node.js environment

190 Aufrufe

Veröffentlicht am

An introduction of Nightwatch.

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Web based automation testing on Node.js environment

  1. 1. Web based automation testing on Node.js environment Kimi
  2. 2. Agenda • Unit Test, TDD and BDD • Mocha and Chai • Selenium • Nightwatch • GUI vs Non-GUI • Jenkins integration • Challenge • Q&A
  3. 3. Unit Test, TDD and BDD
  4. 4. Unit Test • Simple, quick to write and quick to run • Integration tests • Acceptance tests (also called Functional tests) case 1 case 2
  5. 5. TDD • Test Driven Development (TDD) • A process for when you write and run your tests • Test-coverage
  6. 6. 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.”
  7. 7. Chai and Mocha
  8. 8. 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’
  9. 9. Mocha • https://github.com/mochajs/mocha • BDD framework • Open Source • Node.js based • Writing User Story • Export testing report (JSON, HTML et al.)
  10. 10. 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); }); });
  11. 11. Selenium
  12. 12. 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.
  13. 13. How it works?
  14. 14. Selenium - working flow Webdriver, webdriver and webdriver
  15. 15. Selenium - Webdriver • Install a browser • Find and install it’s Webdriver • Can NOT work without webdriver
  16. 16. Selenium RC • Remote Control • HTTP proxy based 192.168.100.101:12600
  17. 17. Selenium - Demo • Step 1: Open Safari browser • Step 2: Maximum window • Step 3: Search a keyword • Non Selenium RC
  18. 18. Take a break
  19. 19. Nightwatch
  20. 20. 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
  21. 21. How it works?
  22. 22. 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
  23. 23. Nightwatch - Configuration • Webdriver path • Test result output path • Test cases path • Screenshot path • Selenium RC address • Browser capabilities
  24. 24. Nightwatch - package.json • Execute CMD: nightwatch -c ./Nightwatch.js --env safari • npm run chrome • npm run sarari
  25. 25. Nightwatch - Tags • nightwatch -c ./Nightwatch.js --tag google • nightwatch -c ./Nightwatch.js --skiptags google
  26. 26. Demo
  27. 27. Nightwatch - Disabling • nightwatch -c ./Nightwatch.js --env chrome
  28. 28. Demo
  29. 29. Nightwatch - Parallel Running • Tests to be run in parallel • nightwatch -c ./Nightwatch.js --env chrome, firefox Test Cases
  30. 30. Get element via CSS/Xpath
  31. 31. Nightwatch - Selector
  32. 32. Chrome - extensions (CSS)
  33. 33. Chrome - extensions (Xpath)
  34. 34. Non GUI testing
  35. 35. 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
  36. 36. Non GUI testing demo
  37. 37. Jenkins CI integration
  38. 38. Jenkins integration • xUnit Test report • Path of the test report • Set PASS/FAIL threshold
  39. 39. Jenkins integration - Slack notification
  40. 40. Challenge
  41. 41. 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?
  42. 42. Q & A

×