background-color · border · border-color · color · Ruby · watir-webdriver

Watir-Webdriver – Verify Elements Color , background-color and border

Description:

To Verify the Elements Color / border-color / border / background-color using Watir-webdriver

Code

require ‘rubygems’
require ‘watir-webdriver’

@browser= Watir::Browser.new :chrome

@browser.goto(“bit.ly/watir-webdriver-demo”)

def verify_element_color(element,property,content,message)
begin
rgb_color=element.style property
rgb_color=rgb_color.sub(“rgba(“,””)
rgb_color=rgb_color.sub(“)”,””)
hex_color=rgb_color.split(“,”)
color=”#%02X%02X%02X%02X” % hex_color

if color.downcase.include? content.downcase
puts “Passed – #{message}”
else
puts “Failed – #{message}”
end
rescue
puts “Failed – #{message}”
end
end

verify_element_color(@browser.text_field(:id,’entry_1000000′),”border-color”,”#BBBBBB”,”Verify that Name Text Field has Block Color Border”)
@browser.button(:name,’submit’).click
verify_element_color(@browser.text_field(:id,’entry_1000000′),”border-color”,”#C43B1D”,”Verify that Name Text Field has Block Color Border”)

Usage:

You can pass property as a “border-color”,”border”, “color”, “background-color”

Advertisements
watir

Watir — Verifying the Current style Properties

require ‘rubygems’

require ‘watir’

ie=Watir::IE.new

ie.goto(“google.com”)

ie.image(:id,’logo’).document.currentstyle.height

#=> “190px”

ie.image(:id,’logo’).document.currentstyle.width

#=> “315px”

ie.image(:id,’logo’).document.currentstyle.fontfamily

#=> “arial,sans-serif”

ie.image(:id,’logo’).document.currentstyle.textalign

#=> “center”

ie.image(:id,’logo’).document.currentstyle.borderwidth

#=> “0px”

For more details,