2016-04-12 100 views
1

使用TextAngularAngularJS/ Rails環境中的富文本輸入框。水豚一體化測試'TextAngular'輸入

運行集成測試Capybara/Selenium & Capybara-Webkit。 試圖創建一個集成測試,將文本輸入文本區域進行測試。但是,我無法成功地做到這一點。

阻止我的事情是文本輸入框ID在測試加載或頁面加載時發生變化。所以我使用了下面的類,它在文本角度測試中使用。隨着:

find('textarea.ta-html.ta-editor') 

我用這個,因爲我知道它的作品和JavaScript測試書面文字角使用此。 text angular github tests

然而,當我試着和文本值設置文本區域:

find('textarea.ta-html.ta-editor').set("Upgraded to SSD") 

我得到:

Failure/Error: find('textarea.ta-html.ta-editor').set("Upgraded to SSD")
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with

如何設置使用Capybara文本區域的值?

回答

1

匹配textarea.ta-html.ta-editor的元素隱藏在頁面上,而不是用戶與之交互的元素。通過設計,水豚通常需要您與用戶進行交互的元素進行交互,因此您需要在可見元素上調用#set,該可見元素是您嘗試與之交互的元素的前一個兄弟,並匹配div[contenteditable]。你不顯示你的HTML,但希望你有一個包含的元素,你可以範圍,所以你可以做

find('<container_selector> div[contenteditable]').set(...) 

find('<more_general_container_selector>', text: '<label text or something else in the container>').find('div[contenteditable]').set(....) 

如果你只有在頁面上這種類型的字段之一你也許可以逃脫

find('.text-angular div[contenteditable]').set('Upgraded to SSD') 

注意:如果使用它有一個限制,它只能與主CONTENTEDITABLE元素進行交互,而不是與獲得創建INSI孩子硒司機去吧。我不確定其他水豚司機是否有同樣的問題。

+0

湯姆燦爛和乾淨的解決方案。可以使用Capybara/Selenium設置文本:find('div.ta-text.ta-editor div [contenteditable]')。set(「Upgraded to SSD」) – orion