2017-02-24 83 views
8

您好我正在嘗試使用selenium-webdriver爲我的反應應用程序寫摩卡測試。以前配置的ChromeDriver服務仍在運行/使用Grunt運行Webdriver測試

我有幾個問題,但幫助他們其中任何一個都會有所幫助,所以我可以繼續前進。所有的

  1. 首先,理想情況下,我想在我的不同測試共享相同的webdriver會議,因爲我不關心它們運行的​​順序。我只想加載一次網頁,運行所有測試,然後關閉網頁。這可能嗎?我最初把我之前和之後的情況放在描述之外的另一個文件中,並且工作正常......但是之後我無法在我的任何測試文件中訪問驅動程序的實例。

  2. 如果共享相同的會話是不可能的,那我怎麼才能解決,低於這個錯誤,當我嘗試運行兩個specFiles發生..

以下是錯誤:

$ grunt test-e2e 
Running "mochatest:e2e" (mochatest) task 
Running Mocha tests on files 
/Users/userName/Desktop/myReactApp/tests/e2e/testSpecOne.js 
/Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js 

Error: The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration. 
    at Error (native) 
    at Object.setDefaultService (/Users/userName/Desktop/myReactApp/node_modules/selenium-webdriver/chrome.js:264:11) 
    at Object.<anonymous> (/Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js:8:8) 
    at Module._compile (module.js:556:32) 
    at loader (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:144:5) 
    at Object.require.extensions.(anonymous function) [as .js] (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:154:7) 
    at Module.load (module.js:473:32) 
    at tryModuleLoad (module.js:432:12) 

典型的測試看起來是這樣的:

import assert from 'assert'; 
import test from 'selenium-webdriver/testing'; 
import webdriver, {By, until} from 'selenium-webdriver'; 
import chrome from 'selenium-webdriver/chrome'; 
import chromedriver from 'chromedriver'; 
import helpers from './helpers.js'; 

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build()); 


test.describe('Main page',() => { 

    let driver = new webdriver 
        .Builder() 
        .withCapabilities(webdriver.Capabilities.chrome()) 
        .build(); 

    test.before(() => { 
     helpers.launchTheApp(driver, 'http://localhost:8000/myApp', 'elementOne', 10000); 
    }); 

    test.after(() => { 
    helpers.closeTheApp(driver); 
    }) 

    test.it('Test some items appear',() => { 

    helpers.checkIfElementIsPresent(driver, By.className, 'elementOne'); 
    helpers.checkIfElementIsPresent(driver, By.className, 'elementTwo'); 
    helpers.checkIfElementIsPresent(driver, By.className, 'elementThree'); 

    }); 
}); 

我使用的是咕嚕 - 摩卡試運行這些測試的conf igured這樣

e2e:{ 
    options: { 
     timeout: 3000000, 
     ignoreLeaks: true, 
     ui: 'bdd', 
     run: true, 
     log: true, 
     reporter: typeof process.env.FUSION_BUILD_GENERATED === 'undefined' ? 'spec' : 'xunit-file', 
     grep: grunt.option('grep') 
    }, 
    src: ['tests/e2e/**/**/*Spec.js'] 
} 

回答

-1

一個可能的解決方案是(在Docker集裝箱爲例)運行在隔離環境中的會話。然而,試圖用標準Selenium來實現這一點很複雜 - 您必須手動啓動和停止容器,或使用像Ansible這樣的基礎設施自動化工具。這裏是一個名爲Selenoid的全新硒兼容工具。只需在測試中請求兩個單獨的會話,它們將在Docker容器內並行運行。這給你很大的靈活性。我的談話:https://www.youtube.com/watch?v=TGjpc32my0Y

相關問題