2014-04-02 32 views
0

我在Windows上構建了一個AngularJS應用程序。我想用Jasmine創建端到端的測試。根據我的理解,我需要量角器來運行這些測試。出於這個原因,我已經添加了以下到我的package.json:讓我的AngularJS應用使用量角器來使用硒

"devDependencies": { 
    ... 
    "grunt-protractor-runner": "0.2.4", 
    "selenium-webdriver":"2.41.0", 
    ... 
} 

在我gruntfile.js,我已經配置量角器這樣:

grunt.initConfig({ 
    protractor: { 
    options: { 
     configFile: "node_modules/protractor/referenceConf.js", // Default config file 
     keepAlive: true, // If false, the grunt process stops when the test fails. 
     noColor: false, // If true, protractor will not use colors in its output. 
     args: { 
     // Arguments passed to the command 
     } 
    }, 
    tests: { 
     options: { 
     configFile: "tests/config/e2e.conf.js", 
     args: {} // Target-specific arguments 
     } 
    }, 
    } 
}); 

我然後運行protractor:tests目標。 e2e.conf.js的內容如下所示:

exports.config = { 
    // The address of a running selenium server. 
    seleniumAddress: 'http://localhost:4444/wd/hub', 

    // Capabilities to be passed to the webdriver instance. 
    capabilities: { 
     'browserName': 'chrome' 
    }, 

    // Spec patterns are relative to the location of the spec file. They may 
    // include glob patterns. 
    specs: ['../../tests/e2e/user-tests.e2e.js'], 

    // Options to be passed to Jasmine-node. 
    jasmineNodeOpts: { 
     showColors: true, // Use colors in the command line report. 
    } 
}; 

現在,當我運行在命令行的呼嚕聲,我得到一個錯誤,指出:

Using the selenium server at http://localhost:4444/wd/hub 

C:\Projects\MyProject\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702 
     throw error; 
      ^
Error: ECONNREFUSED connect ECONNREFUSED 
... 

我不瞭解我爲什麼會收到此錯誤。我在Protractor Getting Started Guide中看到它期望一個硒獨立服務器正在運行。不過,我認爲這是Grunt任務運行者的目的:啓動硒服務器。我看到的webdriver經辦node_modules \咕嚕,量角器亞軍\ node_modules \量角器\ BIN,但是,如果我更改到該目錄,並在命令行中運行webdriver-manager update,我得到一個錯誤,指出:

'webdriver-manager' is not recognized as an internal or external command, 
operable program or batch file. 

如何獲得硒片,以便我可以使用量角器進行端到端測試?

謝謝!

回答

1

您是否嘗試過使用「node」命令?

它的工作對我來說:

node .\node_modules\grunt-protractor-runner\node_modules\protractor\bin\webdriver-manager update 

這應該下載你chromedriver和硒服務器。如果沒有,OU還可以手動下載/提取物:

在:

  • 的src /測試/配置/硒/硒的服務器獨立。 jar
  • src/test/config/selenium/chromedriver.exe

的另一件事是,你需要確保Chrome瀏覽器時isntalled:

<WINDOWS_USERS_FOLDER>\<USERNAME>\AppData\Local\Google\Chrome\Application\chrome.exe 
1

首先是

  • 裏面還有許多組件,我不明白:)
  • 隨意添加註釋,以幫助我提高我的答案。
  • 我知道一些硒就這樣了。
seleniumAddress: 'http://localhost:4444/wd/hub', 

對我來說,此行表明您正在嘗試運行Selenium Grid Server.

以下是如何開始的:(是的,它需要儘量手動啓動,因爲我知道) 從單獨的控制檯,運行以下命令:

java -jar selenium-server-standalone-2.41.0.jar -role hub 
#now wait a few seconds for the hub to start 
java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register 

什麼我們就做什麼?

  • 啓動集線器。這個集線器就像一個測試分銷商 - 它接收請求。
  • 已啓動節點。 (您可以啓動任意數量的節點)。這個節點就是實際進行測試的地方。

您可以驗證此服務器是否已成功啓動。只需訪問瀏覽器上的本地主機鏈接。

陷阱:

  • 檢查你的防火牆是不是給你帶來麻煩。我在Windows 7上開始着手解決問題,最後轉移到Ubuntu(但這可能只是我的情況)。
  • 打開端口4444(用於集線器),5555(用於節點),用於Windows防火牆上的傳入和傳出連接。