我正在使用黃瓜,selenium-webdriver和頁面對象gem進行測試自動化。 當我試圖運行簡單的測試,黃瓜趕以下錯誤:PageObject「等待元素」方法不起作用
Scenario: Going to billing # features/test.feature:10
When I click 'Платные услуги' # features/step_definitions/test_steps.rb:13
Unable to locate element: {"method":"link text","selector":"Платные услуги"} (Selenium::WebDriver::Error::NoSuchElementError)
[remote server] file:///tmp/webdriver-profile20130412-21410-z4p1ez/extensions/[email protected]/components/driver_component.js:8405:in `FirefoxDriver.prototype.findElementInternal_'
[remote server] file:///tmp/webdriver-profile20130412-21410-z4p1ez/extensions/[email protected]/components/driver_component.js:8414:in `FirefoxDriver.prototype.findElement'
[remote server] file:///tmp/webdriver-profile20130412-21410-z4p1ez/extensions/[email protected]/components/command_processor.js:10421:in `DelayedCommand.prototype.executeInternal_/h'
[remote server] file:///tmp/webdriver-profile20130412-21410-z4p1ez/extensions/[email protected]/components/command_processor.js:10426:in `DelayedCommand.prototype.executeInternal_'
[remote server] file:///tmp/webdriver-profile20130412-21410-z4p1ez/extensions/[email protected]/components/command_processor.js:10366:in `DelayedCommand.prototype.execute/<'
./features/pages/job_main_page.rb:38:in `go_to_billing'
./features/step_definitions/test_steps.rb:14:in `/^I click 'Платные услуги'$/'
features/test.feature:11:in `When I click 'Платные услуги''
這裏是黃瓜的特點:
Scenario: Going to billing
When I click 'Платные услуги'
Then I should see "Коммерческие услуги"
步驟定義,被測下降:
When(/^I go to billing$/) do
@job_myroom_billing = @job_myroom.billing_element.when_visible.go_to_billing
end
和頁面對象:
class BasePage
include PageObject
include RSpec::Matchers
end
class JobMyroom < BasePage
link :billing, link: 'Платные услуги'
def go_to_billing
billing
JobMyroomBilling.new @browser
end
end
class JobMyroomBilling < JobMyroom
#some code
end
怎麼了?驅動程序不要等待元素的存在
無意中你打開一個新的瀏覽器,對不對? – e1che
它永遠不會等待元素出現。我們使用的解決方案是:最後加載一個元素 - >在測試代碼運行之前添加一個額外的「等待元素」。有一些特殊的方法可以等待元素出現。 – User
e1che,yes在hooks.rb中使用「before do」,「after do」方法:「@browser = Selenium :: WebDriver.for:firefox」和「@ browser.close」 –