Chapter6: web driver IO & mocha

This section contain the following items:

  • 1.Introduction

  • 2.What is webdriverio?

  • 3.Environment setting

  • 4.Apply to project and analysis

  • 5.Reference

1.Introduction

In order to build a auto testing framework to fulfill our requirement, this chapter have the following items:
1) What is webDriverIO?
  2) Enviroment Setting
  2) Apply to project and analysize
  4) Reference

2.What is webdriverio?

WebdriverIO lets you control a browser or a mobile application with just a few lines of code. Your test code will look simple, concise and easy to read. The integrated
testrunner allows you to write asynchronous commands in a synchronous way so that you 
  don’t need to care about how to propagate a Promise to avoid racing conditions.

  The test runner comes also with a variety of hooks that allow you to interfere into the    
  test process in order to take screenshots if an error occurs or modify the test procedure 
  according to a previous test result. (reference from: http://webdriver.io/)

3.Environment setting

"assert": "^1.4.1",

    "chai": "^3.5.0",

    "chai-as-promised": "^5.3.0",

   "wdio-mocha-framework": "^0.4.0",

    "mocha": "^2.3.0",

    "webdriverio": "^3.3.0",

      "should": "^7.1.0"

      },
  • 5)sudo npm install

  • 6)create test case named "webtest.js" into webdrivverio-test folder, sample code as

  • 7)start to work :

    • 7.1)launch standalone server in webdrivverio-test folder:

    java -jar selenium-server-standalone-2.53.1.jar

    • 7.2)launch http server which you want to test :

    node app.js

    • 7.3) launch webtest.js:

    node webtest.js

  • 8)Test result:

  • ```

    4.Apply to project and analysis

1) 從程式碼中可以了解Mocha屬於BDD的測試框架, 目的以User Story作為出發, 是因此程式碼看起來多半都是When

```
[scenario], giving [conditions], it should [expected results]的語句, 當在什麼情況下測試結果
     應該滿足什麼情況 
  2) 單元測試的3A在此架構下是拆分成獨立的獨立的物件/function, 像是assert就必須引入chai這個library 
      Arrange
        初始化目標物件
        初始化方法參數
        建立模擬物件行為
        設定環境變數,期望結果
      Act
        實際呼叫目標測試物件的方法
      Assert
        驗證目標物件是否如同預期運作

5.Reference

1.官網: http://webdriver.io/guide.html 2.範例: https://github.com/onewithhammer/WebDriverIOTutorial 3.用 mocha 編寫 Node.js unit test:http://syshen.cc/post/23479369750/%E7%94%A8-mocha-%E7%B7%A8%E5%AF%AB-nodejs-unit-test 4.http://toyo0103.blogspot.tw/2015/08/unit-test-3a.html 5.http://slides.com/alincode/deck-2/fullscreen#/

```

```

Last updated

Was this helpful?