Skip to content

Instantly share code, notes, and snippets.

@smpallen99
Created May 9, 2012 03:25
Show Gist options
  • Save smpallen99/2641549 to your computer and use it in GitHub Desktop.
Save smpallen99/2641549 to your computer and use it in GitHub Desktop.
xpath step for FreePBX config page testing using Capybara
# features/support/freepbx_config.rb
module FreePBXConfig
def find_and_click(str)
find_partial_link(str).click
end
def find_partial_link(str)
find(:xpath , "//a[contains(text(), '#{str}')]")
end
def find_config_input(str)
find(:xpath, "//td/input[../preceding-sibling::*[1]/descendant-or-self::*[contains(text(), '#{str}')]]")
end
def find_config_item(item, str)
find(:xpath, "//td/#{item.to_s}[../preceding-sibling::*[1]/descendant-or-self::*[contains(text(), '#{str}')]]")
end
def find_config_select(option, select)
find(:xpath, "//option[contains(text(), '#{option}')][../../preceding-sibling::*[1]/descendant-or-self::*[contains(text(), '#{select}')]]")
end
end
World(FreePBXConfig)
Feature: SIP phone configuration
As a system administrator,
I would like to provision SIP extensions
So that my users can make phone calls
Scenario: New sip phone
Given I am logged in
And extension "399" does not exist
When I add a new SIP extension for "399"
And with a "Display Name" of "John Smith"
And with a "secret" of "abc123"
And I submit and apply configuration changes
Then I should see "John Smith <399>"
Scenario: Enable Voice Mail
Given I am logged in
And I click the PBX tab
And I visit the Extensions page
And I click "John Smith <399>"
When I select "Enabled" for "Status"
And I submit and apply configuration changes
And I click "John Smith <399>"
Then the "Voicemail Password" field should be "829399"
Given /^extension "([^"]*)" does not exist$/ do |arg1|
click_link 'PBX'
begin
find_and_click(arg1)
click_link "Delete Extension #{arg1}"
rescue
end
end
When /^I add a new SIP extension for "([^"]*)"$/ do |arg1|
click_link 'PBX'
select "Generic SIP Device", from: 'tech_hardware'
click_button 'Submit'
fill_in "extension", :with => arg1
end
When /^I submit and apply configuration changes$/ do
click_button 'Submit'
click_on "Apply Configuration Changes Here"
end
Then /^the vm password should equal "([^"]*)"$/ do |arg1|
find_config_input("Voicemail Password").value.should == arg1
#find_field("vmpwd").value.should == arg1
end
Given /^I edit extension ([^ ]*)$/ do |extension|
click_link "PBX"
find_and_click(extension)
end
Then /^the "([^"]*)" field should (?:be|equal|equals|=) "([^"]*)"$/ do |field, val|
find_config_input(field).value.should == val
end
When /^with a "([^"]*)" of "([^"]*)"$/ do |field, val|
find_config_input(field).set(val)
end
When /^I select "([^"]*)" for "([^"]*)"$/ do |option, select|
find_config_select(option, select).select_option
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment