自動化測試開發環境搭建

 首先用vagrant配置一個Linux開發環境:javascript

Vagrant只是一個讓你能夠方便設置你想要的虛擬機的便攜式工具,它底層支持VirtualBox、VMware甚至AWS做爲虛擬機系統,本書中咱們將使用VirtualBox來進行說明,因此第一步須要先安裝Vagrant和VirtualBox。html

 

  VirtualBox安裝:下載地址,麻瓜安裝,任意路徑https://www.virtualbox.org/wiki/Downloadsjava

  Vagrant安裝:最新版本的Vagrant已經沒法經過gem命令來安裝,由於依賴庫太多了,因此目前沒法使用gem來安裝,目前網絡上面不少教程仍是相似這樣的命令,那些都是錯誤的。推薦官網下載安裝包,如上麻瓜安裝https://www.vagrantup.com/downloads.htmlnode

  通常來講下載安裝這兩個就準備ok了,不過有時候win下也會有些奇怪的不可預知錯誤,我第二次安裝碰見了...打上這補丁就okhttp://download.virtualbox.org/virtualbox/5.0.10/Oracle_VM_VirtualBox_Extension_Pack-5.0.10-104061.vbox-extpackgit

  ok,準備工做以上就緒github

鍵入如下命令:web

  mkdir ubuntu14.04shell

  cd ubuntu14.04npm

  vagrant init ubuntu/trusty64 #init 後面自行輸入,那是虛擬機名字ubuntu

  # modify the created Vagrantfile configuration file 在當前目錄下生成了一個vagrantfile配置文件

  vagrant up

 vagrant ssh

通常win下不支持vagrant ssh,會報錯:ssh client not found ,須要安裝一個第三方客服端進行鏈接,這裏推薦msys,它能夠打造相似於Linux shell下的體驗 http://sourceforge.net/projects/msys2/

 下載好msys2包後 運行安裝以下

 $ pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime

 $ pacman-Su

 $ pacman -S git #安裝git和ssh 方便你在win下使用git

 以上,就完成了vagrant的Linux開發環境搭建。

安裝webdriver I/O:

 我這裏用的是nodejs作selenium2.0的開發,用msys2 shell啓動Ubuntu

 我裝的是命令行Ubuntu 無界面,裝一個xvfb來模擬x-server端

sudo apt-get install xvfb#安裝xvf
sudo apt-get install firefox #安裝Firefox
安裝java
$ sudo apt-add-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer
$ export JAVA_HOME=/usr/lib/jvm/java-7-oracle # append to your ~/.profile file.

安裝nodejs
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash
$ nvm #nvm nodejs版本管理器 看是否有輸出,有就安裝成功了
$ nvm install 0.12 #可取官網查看最新版本 nvm可多樣管理這裏不做熬訴

安裝selenium-standalone server
$ npm install selenium-standalone@latest -g $ selenium-standalone install $ xvfb-run --server-args="-screen 0, 1366x768x24" selenium-standalone start
完成後另開一個shell 這是模擬的一個 server端

測試準備
$ mkdir my-test $ cd my-test $ npm init -y # 初始化nodejs項目 $ npm install webdriverio #安裝 webdriverio 包 $ nano baidu-test.js $ # vim baidu-test.js #nano附個百度的小測試         baidu-test.js#var webdriverio = require('webdriverio');var options = {  desiredCapabilities: {    browserName: 'firefox'  }};var browser = webdriverio  .remote(options)  .init();browser  .url('https://www.baidu.com')  .title(function(err, res) {      console.log('Title was: ' + res.value);  })  .end();#$ node baidu-test.jsTitle was: 百度一下,你就知道若是你對coffeeScript也感興趣能夠用coffee來作測試 baidu-test.coffee#webdriverio = require 'webdriverio'options =  desiredCapabilities:    browserName: 'firefox'webdriverio  .remote options  .init()  .url 'https://www.baidu.com'  .title (err, res)->    console.log 'Title was: ' + res.value  .end()# this is a comments#$ npm install -g coffee(安裝)$ coffee baidu-test.coffeeTitle was: 百度一下,你就知道在附一個javascript與coffeescript語法對比 http://coffeescript.org/IBM 翻譯中文文檔 http://www.ibm.com/developerworks/cn/views/web/libraryview.jsp?search_by=%E5%88%9D%E6%AD%A5%E4%BA%86%E8%A7%A3+CoffeeScript 以上就是我近期學會的用vagrant搭建虛擬機基於nodejs selenium 自動化測試的開發環境。 第一次寫博,但願你們多多指教! ————dognie
相關文章
相關標籤/搜索