2014-01-16 47 views
2

我想通過grunt爲瀏覽器功能矩陣運行cucumberjs測試。grunt cucumberjs多個並行運行

矩陣配置「咕嚕」正常(qcuberbatch是當地咕嚕任務定義):

grunt.initConfig 
    qcumberbatch: 
     options: 
      steps: 'src/features/integration/steps' 
      tags: '[email protected]' 
      browserstack: 
       'browserstack.user' : process.env.BS_USER 
       'browserstack.key' : process.env.BS_ACCESS_KEY 
       'browserstack.tunnel' : 'true' # This was the secret! 

      matrix: [ 
       browser: 'firefox' 
       browser_version: '26.0' 
       os: 'Windows' 
       os_version : '7', 
      , 
       browser : 'IE', 
       browser_version : '9.0', 
       os : 'Windows', 
       os_version : '7', 
       resolution : '1024x768' 
      ] 
      hub: "http://hub.browserstack.com/wd/hub" 

     local: 
      files: 
       src: ['src/features/integration/*'] 
      options: 
       hub: 'http://localhost:4444/wd/hub' 
       matrix: ['firefox'] 

     browserstack: 
      files: 
       src: ['src/features/integration/*'] 

     failing: 
      files: 
       src: ['src/features/integration/*'] 
      options: 
       tags: '@ShouldFail' 

默認選項有它使用Firefox和IE瀏覽器在Windows 7上運行鍼對browserstack,與當地的測試覆蓋browserstack使用本地硒webdriver樞紐。

黃瓜世界設定了一個構造函數取功能對象:

module.exports = class World 
    ### 
    Create a new world, assuming firefox capabilities. 

    @param {string} browser property name from the `webdriver.Capabilities` 
     list. 
    ### 
    constructor: (capabilities = {browserName: "firefox"})-> 
     @driver = new webdriver.Builder(). 
      usingServer(process.env.SELENIUM_HUB). 
      withCapabilities(capabilities).build() 

     @driver.manage().timeouts().setScriptTimeout(10000) 

的問題,從咕嚕運行這個時候,是cucumberjs沒有任何編程接口(即我見)。如果沒有配置在運行時加載哪幾個功能塊的能力,我應該怎麼做才能在cucumberjs run和grunt之間傳遞功能?

回答

0

可能的解決辦法:

寫文件,在繁重的文件的已知位置用的所有功能斑點。然後,啓動幾個cucumberjs運行,使用一個進程環境變量告訴世界哪個能力使用blob。

我不喜歡這樣,因爲它涉及每次運行創建臨時文件等。我更喜歡在配置World對象時以編程方式找到一種方法來使用cucumberjs。

+0

擴展到這個想法,在env var中將JSON傳遞的能力如何?然後解析你的世界中的那個JSON字符串,並讓你的對象返回。 – jbpros

1

我會用你的解決方案和一個JSON對象,我建議。但是,如果您對更具編程意義的方法感興趣,則可以很容易地實例化Cucumber運行時。 CLI源代碼非常簡單,它是如何從代碼調用Cucumber的一個很好的例子。見https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber/cli.js

+0

我曾考慮將其綁定到CLI,但這需要在所需的步驟文件中具有文件中的功能。在我看來,支持代碼加載器在僅從文件路徑加載代碼時是有問題的,而不是允許運行時傳入具有步驟定義的對象。但是,在其他頁面中存在各種架構問題。可能超出了這個問題的範圍。 如果我在github上發佈這個作爲0.6的增強版,你會對改變API感興趣嗎? –

+0

當然,我們可以改進它。你有沒有檢查過我們如何在瀏覽器上下文中注入支持代碼?這可能有幫助。 https://github.com/cucumber/cucumber-js/blob/master/example/example.js#L80 – jbpros

+0

嗯,我沒有看到。我會看看並張貼一些東西。 –