2015-03-19 40 views
3

我需要在測試中創建一個新的量角器會話。如何使用新會話重新啓動量角器實例?

我想:

browser.get() 
browser.quit() 
browser.get() 

但它返回一個錯誤:

Failed: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

我也試圖用browser.createSession(),但它返回我:

has no method 'createSession'

所以,我需要類似restartBrowserBetweenTests選項的東西,但我想在測試的任何部分中調用。先謝謝你。

回答

4

按照Using Multiple Browsers in the Same Test,你可以派生新的驅動程序實例:

If you are testing apps where two browsers need to interact with each other (e.g. chat systems), you can do that with protractor by dynamically creating browsers on the go in your test. Protractor exposes a function in the browser object to help you achieve this: browser.forkNewDriverInstance(opt_useSameUrl, opt_copyMockModules) . Calling this will return a new independent browser object.

newBrowser = browser.forkNewDriverInstance(); 

browser.driver.createSession()也可能是相關的取決於你正在努力完成的任務。

+0

是的,謝謝,但它不完全是我不想使用新的webdriver對象,我想重新定義瀏覽器對象。我也不知道爲新的瀏覽器實例創建會話,因爲browser.browser.createSession返回'沒有這樣的方法' – 2015-03-19 14:18:53

+0

@EgorVasilev好吧,謝謝。請參閱更新。 – alecxe 2015-03-19 17:57:35

相關問題