Skip to content

Instantly share code, notes, and snippets.

@gunesmes
Last active August 29, 2015 14:20
Show Gist options
  • Save gunesmes/247ac17ec4432021344b to your computer and use it in GitHub Desktop.
Save gunesmes/247ac17ec4432021344b to your computer and use it in GitHub Desktop.
One of the biggest challange in test automation is updating existing codes. Because of the update in the development, it is very prone to have some changes for the attributes of ui elements and less likely to have some change in behaivour in actions. The second option is most of the time called as bug, otherwise if the business is changed, it co…
# ------- GIVEN --------
Given(/^I go to a brand page$/) do
find_by(IDs.container["Brand List"]).click()
end
# ------- WHEN --------
When(/^user clicks link of "([^"]*)"$/) do |item|
find_by(IDs.header[item]).click()
end
# ---- THEN ----
Then(/^member should see "([^"]*)"$/) do |text|
page.assert_text(text)
end
Then(/^member should see the "([^"]*)" on header$/) do |item|
assert(IDs.header[item])
end
class IDs
class << self;
attr_accessor :header, :container
end
@header = {
"Logo" => [:id, "h-logo"],
"User Icon" => [:xpath, "//*[@class='metrics']/div[1]/i"],
}
@container = {
"Brand List" => [:css, ".brand-list", :first],
"First Product" => [:css, ".product-list", :first],
"Add to Basket" => [:css, ".product-list > .add-basket", :first]
}
end
def find_by(args)
# the third parameter is optional, but default is prefer_exact
page.find(args[0].to_sym, args[1], :match => (args[2] || :prefer_exact).to_sym)
end
def assert(args)
# the third parameter is optional, but default is prefer_exact
page.has_selector?(args[0].to_sym, args[1], :match => (args[2] || :prefer_exact).to_sym)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment