Last active
December 14, 2015 07:19
-
-
Save teleservices/5049883 to your computer and use it in GitHub Desktop.
This gist shows the result of trying to use the element attribute method. The line starting with "=============>" is a raw "puts" of the attribute value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rake SPEC=spec/selenium/brand/test_view_atest_spec.rb | |
/home/vagrant/.rbenv/versions/1.9.3-p194/bin/ruby -S rspec spec/selenium/brand/test_view_atest_spec.rb | |
Rack::File headers parameter replaces cache_control after Rack 1.5. | |
=============> find_element(:xpath, "//div[@id=\"logo-client\"]/img").attribute("src"): http://alpha.decdynamics.com/brands/atest/logo.png | |
F | |
Failures: | |
1) TestViewAtest test_view_a | |
Failure/Error: (@driver.find_element(:xpath, "//div[@id=\"logo-client\"]/img").attribute("src")).should == "../brands/atest/logo.png" | |
expected: "../brands/atest/logo.png" | |
got: "http://alpha.decdynamics.com/brands/atest/logo.png" (using ==) | |
# ./spec/selenium/brand/test_view_atest_spec.rb:31:in `block (2 levels) in <top (required)>' | |
Finished in 3.65 seconds | |
1 example, 1 failure | |
Failed examples: | |
rspec ./spec/selenium/brand/test_view_atest_spec.rb:20 # TestViewAtest test_view_a | |
Randomized with seed 56753 | |
rake aborted! | |
/home/vagrant/.rbenv/versions/1.9.3-p194/bin/ruby -S rspec spec/selenium/brand/test_view_atest_spec.rb failed | |
Tasks: TOP => default => spec | |
(See full trace by running task with --trace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding: UTF-8 | |
require "selenium-webdriver" | |
include RSpec::Expectations | |
describe "TestViewAtest" do | |
before(:each) do | |
@driver = Selenium::WebDriver.for :firefox | |
@base_url = "http://alpha.decdynamics.com/" | |
@accept_next_alert = true | |
@driver.manage.timeouts.implicit_wait = 30 | |
@verification_errors = [] | |
end | |
after(:each) do | |
@driver.quit | |
@verification_errors.should == [] | |
end | |
it "test_view_a" do | |
DDLLC = "Decision Dynamics LLC" | |
COMPANY = "ATEST_company" | |
TITLE = "ATEST_title" | |
@driver.get(@base_url + "ddaps/quit.asp") | |
@driver.get(@base_url + "/atest/") | |
(@driver.title).should == COMPANY + " - " + TITLE | |
@driver.find_element(:css, "BODY").text.should =~ /^[\s\S]*#{COMPANY}[\s\S]*$/ | |
element_present?(:xpath, "//div[@id='logo-client']/img").should be_true | |
# for debugging - show direct result from attribute | |
src = @driver.find_element(:xpath, "//div[@id=\"logo-client\"]/img").attribute("src") | |
puts "=============> find_element(:xpath, \"//div[@id=\\\"logo-client\\\"]/img\").attribute(\"src\"): #{src}" | |
(@driver.find_element(:xpath, "//div[@id=\"logo-client\"]/img").attribute("src")).should == "../brands/atest/logo.png" | |
element_present?(:xpath, "//link[@rel='apple-touch-icon']").should be_true | |
# for debugging - show direct result from attribute | |
href = @driver.find_element(:xpath, "//link[@rel='apple-touch-icon']").attribute("href") | |
puts "=============> find_element(:xpath, \"//link[@rel='apple-touch-icon']\").attribute(\"href\"): #{href}" | |
(@driver.find_element(:xpath, "//link[@rel='apple-touch-icon']").attribute("href")).should == "../brands/atest/logo.png" | |
@driver.find_element(:xpath, "//input[@name='mode' and @value='Register']").click | |
(@driver.title).should == "LOGIN - " + DDLLC | |
verify { (@driver.find_element(:xpath, "//form/table/tbody/tr[1]/td[1]").text).should == "Registration Number:" } | |
@driver.navigate.back | |
(@driver.title).should == COMPANY + " - " + TITLE | |
@driver.find_element(:xpath, "//input[@name='mode' and @value='Login']").click | |
(@driver.title).should == "LOGIN - " + DDLLC | |
verify { (@driver.find_element(:xpath, "//form/table/tbody/tr[1]/td[1]").text).should == "Username:" } | |
verify { (@driver.find_element(:xpath, "//form/table/tbody/tr[2]/td[1]").text).should == "Password:" } | |
@driver.find_element(:xpath, "//input[@name='Action' and @value='Cancel']").click | |
(@driver.title).should == "Sign Off - " + DDLLC | |
@driver.get(@base_url + "ddaps/quit.asp") | |
end | |
def element_present?(how, what) | |
@driver.find_element(how, what) | |
true | |
rescue Selenium::WebDriver::Error::NoSuchElementError | |
false | |
end | |
def verify(&blk) | |
yield | |
rescue ExpectationNotMetError => ex | |
@verification_errors << ex | |
end | |
def close_alert_and_get_its_text(how, what) | |
alert = @driver.switch_to().alert() | |
if (@accept_next_alert) then | |
alert.accept() | |
else | |
alert.dismiss() | |
end | |
alert.text | |
ensure | |
@accept_next_alert = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment